Developing lightweight computation at the DSG edge
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LightKone
antidote-go-client
Commits
eea9853b
Commit
eea9853b
authored
Mar 23, 2018
by
Mathias Weber
Browse files
wip: tests for high-level api
parent
55b86d68
Changes
1
Show whitespace changes
Inline
Side-by-side
antidoteclient_test.go
View file @
eea9853b
package
antidoteclient
//import "fmt"
import
(
"testing"
"fmt"
"sync"
"bytes"
"time"
)
func
TestSimple
(
t
*
testing
.
T
)
{
...
...
@@ -19,7 +20,9 @@ func TestSimple(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
bucket
:=
Bucket
{[]
byte
(
"bucket"
)}
timestamp
:=
time
.
Now
()
.
Unix
()
bucketname
:=
fmt
.
Sprintf
(
"bucket%d"
,
timestamp
)
bucket
:=
Bucket
{[]
byte
(
bucketname
)}
key
:=
Key
(
"keyCounter"
)
err
=
bucket
.
Update
(
tx
,
CounterInc
(
key
,
1
))
if
err
!=
nil
{
...
...
@@ -31,12 +34,15 @@ func TestSimple(t *testing.T) {
t
.
Fatal
(
err
)
}
fmt
.
Print
(
counterVal
)
err
=
tx
.
Commit
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
counterVal
!=
1
{
t
.
Fatalf
(
"Counter value should be 1 but is %d"
,
counterVal
)
}
}
func
TestSetUpdate
(
t
*
testing
.
T
)
{
...
...
@@ -51,11 +57,12 @@ func TestSetUpdate(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
bucket
:=
Bucket
{[]
byte
(
"bucket"
)}
timestamp
:=
time
.
Now
()
.
Unix
()
bucketname
:=
fmt
.
Sprintf
(
"bucket%d"
,
timestamp
)
bucket
:=
Bucket
{[]
byte
(
bucketname
)}
key
:=
Key
(
"keySet"
)
err
=
bucket
.
Update
(
tx
,
SetAdd
(
key
,
[]
byte
(
"test1"
)))
err
=
bucket
.
Update
(
tx
,
SetAdd
(
key
,
[]
byte
(
"test1"
)
,
[]
byte
(
"value2"
),
[]
byte
(
"inset3"
)
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -66,18 +73,79 @@ func TestSetUpdate(t *testing.T) {
t
.
Fatal
(
err
)
}
for
_
,
v
:=
range
setVal
{
fmt
.
Println
(
string
(
v
))
err
=
tx
.
Commit
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
tx
.
Commit
()
for
_
,
expected
:=
range
[]
string
{
"test1"
,
"value2"
,
"inset3"
}
{
found
:=
false
for
_
,
val
:=
range
setVal
{
if
string
(
val
)
==
expected
{
found
=
true
break
}
}
if
!
found
{
t
.
Fatalf
(
"expected value %s not found in result (%s)"
,
expected
,
setVal
)
}
}
}
func
TestMap
(
t
*
testing
.
T
)
{
client
,
err
:=
NewClient
(
Host
{
"127.0.0.1"
,
8087
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
client
.
Close
()
tx
,
err
:=
client
.
StartTransaction
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
timestamp
:=
time
.
Now
()
.
Unix
()
bucketname
:=
fmt
.
Sprintf
(
"bucket%d"
,
timestamp
)
bucket
:=
Bucket
{[]
byte
(
bucketname
)}
key
:=
Key
(
"keyMap"
)
err
=
bucket
.
Update
(
tx
,
MapUpdate
(
key
,
CounterInc
(
Key
(
"counter"
),
13
),
RegPut
(
Key
(
"reg"
),
[]
byte
(
"Hello World"
)),
SetAdd
(
Key
(
"set"
),
[]
byte
(
"A"
),
[]
byte
(
"B"
))))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
mapVal
,
err
:=
bucket
.
ReadMap
(
tx
,
key
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
v
,
e
:=
mapVal
.
Counter
(
Key
(
"counter"
));
e
!=
nil
||
v
!=
13
{
t
.
Fatalf
(
"Wrong counter value: %d"
,
v
)
}
if
v
,
e
:=
mapVal
.
Reg
(
Key
(
"reg"
));
e
!=
nil
||
!
bytes
.
Equal
(
v
,
[]
byte
(
"Hello World"
))
{
t
.
Fatalf
(
"Wrong reg value: %p"
,
v
)
}
v
,
_
:=
mapVal
.
Set
(
Key
(
"set"
))
if
len
(
v
)
!=
2
{
t
.
Fatal
(
"Wrong number of elements in set"
)
}
for
_
,
expected
:=
range
[]
string
{
"A"
,
"B"
}
{
found
:=
false
for
_
,
val
:=
range
v
{
if
string
(
val
)
==
expected
{
found
=
true
break
}
}
if
!
found
{
t
.
Fatalf
(
"expected value %s not found in result (%s)"
,
expected
,
v
)
}
}
}
func
T
estManyUpdates
(
t
*
testing
.
T
)
{
func
t
estManyUpdates
(
t
*
testing
.
T
)
{
client
,
err
:=
NewClient
(
Host
{
"127.0.0.1"
,
8087
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -122,7 +190,7 @@ func TestManyUpdates(t *testing.T) {
fmt
.
Print
(
counterVal
)
}
func
T
estReadMany
(
t
*
testing
.
T
)
{
func
t
estReadMany
(
t
*
testing
.
T
)
{
client
,
err
:=
NewClient
(
Host
{
"127.0.0.1"
,
8087
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -145,12 +213,15 @@ func TestStatic(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
bucket
:=
Bucket
{[]
byte
(
"bucket"
)}
defer
client
.
Close
()
timestamp
:=
time
.
Now
()
.
Unix
()
bucketname
:=
fmt
.
Sprintf
(
"bucket%d"
,
timestamp
)
bucket
:=
Bucket
{[]
byte
(
bucketname
)}
key
:=
Key
(
"keyStatic"
)
tx
:=
client
.
CreateStaticTransaction
()
err
=
bucket
.
Update
(
tx
,
CounterInc
(
key
,
1
))
err
=
bucket
.
Update
(
tx
,
CounterInc
(
key
,
42
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -159,5 +230,7 @@ func TestStatic(t *testing.T) {
t
.
Fatal
(
err
)
}
fmt
.
Print
(
counterVal
)
if
counterVal
!=
42
{
t
.
Fatalf
(
"Counter value should be 42 but is %d"
,
counterVal
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment