1
0
Fork 0

Clear func

This commit is contained in:
Gregory Eremin 2014-08-12 17:14:53 +07:00
parent 57ea4b463e
commit b3bb3000bd
2 changed files with 18 additions and 0 deletions

View File

@ -56,7 +56,10 @@ func (b *Buffer) Flush() {
}
go b.fn(sbuffer)
b.Clear()
}
func (b *Buffer) Clear() {
b.series = make(map[string]*influxdb.Series)
b.size = 0
}

View File

@ -53,6 +53,21 @@ func TestFlush(t *testing.T) {
}
}
func TestClear(t *testing.T) {
fn := func(series []*influxdb.Series) {}
b := NewBuffer(10, fn)
defer b.Close()
b.Add(&influxdb.Series{})
if b.Size() != 1 {
t.Error("Expected buffer to contain 1 series before clearing, got %d", b.Size())
}
b.Clear()
if b.Size() != 0 {
t.Error("Expected buffer to be empty after clearing, got %d series", b.Size())
}
}
func TestLookup(t *testing.T) {
fn := func(series []*influxdb.Series) {}
b := NewBuffer(10, fn)