-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e_test.go
81 lines (77 loc) · 2.13 KB
/
e2e_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
package test
import (
"fmt"
"os"
"testing"
"time"
"github.com/scalog/scalog/client"
"github.com/scalog/scalog/data"
disc "github.com/scalog/scalog/discovery"
"github.com/scalog/scalog/order"
"github.com/scalog/scalog/pkg/address"
"github.com/spf13/viper"
)
func TestEnd2End(t *testing.T) {
// clean up old files
err := os.RemoveAll("log")
if err != nil {
t.Errorf("%v", err)
}
// read configuration file
viper.SetConfigFile("../.scalog.yaml")
viper.AutomaticEnv()
err = viper.ReadInConfig()
if err != nil {
t.Errorf("read config file error: %v", err)
}
// start servers
for i := 0; i < 3; i++ { // number of raft replicas
go order.StartOrder(int32(i))
}
for i := 0; i < 2; i++ { // number of shards
for j := 0; j < 2; j++ { // number of replicas in each shard
go data.StartData(int32(i), int32(j))
}
}
go disc.Start()
// start a client and run the test
time.Sleep(2 * time.Second)
numReplica := int32(viper.GetInt("data-replication-factor"))
discPort := uint16(viper.GetInt("disc-port"))
discIp := viper.GetString(fmt.Sprintf("disc-ip"))
// discAddr := address.NewLocalDiscAddr(discPort)
discAddr := address.NewGeneralDiscAddr(discIp, discPort)
dataPort := uint16(viper.GetInt("data-port"))
// dataIp := viper.GetString(fmt.Sprintf("data-%v-%v-ip", 0, 0))
// dataAddr := address.NewLocalDataAddr(numReplica, dataPort)
dataAddr := address.NewGeneralDataAddr("data-%v-%v-ip", numReplica, dataPort)
cli, err := client.NewClient(dataAddr, discAddr, numReplica)
if err != nil {
t.Errorf("create client failure: %v", err)
}
time.Sleep(time.Second)
record := "hello"
gsn, sid, err := cli.AppendOne(record)
if err != nil {
t.Errorf("write record failure: %v", err)
}
if gsn < 0 {
t.Errorf("error global sequence number (should be non-negative): %v", gsn)
}
if sid < 0 {
t.Errorf("error shard (should be non-negative): %v", sid)
}
rid := int32(0)
rec, err := cli.Read(gsn, sid, rid)
if err != nil {
t.Errorf("read record failure: %v", err)
}
if rec != record {
t.Errorf("read different from write: %v vs %v", rec, record)
}
// clean up
err = os.RemoveAll("log")
if err != nil {
t.Errorf("%v", err)
}
}