forked from HdrHistogram/hdrhistogram-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_writer_test.go
81 lines (76 loc) · 2.44 KB
/
log_writer_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 hdrhistogram
import (
"bytes"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)
func TestHistogramLogWriter_empty(t *testing.T) {
var b bytes.Buffer
writer := NewHistogramLogWriter(&b)
err := writer.OutputLogFormatVersion()
assert.Nil(t, err)
var startTimeWritten int64 = 1000
err = writer.OutputStartTime(startTimeWritten)
assert.Nil(t, err)
err = writer.OutputLogFormatVersion()
assert.Nil(t, err)
err = writer.OutputLegend()
assert.Nil(t, err)
got, _ := b.ReadString('\n')
want := "#[Histogram log format version 1.3]\n"
assert.Equal(t, want, got)
got, _ = b.ReadString('\n')
// avoid failing tests due to GMT time differences ( so we want all to be equal up until the first + )
want = "#[StartTime: 1 (seconds since epoch), 1970-01-01"
assert.Contains(t, got, want)
}
func TestHistogramLogWriterReader(t *testing.T) {
var b bytes.Buffer
writer := NewHistogramLogWriter(&b)
err := writer.OutputLogFormatVersion()
assert.Equal(t, nil, err)
var startTimeWritten int64 = 1000
err = writer.OutputStartTime(startTimeWritten)
assert.Nil(t, err)
err = writer.OutputLogFormatVersion()
assert.Nil(t, err)
err = writer.OutputLegend()
assert.Nil(t, err)
histogram := New(1, 1000, 3)
for i := 0; i < 10; i++ {
err = histogram.RecordValue(int64(i))
assert.Nil(t, err)
}
err = writer.OutputIntervalHistogram(histogram)
assert.Equal(t, nil, err)
r := bytes.NewReader(b.Bytes())
reader := NewHistogramLogReader(r)
outHistogram, err := reader.NextIntervalHistogram()
assert.Equal(t, nil, err)
assert.Equal(t, histogram.TotalCount(), outHistogram.TotalCount())
assert.Equal(t, histogram.LowestTrackableValue(), outHistogram.LowestTrackableValue())
assert.Equal(t, histogram.HighestTrackableValue(), outHistogram.HighestTrackableValue())
}
func TestHistogramLogReader_logV2(t *testing.T) {
dat, err := ioutil.ReadFile("./test/jHiccup-2.0.7S.logV2.hlog")
assert.Equal(t, nil, err)
r := bytes.NewReader(dat)
reader := NewHistogramLogReader(r)
for i := 0; i < 61; i++ {
outHistogram, err := reader.NextIntervalHistogram()
assert.Equal(t, nil, err)
assert.NotNil(t, outHistogram)
}
}
func TestHistogramLogReader_tagged_log(t *testing.T) {
dat, err := ioutil.ReadFile("./test/tagged-Log.logV2.hlog")
assert.Equal(t, nil, err)
r := bytes.NewReader(dat)
reader := NewHistogramLogReader(r)
for i := 0; i < 42; i++ {
outHistogram, err := reader.NextIntervalHistogram()
assert.Equal(t, nil, err)
assert.NotNil(t, outHistogram)
}
}