-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
97 lines (76 loc) · 2.47 KB
/
client_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
package trr
import (
"log"
"os"
"testing"
"time"
)
func TestClientWithSingleServerWithRawData(t *testing.T) {
srv := StartServer("127.0.0.1:1234", 1)
client := MakeClerk("127.0.0.1:1234")
client.putRaw("t1", []byte("v1"))
ret := client.getRaw("t1")
log.Println("got:", ret)
if string(ret) != "v1" {
t.Error("Client get error:", ret)
}
srv.kill()
os.RemoveAll("trr-1")
}
func TestClientWithSingleServerWithTimeDataFirst(t *testing.T) {
t0, _ := time.ParseInLocation("Jan _2 2006 15:04:05", "Mar 24 2015 02:00:00", time.Local)
tunix := uint32(t0.Unix())
srv := StartServer("127.0.0.1:1239", 1)
client := MakeClerk("127.0.0.1:1239")
client.PutTimeData("t1", tunix, 10)
tt, vv, err := client.GetTimeData("t1")
if err != nil || tt != tunix || vv != 10 {
t.Error("Simple time get error", tt, vv, err)
}
tt, vv, err = client.GetTimeData("t1")
if err == nil {
t.Error("Should be error when no value", err)
}
srv.kill()
os.RemoveAll("trr-1")
}
func TestClientWithSingleServerWithTimeDataSecond(t *testing.T) {
t0, _ := time.ParseInLocation("Jan _2 2006 15:04:05", "Mar 24 2015 02:00:00", time.Local)
t0unix := uint32(t0.Unix())
srv := StartServer("127.0.0.1:1230", 1)
client := MakeClerk("127.0.0.1:1230")
client.PutTimeData("t1", t0unix, 10)
t1unix := t0unix + 62
client.PutTimeData("t1", t1unix, 12)
t2unix := t1unix + 62
client.PutTimeDataBack("t1", t2unix, 14)
tt, vv, err := client.GetTimeData("t1")
if err != nil || tt != t0unix || vv != 10 {
t.Error("Simple time get error", tt, vv, err)
}
tt, vv, err = client.GetTimeData("t1")
if err != nil || tt != t1unix || vv != 12 {
t.Error("Simple time get error", tt, vv, err)
}
tt, vv, err = client.GetTimeData("t2")
if err == nil {
t.Error("Should be error when no value", err)
}
tt, vv, err = client.GetTimeData("t1")
if err != nil || tt != t2unix || vv != 14 {
t.Error("Simple time get error", tt, vv, err)
}
srv.kill()
os.RemoveAll("trr-1")
}