forked from deepkaran/goforestdb
-
Notifications
You must be signed in to change notification settings - Fork 6
/
pool_test.go
49 lines (40 loc) · 930 Bytes
/
pool_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
package forestdb
import (
"os"
"testing"
)
func TestPool(t *testing.T) {
defer os.RemoveAll("test")
// create a pool of 10 forestdb clients for file: test kvstore: default
fdbConfig := DefaultConfig()
kvConfig := DefaultKVStoreConfig()
kvpool, err := NewKVPool("test", fdbConfig, "default", kvConfig, 10)
if err != nil {
t.Fatal(err)
}
// get from the pool
kvs, err := kvpool.Get()
if err != nil {
t.Fatal(err)
}
// return to pool
err = kvpool.Return(kvs)
if err != nil {
t.Fatal(err)
}
// close the pool
err = kvpool.Close()
if err != nil {
t.Fatal(err)
}
// try to get after closing
_, err = kvpool.Get()
if err != PoolClosed {
t.Errorf("expected %v, got %v when calling Get on closed pool", PoolClosed, err)
}
// try to return after closing
err = kvpool.Return(kvs)
if err != PoolClosed {
t.Errorf("expected %v, got %v when calling Return on closed pool", PoolClosed, err)
}
}