influxdb/services/precreator/service_test.go

56 lines
1.2 KiB
Go
Raw Normal View History

package precreator
2015-06-10 19:56:22 +00:00
import (
"sync"
2015-06-10 19:56:22 +00:00
"testing"
"time"
"github.com/influxdata/influxdb/toml"
2015-06-10 19:56:22 +00:00
)
func Test_ShardPrecreation(t *testing.T) {
t.Parallel()
now := time.Now().UTC()
advancePeriod := 5 * time.Minute
2015-06-10 19:56:22 +00:00
// A test metastaore which returns 2 shard groups, only 1 of which requires a successor.
var wg sync.WaitGroup
wg.Add(1)
2016-01-20 00:04:42 +00:00
ms := metaClient{
PrecreateShardGroupsFn: func(v, u time.Time) error {
wg.Done()
if u != now.Add(advancePeriod) {
t.Fatalf("precreation called with wrong time, got %s, exp %s", u, now)
2015-06-10 19:56:22 +00:00
}
return nil
2015-06-10 19:56:22 +00:00
},
}
srv, err := NewService(Config{
CheckInterval: toml.Duration(time.Minute),
AdvancePeriod: toml.Duration(advancePeriod),
2015-06-10 19:56:22 +00:00
})
if err != nil {
t.Fatalf("failed to create shard precreation service: %s", err.Error())
}
2016-01-20 00:04:42 +00:00
srv.MetaClient = ms
2015-06-10 19:56:22 +00:00
err = srv.precreate(now)
2015-06-10 19:56:22 +00:00
if err != nil {
t.Fatalf("failed to precreate shards: %s", err.Error())
}
2016-01-20 00:04:42 +00:00
wg.Wait() // Ensure metaClient test function is called.
2015-06-10 19:56:22 +00:00
return
}
// PointsWriter represents a mock impl of PointsWriter.
2016-01-20 00:04:42 +00:00
type metaClient struct {
PrecreateShardGroupsFn func(now, cutoff time.Time) error
2015-06-10 19:56:22 +00:00
}
2016-01-20 00:04:42 +00:00
func (m metaClient) PrecreateShardGroups(now, cutoff time.Time) error {
return m.PrecreateShardGroupsFn(now, cutoff)
2015-06-10 19:56:22 +00:00
}