Developing lightweight computation at the DSG edge

antidoteclient_test.go 1.22 KB
Newer Older
Peter Zeller's avatar
Peter Zeller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package antidoteclient

//import "fmt"
import (
	"testing"
	"fmt"
)

func TestSimple(t *testing.T) {

	client, err := NewClient(Host{"127.0.0.1", 8087})
	if err != nil {
		t.Fatal(err)
	}

	tx, err := client.StartTransaction()
	if err != nil {
		t.Fatal(err)
	}
	crdtType := CRDTType_COUNTER
	key := &ApbBoundObject{
		Bucket: []byte("bucket"),
		Key:    []byte("key"),
		Type:   &crdtType}
	one := int64(1)
26
	tx.Update(&ApbUpdateOp{
Peter Zeller's avatar
Peter Zeller committed
27
28
29
		Boundobject: key,
		Operation:   &ApbUpdateOperation{Counterop: &ApbCounterUpdate{Inc: &one}},
	})
30
	resp, err := tx.Read(key)
Peter Zeller's avatar
Peter Zeller committed
31
32
33
34
35
36
	if err != nil {
		t.Fatal(err)
	}

	fmt.Print(resp.Objects[0])

37
	_, err = tx.Commit()
Peter Zeller's avatar
Peter Zeller committed
38
39
40
41
42
	if err != nil {
		t.Fatal(err)
	}

}
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

func TestStatic(t *testing.T) {
	client, err := NewClient(Host{"127.0.0.1", 8087})
	if err != nil {
		t.Fatal(err)
	}

	crdtType := CRDTType_COUNTER
	key := &ApbBoundObject{
		Bucket: []byte("bucket"),
		Key:    []byte("keyStatic"),
		Type:   &crdtType}
	one := int64(1)
	_, err = client.StaticUpdate(&ApbUpdateOp{
		Boundobject: key,
		Operation:   &ApbUpdateOperation{Counterop: &ApbCounterUpdate{Inc: &one}},
	})
	if err != nil {
		t.Fatal(err)
	}
	resp, err := client.StaticRead(key)
	if err != nil {
		t.Fatal(err)
	}

	fmt.Print(resp.Objects.Objects[0])
}