Tidy up test initialisation
parent
8a00870616
commit
ef5e3a09cd
|
@ -691,10 +691,7 @@ func TestShard_Close_RemoveIndex(t *testing.T) {
|
||||||
func TestShard_CreateIterator_Ascending(t *testing.T) {
|
func TestShard_CreateIterator_Ascending(t *testing.T) {
|
||||||
for _, index := range tsdb.RegisteredIndexes() {
|
for _, index := range tsdb.RegisteredIndexes() {
|
||||||
t.Run(index, func(t *testing.T) {
|
t.Run(index, func(t *testing.T) {
|
||||||
sfile := MustOpenSeriesFile()
|
sh := NewShard(index)
|
||||||
defer sfile.Close()
|
|
||||||
|
|
||||||
sh := NewShard(index, sfile.SeriesFile)
|
|
||||||
defer sh.Close()
|
defer sh.Close()
|
||||||
|
|
||||||
// Calling CreateIterator when the engine is not open will return
|
// Calling CreateIterator when the engine is not open will return
|
||||||
|
@ -778,10 +775,7 @@ func TestShard_CreateIterator_Descending(t *testing.T) {
|
||||||
var itr query.Iterator
|
var itr query.Iterator
|
||||||
|
|
||||||
test := func(index string) {
|
test := func(index string) {
|
||||||
sfile := MustOpenSeriesFile()
|
sh = NewShard(index)
|
||||||
defer sfile.Close()
|
|
||||||
|
|
||||||
sh = NewShard(index, sfile.SeriesFile)
|
|
||||||
|
|
||||||
// Calling CreateIterator when the engine is not open will return
|
// Calling CreateIterator when the engine is not open will return
|
||||||
// ErrEngineClosed.
|
// ErrEngineClosed.
|
||||||
|
@ -883,10 +877,7 @@ func TestShard_CreateIterator_Series_Auth(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
test := func(index string, v variant) error {
|
test := func(index string, v variant) error {
|
||||||
sfile := MustOpenSeriesFile()
|
sh := MustNewOpenShard(index)
|
||||||
defer sfile.Close()
|
|
||||||
|
|
||||||
sh := MustNewOpenShard(index, sfile.SeriesFile)
|
|
||||||
defer sh.Close()
|
defer sh.Close()
|
||||||
sh.MustWritePointsString(`
|
sh.MustWritePointsString(`
|
||||||
cpu,host=serverA,region=uswest value=100 0
|
cpu,host=serverA,region=uswest value=100 0
|
||||||
|
@ -1015,10 +1006,7 @@ func TestShard_Disabled_WriteQuery(t *testing.T) {
|
||||||
var sh *Shard
|
var sh *Shard
|
||||||
|
|
||||||
test := func(index string) {
|
test := func(index string) {
|
||||||
sfile := MustOpenSeriesFile()
|
sh = NewShard(index)
|
||||||
defer sfile.Close()
|
|
||||||
|
|
||||||
sh = NewShard(index, sfile.SeriesFile)
|
|
||||||
if err := sh.Open(); err != nil {
|
if err := sh.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1069,10 +1057,7 @@ func TestShard_Disabled_WriteQuery(t *testing.T) {
|
||||||
func TestShard_Closed_Functions(t *testing.T) {
|
func TestShard_Closed_Functions(t *testing.T) {
|
||||||
var sh *Shard
|
var sh *Shard
|
||||||
test := func(index string) {
|
test := func(index string) {
|
||||||
sfile := MustOpenSeriesFile()
|
sh = NewShard(index)
|
||||||
defer sfile.Close()
|
|
||||||
|
|
||||||
sh = NewShard(index, sfile.SeriesFile)
|
|
||||||
if err := sh.Open(); err != nil {
|
if err := sh.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1108,7 +1093,7 @@ func TestShard_FieldDimensions(t *testing.T) {
|
||||||
defer sfile.Close()
|
defer sfile.Close()
|
||||||
|
|
||||||
setup := func(index string) {
|
setup := func(index string) {
|
||||||
sh = NewShard(index, sfile.SeriesFile)
|
sh = NewShard(index)
|
||||||
|
|
||||||
if err := sh.Open(); err != nil {
|
if err := sh.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1223,11 +1208,8 @@ _reserved,region=uswest value="foo" 0
|
||||||
func TestShards_FieldDimensions(t *testing.T) {
|
func TestShards_FieldDimensions(t *testing.T) {
|
||||||
var shard1, shard2 *Shard
|
var shard1, shard2 *Shard
|
||||||
|
|
||||||
sfile := MustOpenSeriesFile()
|
|
||||||
defer sfile.Close()
|
|
||||||
|
|
||||||
setup := func(index string) {
|
setup := func(index string) {
|
||||||
shard1 = NewShard(index, sfile.SeriesFile)
|
shard1 = NewShard(index)
|
||||||
if err := shard1.Open(); err != nil {
|
if err := shard1.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1238,7 +1220,7 @@ cpu,host=serverA,region=uswest value=50,val2=5 10
|
||||||
cpu,host=serverB,region=uswest value=25 0
|
cpu,host=serverB,region=uswest value=25 0
|
||||||
`)
|
`)
|
||||||
|
|
||||||
shard2 = NewShard(index, sfile.SeriesFile)
|
shard2 = NewShard(index)
|
||||||
if err := shard2.Open(); err != nil {
|
if err := shard2.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1352,10 +1334,7 @@ func TestShards_MapType(t *testing.T) {
|
||||||
var shard1, shard2 *Shard
|
var shard1, shard2 *Shard
|
||||||
|
|
||||||
setup := func(index string) {
|
setup := func(index string) {
|
||||||
sfile := MustOpenSeriesFile()
|
shard1 = NewShard(index)
|
||||||
defer sfile.Close()
|
|
||||||
|
|
||||||
shard1 = NewShard(index, sfile.SeriesFile)
|
|
||||||
if err := shard1.Open(); err != nil {
|
if err := shard1.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1366,7 +1345,7 @@ cpu,host=serverA,region=uswest value=50,val2=5 10
|
||||||
cpu,host=serverB,region=uswest value=25 0
|
cpu,host=serverB,region=uswest value=25 0
|
||||||
`)
|
`)
|
||||||
|
|
||||||
shard2 = NewShard(index, sfile.SeriesFile)
|
shard2 = NewShard(index)
|
||||||
if err := shard2.Open(); err != nil {
|
if err := shard2.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1493,11 +1472,8 @@ _reserved,region=uswest value="foo" 0
|
||||||
func TestShards_MeasurementsByRegex(t *testing.T) {
|
func TestShards_MeasurementsByRegex(t *testing.T) {
|
||||||
var shard1, shard2 *Shard
|
var shard1, shard2 *Shard
|
||||||
|
|
||||||
sfile := MustOpenSeriesFile()
|
|
||||||
defer sfile.Close()
|
|
||||||
|
|
||||||
setup := func(index string) {
|
setup := func(index string) {
|
||||||
shard1 = NewShard(index, sfile.SeriesFile)
|
shard1 = NewShard(index)
|
||||||
if err := shard1.Open(); err != nil {
|
if err := shard1.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1508,7 +1484,7 @@ cpu,host=serverA,region=uswest value=50,val2=5 10
|
||||||
cpu,host=serverB,region=uswest value=25 0
|
cpu,host=serverB,region=uswest value=25 0
|
||||||
`)
|
`)
|
||||||
|
|
||||||
shard2 = NewShard(index, sfile.SeriesFile)
|
shard2 = NewShard(index)
|
||||||
if err := shard2.Open(); err != nil {
|
if err := shard2.Open(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1924,24 +1900,26 @@ func chunkedWrite(shard *tsdb.Shard, points []models.Point) {
|
||||||
// Shard represents a test wrapper for tsdb.Shard.
|
// Shard represents a test wrapper for tsdb.Shard.
|
||||||
type Shard struct {
|
type Shard struct {
|
||||||
*tsdb.Shard
|
*tsdb.Shard
|
||||||
sfile *tsdb.SeriesFile
|
sfile *SeriesFile
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewShard returns a new instance of Shard with temp paths.
|
// NewShard returns a new instance of Shard with temp paths.
|
||||||
func NewShard(index string, sfile *tsdb.SeriesFile) *Shard {
|
func NewShard(index string) *Shard {
|
||||||
// Create temporary path for data and WAL.
|
// Create temporary path for data and WAL.
|
||||||
dir, err := ioutil.TempDir("", "influxdb-tsdb-")
|
dir, err := ioutil.TempDir("", "influxdb-tsdb-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sfile := MustOpenSeriesFile()
|
||||||
|
|
||||||
// Build engine options.
|
// Build engine options.
|
||||||
opt := tsdb.NewEngineOptions()
|
opt := tsdb.NewEngineOptions()
|
||||||
opt.IndexVersion = index
|
opt.IndexVersion = index
|
||||||
opt.Config.WALDir = filepath.Join(dir, "wal")
|
opt.Config.WALDir = filepath.Join(dir, "wal")
|
||||||
if index == "inmem" {
|
if index == "inmem" {
|
||||||
opt.InmemIndex = inmem.NewIndex(path.Base(dir), sfile)
|
opt.InmemIndex = inmem.NewIndex(path.Base(dir), sfile.SeriesFile)
|
||||||
}
|
}
|
||||||
// Initialise series id sets. Need to do this as it's normally done at the
|
// Initialise series id sets. Need to do this as it's normally done at the
|
||||||
// store level.
|
// store level.
|
||||||
|
@ -1952,7 +1930,7 @@ func NewShard(index string, sfile *tsdb.SeriesFile) *Shard {
|
||||||
Shard: tsdb.NewShard(0,
|
Shard: tsdb.NewShard(0,
|
||||||
filepath.Join(dir, "data", "db0", "rp0", "1"),
|
filepath.Join(dir, "data", "db0", "rp0", "1"),
|
||||||
filepath.Join(dir, "wal", "db0", "rp0", "1"),
|
filepath.Join(dir, "wal", "db0", "rp0", "1"),
|
||||||
sfile,
|
sfile.SeriesFile,
|
||||||
opt,
|
opt,
|
||||||
),
|
),
|
||||||
sfile: sfile,
|
sfile: sfile,
|
||||||
|
@ -1961,8 +1939,8 @@ func NewShard(index string, sfile *tsdb.SeriesFile) *Shard {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustNewOpenShard creates and opens a shard with the provided index.
|
// MustNewOpenShard creates and opens a shard with the provided index.
|
||||||
func MustNewOpenShard(index string, sfile *tsdb.SeriesFile) *Shard {
|
func MustNewOpenShard(index string) *Shard {
|
||||||
sh := NewShard(index, sfile)
|
sh := NewShard(index)
|
||||||
if err := sh.Open(); err != nil {
|
if err := sh.Open(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -1971,6 +1949,11 @@ func MustNewOpenShard(index string, sfile *tsdb.SeriesFile) *Shard {
|
||||||
|
|
||||||
// Close closes the shard and removes all underlying data.
|
// Close closes the shard and removes all underlying data.
|
||||||
func (sh *Shard) Close() error {
|
func (sh *Shard) Close() error {
|
||||||
|
// Will remove temp series file data.
|
||||||
|
if err := sh.sfile.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
defer os.RemoveAll(sh.path)
|
defer os.RemoveAll(sh.path)
|
||||||
return sh.Shard.Close()
|
return sh.Shard.Close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue