Esempio n. 1
0
// TestInitEngines tests whether multiple engines specified as a
// single comma-separated list are parsed correctly.
func TestInitEngines(t *testing.T) {
	tmp := createTempDirs(2, t)
	defer resetTestData(tmp)

	stores := fmt.Sprintf("mem=1000,mem:ddr3=1000,ssd=%s,hdd:7200rpm=%s", tmp[0], tmp[1])
	expEngines := []struct {
		attrs engine.Attributes
		isMem bool
	}{
		{engine.Attributes([]string{"mem"}), true},
		{engine.Attributes([]string{"mem", "ddr3"}), true},
		{engine.Attributes([]string{"ssd"}), false},
		{engine.Attributes([]string{"hdd", "7200rpm"}), false},
	}

	engines, err := initEngines(stores)
	if err != nil {
		t.Fatal(err)
	}
	if len(engines) != len(expEngines) {
		t.Errorf("number of engines parsed %d != expected %d", len(engines), len(expEngines))
	}
	for i, e := range engines {
		if e.Attrs().SortedString() != expEngines[i].attrs.SortedString() {
			t.Errorf("wrong engine attributes, expected %v but got %v: %+v", expEngines[i].attrs, e.Attrs(), expEngines[i])
		}
		_, ok := e.(*engine.InMem)
		if expEngines[i].isMem != ok {
			t.Errorf("expected in memory? %b, got %b: %+v", expEngines[i].isMem, ok, expEngines[i])
		}
	}
}
Esempio n. 2
0
// parseAttributes parses a colon-separated list of strings,
// filtering empty strings (i.e. ",," will yield no attributes.
// Returns the list of strings as Attributes.
func parseAttributes(attrsStr string) engine.Attributes {
	var filtered []string
	for _, attr := range strings.Split(attrsStr, ":") {
		if len(attr) != 0 {
			filtered = append(filtered, attr)
		}
	}
	sort.Strings(filtered)
	return engine.Attributes(filtered)
}
Esempio n. 3
0
// filterStores returns just the store descriptors in the supplied
// stores slice which contain all the specified attributes.
func filterStores(a engine.Attributes, stores []*StoreDescriptor) ([]*StoreDescriptor, error) {
	var filtered []*StoreDescriptor
	for _, s := range stores {
		b := []string(s.Attrs)
		b = append(b, []string(s.Node.Attrs)...)
		if a.IsSubset(engine.Attributes(b)) {
			filtered = append(filtered, s)
		}
	}
	return filtered, nil
}
Esempio n. 4
0
// createTestEngine creates an in-memory engine and initializes some
// default configuration settings.
func createTestEngine(t *testing.T) engine.Engine {
	e := engine.NewInMem(engine.Attributes([]string{"dc1", "mem"}), 1<<20)
	if err := engine.PutI(e, engine.KeyConfigAccountingPrefix, testDefaultAcctConfig); err != nil {
		t.Fatal(err)
	}
	if err := engine.PutI(e, engine.KeyConfigPermissionPrefix, testDefaultPermConfig); err != nil {
		t.Fatal(err)
	}
	if err := engine.PutI(e, engine.KeyConfigZonePrefix, testDefaultZoneConfig); err != nil {
		t.Fatal(err)
	}
	return e
}
Esempio n. 5
0
// TestInitEngine tests whether the data directory string is parsed correctly.
func TestInitEngine(t *testing.T) {
	tmp := createTempDirs(5, t)
	defer resetTestData(tmp)

	testCases := []struct {
		key       string            // data directory
		expAttrs  engine.Attributes // attributes for engine
		wantError bool              // do we expect an error from this key?
		isMem     bool              // is the engine in-memory?
	}{
		{"mem=1000", engine.Attributes([]string{"mem"}), false, true},
		{"ssd=1000", engine.Attributes([]string{"ssd"}), false, true},
		{fmt.Sprintf("ssd=%s", tmp[0]), engine.Attributes([]string{"ssd"}), false, false},
		{fmt.Sprintf("hdd=%s", tmp[1]), engine.Attributes([]string{"hdd"}), false, false},
		{fmt.Sprintf("mem=%s", tmp[2]), engine.Attributes([]string{"mem"}), false, false},
		{fmt.Sprintf("abc=%s", tmp[3]), engine.Attributes([]string{"abc"}), false, false},
		{fmt.Sprintf("hdd:7200rpm=%s", tmp[4]), engine.Attributes([]string{"hdd", "7200rpm"}), false, false},
		{"hdd=/dev/null", engine.Attributes{}, true, false},
		{"", engine.Attributes{}, true, false},
		{"  ", engine.Attributes{}, true, false},
		{"arbitrarystring", engine.Attributes{}, true, false},
		{"mem=", engine.Attributes{}, true, false},
		{"ssd=", engine.Attributes{}, true, false},
		{"hdd=", engine.Attributes{}, true, false},
	}
	for _, spec := range testCases {
		engines, err := initEngines(spec.key)
		if err == nil {
			if spec.wantError {
				t.Fatalf("invalid engine spec '%v' erroneously accepted: %+v", spec.key, spec)
			}
			if len(engines) != 1 {
				t.Fatalf("unexpected number of engines: %d: %+v", len(engines), spec)
			}
			e := engines[0]
			if e.Attrs().SortedString() != spec.expAttrs.SortedString() {
				t.Errorf("wrong engine attributes, expected %v but got %v: %+v", spec.expAttrs, e.Attrs(), spec)
			}
			_, ok := e.(*engine.InMem)
			if spec.isMem != ok {
				t.Errorf("expected in memory? %b, got %b: %+v", spec.isMem, ok, spec)
			}
		} else if !spec.wantError {
			t.Errorf("expected no error, got %v: %+v", err, spec)
		}
	}
}
Esempio n. 6
0
//
// Author: Levon Lloyd ([email protected])
// Author: Spencer Kimball ([email protected])

