forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nuts_store_test.go
81 lines (65 loc) · 1.84 KB
/
nuts_store_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 quickfix
import (
"fmt"
"os"
"path"
"testing"
"github.com/nutsdb/nutsdb"
"github.com/stretchr/testify/require"
)
func TestSetup(t *testing.T) {
// create settings
sessionID := SessionID{BeginString: "FIX.4.4", SenderCompID: "SENDER", TargetCompID: "TARGET"}
// settings, err := ParseSettings(strings.NewReader(fmt.Sprintf(`
// [DEFAULT]
// TimeStampPrecision=MICROS
// [SESSION]
// Tenant=lb_hk
// BeginString=%s
// SenderCompID=%s
// TargetCompID=%s`, sessionID.BeginString, sessionID.SenderCompID, sessionID.TargetCompID)))
// require.Nil(t, err)
file := path.Join(os.TempDir(), fmt.Sprintf("%d", os.Getpid()))
file = path.Join(file, "/tmp/nutsdb")
db, err := nutsdb.Open(
nutsdb.DefaultOptions,
nutsdb.WithSyncEnable(false),
nutsdb.WithRWMode(nutsdb.MMap),
nutsdb.WithDir(file),
nutsdb.WithEntryIdxMode(nutsdb.HintKeyValAndRAMIdxMode),
)
require.Nil(t, err)
defer os.RemoveAll(file)
messageStoreFactory := NewNutsDbStoreFactory(db)
store, err := messageStoreFactory.Create(sessionID)
require.Nil(t, err)
require.NotNil(t, store)
for i := 0; i < 10; i++ {
err = store.SaveMessage(i, []byte(fmt.Sprintf("hello_%v", i)))
require.Nil(t, err)
err = store.IncrNextSenderMsgSeqNum()
require.Nil(t, err)
}
bs, err := store.GetMessages(0, 1)
require.Nil(t, err)
require.Equal(t, len(bs), 2)
bs, err = store.GetMessages(1, 10)
require.Nil(t, err)
require.Equal(t, len(bs), 9)
err = store.Reset()
require.Nil(t, err)
bs, err = store.GetMessages(0, 1)
require.Nil(t, err)
require.Equal(t, len(bs), 0)
for i := 0; i < 100; i++ {
err = store.SaveMessage(i, []byte(fmt.Sprintf("hello_%v", i)))
require.Nil(t, err)
err = store.IncrNextSenderMsgSeqNum()
require.Nil(t, err)
}
bs, err = store.GetMessages(0, 100)
require.Nil(t, err)
require.Equal(t, len(bs), 100)
err = store.Close()
require.Nil(t, err)
}