Developing lightweight computation at the DSG edge

Commit 38da0135 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[goclidote-demo] Dummy tests with maps


Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent caf1cd70
......@@ -3,14 +3,14 @@ package main
import (
"fmt"
"github.com/mweberUKL/go-antidote"
"github.com/AntidoteDB/antidote-go-client"
)
// Host represents an Antidote server.
// The port needs to be the port of the protocol-buffer interface (usually 8087)
// AntidoteAddItemToSetInBucket save an item to a set in a bucketdcrf
func main() {
func maain() {
client, err := antidoteclient.NewClient(antidoteclient.Host{"127.0.0.1", 8087})
errCheck(err, "")
......@@ -74,7 +74,7 @@ func main() {
}
// Panic on error
func errCheck(err error, message string) {
func errChseck(err error, message string) {
if err != nil {
fmt.Println(message)
panic(err)
......
package main
import (
"fmt"
"math/rand"
"time"
"github.com/AntidoteDB/antidote-go-client"
)
// Host represents an Antidote server.
// The port needs to be the port of the protocol-buffer interface (usually 8087)
// AntidoteAddItemToSetInBucket save an item to a set in a bucketdcrf
func maaain() {
var myBucket = "device-123"
var myTimestamp = time.Now().UTC()
var myKey = myTimestamp.Format("2006-01-02-15-04-05")
fmt.Println(myKey)
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
fmt.Println(fmt.Sprintf("%d", r1.Intn(100)))
client, err := antidoteclient.NewClient(antidoteclient.Host{"127.0.0.1", 8087})
errCheck(err, "")
defer client.Close()
tx, err := client.StartTransaction()
errCheck(err, "")
bucket := antidoteclient.Bucket{[]byte(myBucket)}
key := antidoteclient.Key(myKey)
err = bucket.Update(tx, antidoteclient.SetAdd(key, []byte(fmt.Sprintf("%d", r1.Intn(100)))))
errCheck(err, "")
setVal, err := bucket.ReadSet(tx, key)
errCheck(err, "")
fmt.Println("(1)")
for _, v := range setVal {
fmt.Println(string(v))
}
err = bucket.Update(tx, antidoteclient.SetAdd(key, []byte(fmt.Sprintf("%d", r1.Intn(100)))))
errCheck(err, "")
setVal, err = bucket.ReadSet(tx, key)
errCheck(err, "")
fmt.Println("(2)")
for _, v := range setVal {
fmt.Println(string(v))
}
err = bucket.Update(tx, antidoteclient.SetAdd(key, []byte(fmt.Sprintf("%d", r1.Intn(100)))))
errCheck(err, "")
setVal, err = bucket.ReadSet(tx, key)
errCheck(err, "")
fmt.Println("(3)")
for _, v := range setVal {
fmt.Println(string(v))
}
err = bucket.Update(tx, antidoteclient.SetAdd(key, []byte(fmt.Sprintf("%d", r1.Intn(100)))))
errCheck(err, "")
setVal, err = bucket.ReadSet(tx, key)
errCheck(err, "")
fmt.Println("(4)")
for _, v := range setVal {
fmt.Println(string(v))
}
err = tx.Commit()
errCheck(err, "")
}
// Panic on error
func errdCheck(err error, message string) {
if err != nil {
fmt.Println(message)
panic(err)
}
}
package main
import (
"bytes"
"fmt"
"math/rand"
"time"
"github.com/AntidoteDB/antidote-go-client"
)
// Host represents an Antidote server.
// The port needs to be the port of the protocol-buffer interface (usually 8087)
// AntidoteAddItemToSetInBucket save an item to a set in a bucketdcrf
func main() {
var myBucket = "device-1234"
var myMap = "raw"
var myKey = time.Now().UTC().Format("2006-01-02-15-04-05")
r1 := rand.New(rand.NewSource(time.Now().UnixNano()))
client, err := antidoteclient.NewClient(antidoteclient.Host{"127.0.0.1", 8087})
errCheck(err, "")
defer client.Close()
tx, err := client.StartTransaction()
errCheck(err, "")
bucket := antidoteclient.Bucket{[]byte(myBucket)}
key := antidoteclient.Key(myMap)
err = bucket.Update(tx, antidoteclient.MapUpdate(key,
antidoteclient.SetAdd(antidoteclient.Key(myKey), []byte(fmt.Sprintf("%d", r1.Intn(100))))))
errCheck(err, "")
mapVal, err := bucket.ReadMap(tx, key)
errCheck(err, "")
keyList := mapVal.ListMapKeys()
fmt.Println("(1)")
for _, expected := range []antidoteclient.MapEntryKey{
{[]byte("counter"), antidoteclient.CRDTType_COUNTER},
{[]byte("reg"), antidoteclient.CRDTType_LWWREG},
{[]byte("set"), antidoteclient.CRDTType_ORSET},
} {
found := false
for _, entry := range keyList {
fmt.Println(string(entry.Key))
if bytes.Equal(entry.Key, expected.Key) && entry.CrdtType == expected.CrdtType {
found = true
fmt.Println("a")
break
}
}
if !found {
fmt.Sprintln("expected value %s not found in result (%s)", expected.Key, keyList)
}
}
err = tx.Commit()
errCheck(err, "")
}
// Panic on error
func errCheck(err error, message string) {
if err != nil {
fmt.Println(message)
panic(err)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment