forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
141 lines (124 loc) · 4.37 KB
/
config_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package tsdb_test
import (
"testing"
"time"
"github.com/BurntSushi/toml"
"github.com/influxdata/influxdb/v2/tsdb"
)
func TestConfig_Parse(t *testing.T) {
// Parse configuration.
c := tsdb.NewConfig()
if _, err := toml.Decode(`
dir = "/var/lib/influxdb/data"
wal-dir = "/var/lib/influxdb/wal"
wal-fsync-delay = "10s"
tsm-use-madv-willneed = true
`, &c); err != nil {
t.Fatal(err)
}
if err := c.Validate(); err != nil {
t.Errorf("unexpected validate error: %s", err)
}
if got, exp := c.Dir, "/var/lib/influxdb/data"; got != exp {
t.Errorf("unexpected dir:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.WALDir, "/var/lib/influxdb/wal"; got != exp {
t.Errorf("unexpected wal-dir:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.WALFsyncDelay, time.Duration(10*time.Second); time.Duration(got).Nanoseconds() != exp.Nanoseconds() {
t.Errorf("unexpected wal-fsync-delay:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.TSMWillNeed, true; got != exp {
t.Errorf("unexpected tsm-madv-willneed:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
}
func TestConfig_Validate_Error(t *testing.T) {
c := tsdb.NewConfig()
if err := c.Validate(); err == nil || err.Error() != "Data.Dir must be specified" {
t.Errorf("unexpected error: %s", err)
}
c.Dir = "/var/lib/influxdb/data"
if err := c.Validate(); err == nil || err.Error() != "Data.WALDir must be specified" {
t.Errorf("unexpected error: %s", err)
}
c.WALDir = "/var/lib/influxdb/wal"
c.Engine = "fake1"
if err := c.Validate(); err == nil || err.Error() != "unrecognized engine fake1" {
t.Errorf("unexpected error: %s", err)
}
c.Engine = "tsm1"
c.Index = "foo"
if err := c.Validate(); err == nil || err.Error() != "unrecognized index foo" {
t.Errorf("unexpected error: %s", err)
}
c.Index = tsdb.TSI1IndexName
if err := c.Validate(); err != nil {
t.Error(err)
}
c.SeriesIDSetCacheSize = -1
if err := c.Validate(); err == nil || err.Error() != "series-id-set-cache-size must be non-negative" {
t.Errorf("unexpected error: %s", err)
}
}
func TestConfig_ByteSizes(t *testing.T) {
// Parse configuration.
c := tsdb.NewConfig()
if _, err := toml.Decode(`
dir = "/var/lib/influxdb/data"
wal-dir = "/var/lib/influxdb/wal"
wal-fsync-delay = "10s"
cache-max-memory-size = 5368709120
cache-snapshot-memory-size = 104857600
`, &c); err != nil {
t.Fatal(err)
}
if err := c.Validate(); err != nil {
t.Errorf("unexpected validate error: %s", err)
}
if got, exp := c.Dir, "/var/lib/influxdb/data"; got != exp {
t.Errorf("unexpected dir:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.WALDir, "/var/lib/influxdb/wal"; got != exp {
t.Errorf("unexpected wal-dir:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.WALFsyncDelay, time.Duration(10*time.Second); time.Duration(got).Nanoseconds() != exp.Nanoseconds() {
t.Errorf("unexpected wal-fsync-delay:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.CacheMaxMemorySize, uint64(5<<30); uint64(got) != exp {
t.Errorf("unexpected cache-max-memory-size:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.CacheSnapshotMemorySize, uint64(100<<20); uint64(got) != exp {
t.Errorf("unexpected cache-snapshot-memory-size:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
}
func TestConfig_HumanReadableSizes(t *testing.T) {
// Parse configuration.
c := tsdb.NewConfig()
if _, err := toml.Decode(`
dir = "/var/lib/influxdb/data"
wal-dir = "/var/lib/influxdb/wal"
wal-fsync-delay = "10s"
cache-max-memory-size = "5gib"
cache-snapshot-memory-size = "100mib"
`, &c); err != nil {
t.Fatal(err)
}
if err := c.Validate(); err != nil {
t.Errorf("unexpected validate error: %s", err)
}
if got, exp := c.Dir, "/var/lib/influxdb/data"; got != exp {
t.Errorf("unexpected dir:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.WALDir, "/var/lib/influxdb/wal"; got != exp {
t.Errorf("unexpected wal-dir:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.WALFsyncDelay, time.Duration(10*time.Second); time.Duration(got).Nanoseconds() != exp.Nanoseconds() {
t.Errorf("unexpected wal-fsync-delay:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.CacheMaxMemorySize, uint64(5<<30); uint64(got) != exp {
t.Errorf("unexpected cache-max-memory-size:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
if got, exp := c.CacheSnapshotMemorySize, uint64(100<<20); uint64(got) != exp {
t.Errorf("unexpected cache-snapshot-memory-size:\n\nexp=%v\n\ngot=%v\n\n", exp, got)
}
}