forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix many issues and get all tests passing
- Loading branch information
Showing
7 changed files
with
409 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package models | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
models "github.com/influxdata/telegraf/models/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func newTestDiskBuffer(t testing.TB) Buffer { | ||
t.Helper() | ||
path, err := os.MkdirTemp("", "*-buffer-test") | ||
require.NoError(t, err) | ||
buf, err := NewBuffer("test", "", 0, "disk", path) | ||
require.NoError(t, err) | ||
buf.Stats().MetricsAdded.Set(0) | ||
buf.Stats().MetricsWritten.Set(0) | ||
buf.Stats().MetricsDropped.Set(0) | ||
return buf | ||
} | ||
|
||
func TestBuffer_AddCallsMetricAccept(t *testing.T) { | ||
var accept int | ||
mm := &models.MockMetric{ | ||
Metric: Metric(), | ||
AcceptF: func() { | ||
accept++ | ||
}, | ||
} | ||
b := newTestDiskBuffer(t) | ||
b.Add(mm, mm, mm) | ||
batch := b.Batch(2) | ||
b.Accept(batch) | ||
// all 3 metrics should be accepted as metric Accept() is called on buffer Add() | ||
require.Equal(t, 3, accept) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package models | ||
|
||
import ( | ||
"testing" | ||
|
||
models "github.com/influxdata/telegraf/models/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func newTestMemoryBuffer(t testing.TB, capacity int) Buffer { | ||
t.Helper() | ||
buf, err := NewBuffer("test", "", capacity, "memory", "") | ||
require.NoError(t, err) | ||
buf.Stats().MetricsAdded.Set(0) | ||
buf.Stats().MetricsWritten.Set(0) | ||
buf.Stats().MetricsDropped.Set(0) | ||
return buf | ||
} | ||
|
||
func TestBuffer_AcceptCallsMetricAccept(t *testing.T) { | ||
var accept int | ||
mm := &models.MockMetric{ | ||
Metric: Metric(), | ||
AcceptF: func() { | ||
accept++ | ||
}, | ||
} | ||
b := newTestMemoryBuffer(t, 5) | ||
b.Add(mm, mm, mm) | ||
batch := b.Batch(2) | ||
b.Accept(batch) | ||
require.Equal(t, 2, accept) | ||
} | ||
|
||
func TestBuffer_RejectCallsMetricRejectWithOverwritten(t *testing.T) { | ||
var reject int | ||
mm := &models.MockMetric{ | ||
Metric: Metric(), | ||
RejectF: func() { | ||
reject++ | ||
}, | ||
} | ||
b := newTestMemoryBuffer(t, 5) | ||
b.Add(mm, mm, mm, mm, mm) | ||
batch := b.Batch(5) | ||
b.Add(mm, mm) | ||
require.Equal(t, 0, reject) | ||
b.Reject(batch) | ||
require.Equal(t, 2, reject) | ||
} | ||
|
||
func BenchmarkMemoryAddMetrics(b *testing.B) { | ||
buf := newTestMemoryBuffer(b, 10000) | ||
m := Metric() | ||
for n := 0; n < b.N; n++ { | ||
buf.Add(m) | ||
} | ||
} |
Oops, something went wrong.