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
|
package sfive
import (
"testing"
"time"
)
func TestAppend(t *testing.T) {
store, err := NewStore(false, "file:memdb1?mode=memory&cache=shared")
if err != nil {
t.Errorf("Failed to initialize: %v", err)
return
}
defer store.Close()
startTime := time.Date(2014, time.August, 24, 14, 35, 33, 847282000, time.UTC)
update := DataUpdate{Data: SourceData{BytesSent: 1, ClientCount: 3, BytesReceived: 1}, StartTime: startTime, Duration: 5}
streamId := StreamId{ContentId: "content", Format: "7bitascii", Quality: QualityHigh}
source := SourceId{Hostname: "localhost", Tags: []string{"tag1", "master"}, StreamId: streamId, Version: 1}
dat := StatisticsData{nil, nil, source, update}
err = store.Append(dat)
if err != nil {
t.Errorf("Failed to append: %v", err)
return
}
stats, err := store.GetStats(nil)
if err != nil {
t.Errorf("Failed to get stats: %v", err)
} else {
clientCount := int(stats.ClientCount)
updateCount := stats.UpdateCount
if 3 != clientCount {
t.Errorf("Failed fo append, invalid number of clients, 3 != %v", clientCount)
}
if 1 != updateCount {
t.Errorf("Failed to append, invalid number of updates, 1 != %v", updateCount)
}
}
queryStartTime := time.Date(2015, time.December, 24, 1, 1, 1, 0, time.UTC)
filterStruct := StatsFilter{start: &queryStartTime}
stats, err = store.GetStats(&filterStruct)
if err != nil {
t.Errorf("Failed to get stats: %v", err)
} else {
updateCount := stats.UpdateCount
if 0 != updateCount {
t.Errorf("Failed to filter entries by start time, 0 != %v", updateCount)
}
}
}
func TestCount(t *testing.T) {
store, err := NewStore(false, "file:memdb1?mode=memory&cache=shared")
if err != nil {
t.Errorf("Failed to initialize: %v", err)
}
defer store.Close()
stats, err := store.GetStats(nil)
clientCount := int(stats.ClientCount)
if 0 != clientCount {
t.Errorf("Failed to count correctly.")
}
}
func TestGetUpdatesAfter(t *testing.T) {
store, err := NewStore(false, "file:memdb1?mode=memory&cache=shared")
if err != nil {
t.Errorf("Failed to initialize: %v", err)
return
}
defer store.Close()
startTime := time.Date(2014, time.August, 24, 14, 35, 33, 847282000, time.UTC)
update := DataUpdate{Data: SourceData{BytesSent: 1, ClientCount: 3, BytesReceived: 1}, StartTime: startTime, Duration: 5}
streamId := StreamId{ContentId: "content", Format: "7bitascii", Quality: QualityHigh}
source := SourceId{Hostname: "localhost", Tags: []string{"tag1", "master"}, StreamId: streamId, Version: 1}
dat := StatisticsData{nil, nil, source, update}
err = store.Append(dat)
if err != nil {
t.Errorf("Failed to append: %v", err)
return
}
res, err := store.GetUpdatesAfter(2)
t.Logf("got updates (err %v):\n%#v", err, res)
}
|