-
Notifications
You must be signed in to change notification settings - Fork 3
/
kvstore_test.go
59 lines (45 loc) · 1.2 KB
/
kvstore_test.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package orbitdb
import (
"fmt"
"time"
)
func ExampleKVStore() {
s1, err := NewOrbitDB(topic)
assert(err == nil, err)
time.Sleep(5 * time.Millisecond)
s2, err := NewOrbitDB(topic)
assert(err == nil, err)
kv1 := NewKVStore(s1)
kv2 := NewKVStore(s2)
fmt.Println("kv1: foo=bar")
err = kv1.Put("foo", "bar")
assert(err == nil, err)
time.Sleep(10 * time.Millisecond)
val2, err := kv2.Get("foo")
assert(err == nil, err)
assert(val2 == "bar", "val2 != \"bar\"", val2)
fmt.Println("kv2: get foo -> bar")
val1, err := kv1.Get("foo")
assert(err == nil, err)
assert(val1 == "bar", "val1 != \"bar\"", val1)
fmt.Println("kv1: get foo -> bar")
fmt.Println("kv2: del(foo)")
err = kv2.Delete("foo")
assert(err == nil, err)
time.Sleep(10 * time.Millisecond)
val2, err = kv2.Get("foo")
assert(err == ErrNotFound, err)
assert(val2 == "", `val2 != ""`, val2)
fmt.Println("kv2: get foo -> ErrNotFound")
val1, err = kv1.Get("foo")
assert(err == ErrNotFound, err)
assert(val1 == "", `val1 != ""`, val1)
fmt.Println("kv1: get foo -> ErrNotFound")
//Output:
// kv1: foo=bar
// kv2: get foo -> bar
// kv1: get foo -> bar
// kv2: del(foo)
// kv2: get foo -> ErrNotFound
// kv1: get foo -> ErrNotFound
}