2021-09-09 11:19:29 -05:00
|
|
|
package pipeline
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testBuilder struct{}
|
|
|
|
|
|
|
|
func (t *testBuilder) BuildRules(_ context.Context, _ int64) ([]*LiveChannelRule, error) {
|
|
|
|
return []*LiveChannelRule{
|
|
|
|
{
|
2021-11-09 04:10:43 -06:00
|
|
|
OrgId: 1,
|
|
|
|
Pattern: "stream/telegraf/cpu",
|
2021-09-09 11:19:29 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
OrgId: 1,
|
|
|
|
Pattern: "stream/telegraf/:metric",
|
|
|
|
},
|
|
|
|
{
|
2021-10-06 12:43:25 -05:00
|
|
|
OrgId: 1,
|
|
|
|
Pattern: "stream/telegraf/:metric/:extra",
|
2021-09-30 11:29:32 -05:00
|
|
|
},
|
|
|
|
{
|
2021-11-09 04:10:43 -06:00
|
|
|
OrgId: 1,
|
|
|
|
Pattern: "stream/boom:er",
|
2021-09-09 11:19:29 -05:00
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStorage_Get(t *testing.T) {
|
|
|
|
s := NewCacheSegmentedTree(&testBuilder{})
|
|
|
|
rule, ok, err := s.Get(1, "stream/telegraf/cpu")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ok)
|
2021-11-09 04:10:43 -06:00
|
|
|
require.Equal(t, "stream/telegraf/cpu", rule.Pattern)
|
2021-09-09 11:19:29 -05:00
|
|
|
|
|
|
|
rule, ok, err = s.Get(1, "stream/telegraf/mem")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ok)
|
2021-11-09 04:10:43 -06:00
|
|
|
require.Equal(t, "stream/telegraf/:metric", rule.Pattern)
|
2021-09-09 11:19:29 -05:00
|
|
|
|
|
|
|
rule, ok, err = s.Get(1, "stream/telegraf/mem/rss")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ok)
|
2021-11-09 04:10:43 -06:00
|
|
|
require.Equal(t, "stream/telegraf/:metric/:extra", rule.Pattern)
|
2021-09-30 11:29:32 -05:00
|
|
|
|
|
|
|
rule, ok, err = s.Get(1, "stream/booms")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, ok)
|
2021-11-09 04:10:43 -06:00
|
|
|
require.Equal(t, "stream/boom:er", rule.Pattern)
|
2021-09-09 11:19:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkRuleGet(b *testing.B) {
|
|
|
|
s := NewCacheSegmentedTree(&testBuilder{})
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_, ok, err := s.Get(1, "stream/telegraf/cpu")
|
|
|
|
if err != nil || !ok {
|
|
|
|
b.Fatal("unexpected return values")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|