-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine_test.go
More file actions
116 lines (101 loc) · 3.21 KB
/
engine_test.go
File metadata and controls
116 lines (101 loc) · 3.21 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright (c) 2019 uplus.io
*/
package uengine
import (
"fmt"
"testing"
"github.com/uplus-io/uengine/model"
"github.com/uplus-io/ugo/utils"
)
func TestEngine_AddPart(t *testing.T) {
engine := createEngine()
defer engine.Close()
engine.AddPart(model.Partition{Id: 1000, Version: VERSION, Index: 0})
engine.AddPart(model.Partition{Id: 1001, Version: VERSION, Index: 1})
fmt.Printf("part0 info - %s\n", engine.GetPart(1000).String())
fmt.Printf("part1 info - %s\n", engine.GetPart(1001).String())
}
func TestEngine_SetData(t *testing.T) {
engine := createEngine()
defer engine.Close()
var err error
identity1 := NewIdOfData("udb", "user", []byte("1"))
identity2 := NewIdOfData("udb", "user", []byte("2"))
err = engine.SetData(1000, *NewData(*identity1, utils.LInt32ToBytes(101)),true)
printError(err, "set data error")
err = engine.SetData(1001, *NewData(*identity2, utils.LInt32ToBytes(102)),true)
printError(err, "set data error")
_,val1, _ := engine.GetData(1000, *identity1)
printDataContent(identity1.Key, val1)
_,val2, _ := engine.GetData(1001, *identity2)
printDataContent(identity2.Key, val2)
printAllData(engine)
}
func printError(err error, format string, args ...interface{}) {
if err != nil {
msg := fmt.Sprintf(format, args...)
fmt.Printf("%s - %v\n", msg, err)
}
}
func printDataContent(key []byte, data *model.DataContent) {
fmt.Printf("data key:%s content[%s]\n", key, data.String())
}
func printAllData(engine *Engine) {
fmt.Printf("meta part|meta---------------------------\n")
metaOperator := engine.meta
printMetaStorage(metaOperator)
fmt.Printf("meta part|data---------------------------\n")
printDataStorage(metaOperator)
fmt.Printf("meta ns tab---------------------------\n")
printNSAndTAB(metaOperator)
for i := 0; i < len(engine.partitions); i++ {
fmt.Printf("data part[%d]|meta---------------------------\n", i)
operator := engine.partitions[i]
printMetaStorage(operator)
fmt.Printf("data part[%d]|data---------------------------\n", i)
printDataStorage(operator)
fmt.Printf("data part[%d]|ns tab---------------------------\n", i)
printNSAndTAB(operator)
}
}
func printNSAndTAB(operator StoreOperator) {
nss := operator.NSs()
for _, ns := range nss {
fmt.Printf("ns[%s]---------------------------\n", ns.String())
tables := operator.TABs(ns.Name)
for _, tab := range tables {
fmt.Printf("tab[%s]---------------------------\n", tab.String())
}
}
}
func printMetaStorage(operator StoreOperator) {
operator.MetaForEach(func(key []byte, meta model.DataMeta) bool {
printMetaInfo(key,&meta)
return true
})
}
func printDataStorage(operator StoreOperator) {
operator.DataForEach(func(key, data []byte) bool {
printDataInfo(key, data)
return true
})
}
func printDataInfo(key []byte, data []byte) {
fmt.Printf("data key:%s valLen:%d\n", string(key), len(data))
}
func printMetaInfo(key []byte, data *model.DataMeta) {
fmt.Printf("meta key:%s val:%s\n", string(key), data.String())
}
func createEngine() *Engine {
cfg := UEngineConfig{
Engine: "BADGER",
Meta: "./test-data/engine-test/meta",
Wal: "./test-data/engine-test/wal",
Partitions: []string{
"./test-data/engine-test/data/0",
"./test-data/engine-test/data/1",
},
}
return NewEngine(cfg)
}