package storage

import (
	"reflect"
	"testing"

	"github.com/cockroachdb/cockroach/storage/engine"
)

var testConfig = ZoneConfig{
	Replicas: []engine.Attributes{
		engine.Attributes([]string{"a", "ssd"}),
		engine.Attributes([]string{"a", "hdd"}),
		engine.Attributes([]string{"b", "ssd"}),
		engine.Attributes([]string{"b", "hdd"}),
	},
	RangeMinBytes: 1 << 20,
	RangeMaxBytes: 64 << 20,
}

var yamlConfig = `
replicas:
  - [a, ssd]
  - [a, hdd]
  - [b, ssd]
  - [b, hdd]
range_min_bytes: 1048576
Esempio n. 7
0
	"github.com/cockroachdb/cockroach/gossip"
	"github.com/cockroachdb/cockroach/rpc"
	"github.com/cockroachdb/cockroach/storage/engine"
	"github.com/cockroachdb/cockroach/util/hlc"
)

var (
	testRangeDescriptor = RangeDescriptor{
		StartKey: engine.KeyMin,
		EndKey:   engine.KeyMax,
		Replicas: []Replica{
			{
				NodeID:  1,
				StoreID: 1,
				RangeID: 1,
				Attrs:   engine.Attributes([]string{"dc1", "mem"}),
			},
			{
				NodeID:  2,
				StoreID: 1,
				RangeID: 1,
				Attrs:   engine.Attributes([]string{"dc2", "mem"}),
			},
		},
	}
	testDefaultAcctConfig = AcctConfig{}
	testDefaultPermConfig = PermConfig{
		Read:  []string{"root"},
		Write: []string{"root"},
	}
	testDefaultZoneConfig = ZoneConfig{
Esempio n. 8
0
// for names of contributors.
//
// Author: Levon Lloyd ([email protected])

package storage

import (
	"math/rand"
	"testing"

	"github.com/cockroachdb/cockroach/storage/engine"
)

var simpleZoneConfig = ZoneConfig{
	Replicas: []engine.Attributes{
		engine.Attributes([]string{"a", "ssd"}),
	},
}

var multiDisksConfig = ZoneConfig{
	Replicas: []engine.Attributes{
		engine.Attributes([]string{"a", "ssd"}),
		engine.Attributes([]string{"a", "hdd"}),
		engine.Attributes([]string{"a", "mem"}),
	},
}

var multiDCConfig = ZoneConfig{
	Replicas: []engine.Attributes{
		engine.Attributes([]string{"a", "ssd"}),
		engine.Attributes([]string{"b", "ssd"}),