當前位置: 首頁>>代碼示例>>Golang>>正文


Golang proto.MakeKey函數代碼示例

本文整理匯總了Golang中github.com/cockroachdb/cockroach/proto.MakeKey函數的典型用法代碼示例。如果您正苦於以下問題:Golang MakeKey函數的具體用法?Golang MakeKey怎麽用?Golang MakeKey使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MakeKey函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestMetaScanBounds

func TestMetaScanBounds(t *testing.T) {
	defer leaktest.AfterTest(t)

	testCases := []struct {
		key, expStart, expEnd proto.Key
	}{
		{
			key:      proto.Key{},
			expStart: Meta1Prefix,
			expEnd:   Meta1Prefix.PrefixEnd(),
		},
		{
			key:      proto.Key("foo"),
			expStart: proto.Key("foo").Next(),
			expEnd:   proto.Key("foo")[:len(Meta1Prefix)].PrefixEnd(),
		},
		{
			key:      proto.MakeKey(Meta1Prefix, proto.KeyMax),
			expStart: proto.MakeKey(Meta1Prefix, proto.KeyMax),
			expEnd:   Meta1Prefix.PrefixEnd(),
		},
	}
	for i, test := range testCases {
		resStart, resEnd := MetaScanBounds(test.key)
		if !resStart.Equal(test.expStart) || !resEnd.Equal(test.expEnd) {
			t.Errorf("%d: range bounds %q-%q don't match expected bounds %q-%q for key %q", i, resStart, resEnd, test.expStart, test.expEnd, test.key)
		}
	}
}
開發者ID:Hellblazer,項目名稱:cockroach,代碼行數:29,代碼來源:keys_test.go

示例2: TestMetaReverseScanBounds

func TestMetaReverseScanBounds(t *testing.T) {
	defer leaktest.AfterTest(t)

	testCases := []struct {
		key, expStart, expEnd proto.Key
		err                   error
	}{
		{
			key:      proto.Key{},
			expStart: nil,
			expEnd:   nil,
			err:      NewInvalidRangeMetaKeyError("KeyMin or Meta1Prefix can't be used as the key of reverse scan", proto.Key{}),
		},
		{
			key:      Meta1Prefix,
			expStart: nil,
			expEnd:   nil,
			err:      NewInvalidRangeMetaKeyError("KeyMin or Meta1Prefix can't be used as the key of reverse scan", Meta1Prefix),
		},
		{
			key:      proto.MakeKey(Meta2Prefix, proto.Key("foo")),
			expStart: Meta2Prefix,
			expEnd:   proto.MakeKey(Meta2Prefix, proto.Key("foo\x00")),
			err:      nil,
		},
		{
			key:      proto.MakeKey(Meta1Prefix, proto.Key("foo")),
			expStart: Meta1Prefix,
			expEnd:   proto.MakeKey(Meta1Prefix, proto.Key("foo\x00")),
			err:      nil,
		},
		{
			key:      Meta2Prefix,
			expStart: Meta1Prefix,
			expEnd:   Meta2Prefix.Next(),
			err:      nil,
		},
	}
	for i, test := range testCases {
		resStart, resEnd, _ := MetaReverseScanBounds(test.key)
		if !resStart.Equal(test.expStart) || !resEnd.Equal(test.expEnd) {
			t.Errorf("%d: range bounds %q-%q don't match expected bounds %q-%q for key %q", i, resStart, resEnd, test.expStart, test.expEnd, test.key)
		}
	}
}
開發者ID:elkingtoncode,項目名稱:LampDB,代碼行數:45,代碼來源:keys_test.go

示例3: TestBootstrapCluster

// TestBootstrapCluster verifies the results of bootstrapping a
// cluster. Uses an in memory engine.
func TestBootstrapCluster(t *testing.T) {
	defer leaktest.AfterTest(t)
	stopper := stop.NewStopper()
	e := engine.NewInMem(proto.Attributes{}, 1<<20)
	localDB, err := BootstrapCluster("cluster-1", []engine.Engine{e}, stopper)
	if err != nil {
		t.Fatal(err)
	}
	defer stopper.Stop()

	// Scan the complete contents of the local database.
	rows, err := localDB.Scan(keys.LocalPrefix.PrefixEnd(), proto.KeyMax, 0)
	if err != nil {
		t.Fatal(err)
	}
	var keys []proto.Key
	for _, kv := range rows {
		keys = append(keys, kv.Key)
	}
	// TODO(marc): this depends on the sql system objects.
	var expectedKeys = []proto.Key{
		proto.MakeKey(proto.Key("\x00\x00meta1"), proto.KeyMax),
		proto.MakeKey(proto.Key("\x00\x00meta2"), proto.KeyMax),
		proto.Key("\x00desc-idgen"),
		proto.Key("\x00node-idgen"),
		proto.Key("\x00range-tree-root"),
		proto.Key("\x00store-idgen"),
		proto.Key("\x00zone"),
		proto.Key("\xff\n\x02\n\x01\tsystem\x00\x01\n\x03"),
		proto.Key("\xff\n\x02\n\x01\n\x01descriptor\x00\x01\n\x03"),
		proto.Key("\xff\n\x02\n\x01\n\x01namespace\x00\x01\n\x03"),
		proto.Key("\xff\n\x02\n\x01\n\x01users\x00\x01\n\x03"),
		proto.Key("\xff\n\x03\n\x01\n\x01\n\x02"),
		proto.Key("\xff\n\x03\n\x01\n\x02\n\x02"),
		proto.Key("\xff\n\x03\n\x01\n\x03\n\x02"),
		proto.Key("\xff\n\x03\n\x01\n\x04\n\x02"),
	}
	if !reflect.DeepEqual(keys, expectedKeys) {
		t.Errorf("expected keys mismatch:\n%s\n  -- vs. -- \n\n%s",
			formatKeys(keys), formatKeys(expectedKeys))
	}

	// TODO(spencer): check values.
}
開發者ID:kangxinrong,項目名稱:cockroach,代碼行數:46,代碼來源:node_test.go

示例4: TestBootstrapCluster

// TestBootstrapCluster verifies the results of bootstrapping a
// cluster. Uses an in memory engine.
func TestBootstrapCluster(t *testing.T) {
	defer leaktest.AfterTest(t)
	stopper := stop.NewStopper()
	e := engine.NewInMem(proto.Attributes{}, 1<<20)
	localDB, err := BootstrapCluster("cluster-1", []engine.Engine{e}, stopper)
	if err != nil {
		t.Fatal(err)
	}
	defer stopper.Stop()

	// Scan the complete contents of the local database.
	rows, err := localDB.Scan(keys.LocalPrefix.PrefixEnd(), proto.KeyMax, 0)
	if err != nil {
		t.Fatal(err)
	}
	var foundKeys proto.KeySlice
	for _, kv := range rows {
		foundKeys = append(foundKeys, kv.Key)
	}
	var expectedKeys = proto.KeySlice{
		proto.MakeKey(proto.Key("\x00\x00meta1"), proto.KeyMax),
		proto.MakeKey(proto.Key("\x00\x00meta2"), proto.KeyMax),
		proto.Key("\x00node-idgen"),
		proto.Key("\x00range-tree-root"),
		proto.Key("\x00store-idgen"),
		proto.Key("\x00zone"),
	}
	// Add the initial keys for sql.
	for _, kv := range sql.GetInitialSystemValues() {
		expectedKeys = append(expectedKeys, kv.Key)
	}
	// Resort the list. The sql values are not sorted.
	sort.Sort(expectedKeys)

	if !reflect.DeepEqual(foundKeys, expectedKeys) {
		t.Errorf("expected keys mismatch:\n%s\n  -- vs. -- \n\n%s",
			formatKeys(foundKeys), formatKeys(expectedKeys))
	}

	// TODO(spencer): check values.
}
開發者ID:husttom,項目名稱:cockroach,代碼行數:43,代碼來源:node_test.go

示例5: TestValidateRangeMetaKey

func TestValidateRangeMetaKey(t *testing.T) {
	defer leaktest.AfterTest(t)
	testCases := []struct {
		key    proto.Key
		expErr bool
	}{
		{proto.KeyMin, false},
		{proto.Key("\x00"), true},
		{Meta1Prefix[:len(Meta1Prefix)-1], true},
		{Meta1Prefix, false},
		{proto.MakeKey(Meta1Prefix, proto.KeyMax), false},
		{proto.MakeKey(Meta2Prefix, proto.KeyMax), true},
		{proto.MakeKey(Meta2Prefix, proto.KeyMax.Next()), true},
	}
	for i, test := range testCases {
		err := ValidateRangeMetaKey(test.key)
		if err != nil != test.expErr {
			t.Errorf("%d: expected error? %t: %s", i, test.expErr, err)
		}
	}
}
開發者ID:Hellblazer,項目名稱:cockroach,代碼行數:21,代碼來源:keys_test.go

示例6: MakeKey

// MakeKey makes a new key which is the concatenation of the
// given inputs, in order.
func MakeKey(keys ...proto.Key) proto.Key {
	return proto.MakeKey(keys...)
}
開發者ID:mberhault,項目名稱:cockroach,代碼行數:5,代碼來源:keys.go

示例7: MakeDataKey

//
// The resolution refers to the sample duration at which data is stored.
// Cockroach supports a fixed set of named resolutions, which are stored in the
// Resolution enumeration. This value is encoded as a VarInt in the key.
//
// Cockroach divides all data for a series into contiguous "time slots" of
// uniform length based on the "key duration" of the Resolution. For each
// series/source pair, there will be one key per slot. Slot 0 begins at unix
// epoch; the slot for a specific timestamp is found by truncating the
// timestamp to an exact multiple of the key duration, and then dividing it by
// the key duration:
//
// 		slot := (timestamp / keyDuration) // integer division
var (
	// keyDataPrefix is the key prefix for time series data keys.
	keyDataPrefix = proto.MakeKey(keys.SystemPrefix, proto.Key("tsd"))
)

// MakeDataKey creates a time series data key for the given series name, source,
// Resolution and timestamp. The timestamp is expressed in nanoseconds since the
// epoch; it will be truncated to an exact multiple of the supplied
// Resolution's KeyDuration.
func MakeDataKey(name string, source string, r Resolution, timestamp int64) proto.Key {
	// Normalize timestamp into a timeslot before recording.
	timeslot := timestamp / r.KeyDuration()

	k := append(proto.Key(nil), keyDataPrefix...)
	k = encoding.EncodeBytes(k, []byte(name))
	k = encoding.EncodeVarint(k, int64(r))
	k = encoding.EncodeVarint(k, timeslot)
	k = append(k, source...)
開發者ID:mberhault,項目名稱:cockroach,代碼行數:31,代碼來源:keys.go

示例8: TestMetaReverseScanBounds

func TestMetaReverseScanBounds(t *testing.T) {
	defer leaktest.AfterTest(t)

	testCases := []struct {
		key, expStart, expEnd proto.Key
		expError              string
	}{
		{
			key:      proto.Key{},
			expStart: nil,
			expEnd:   nil,
			expError: "KeyMin and Meta1Prefix can't be used as the key of reverse scan",
		},
		{
			key:      Meta1Prefix,
			expStart: nil,
			expEnd:   nil,
			expError: "KeyMin and Meta1Prefix can't be used as the key of reverse scan",
		},
		{
			key:      Meta2KeyMax.Next(),
			expStart: nil,
			expEnd:   nil,
			expError: "body of meta key range lookup is",
		},
		{
			key:      Meta1KeyMax.Next(),
			expStart: nil,
			expEnd:   nil,
			expError: "body of meta key range lookup is",
		},
		{
			key:      proto.MakeKey(Meta2Prefix, proto.Key("foo")),
			expStart: Meta2Prefix,
			expEnd:   proto.MakeKey(Meta2Prefix, proto.Key("foo\x00")),
			expError: "",
		},
		{
			key:      proto.MakeKey(Meta1Prefix, proto.Key("foo")),
			expStart: Meta1Prefix,
			expEnd:   proto.MakeKey(Meta1Prefix, proto.Key("foo\x00")),
			expError: "",
		},
		{
			key:      Meta2Prefix,
			expStart: Meta1Prefix,
			expEnd:   Meta2Prefix.Next(),
			expError: "",
		},
		{
			key:      Meta2KeyMax,
			expStart: Meta2Prefix,
			expEnd:   Meta2KeyMax.Next(),
			expError: "",
		},
	}
	for i, test := range testCases {
		resStart, resEnd, err := MetaReverseScanBounds(test.key)

		if err != nil && !testutils.IsError(err, test.expError) {
			t.Errorf("expected error: %s ; got %s", test.expError, err)
		} else if err == nil && test.expError != "" {
			t.Errorf("expected error: %s", test.expError)
		}

		if !resStart.Equal(test.expStart) || !resEnd.Equal(test.expEnd) {
			t.Errorf("%d: range bounds %q-%q don't match expected bounds %q-%q for key %q", i, resStart, resEnd, test.expStart, test.expEnd, test.key)
		}
	}
}
開發者ID:harryyeh,項目名稱:cockroach,代碼行數:70,代碼來源:keys_test.go


注:本文中的github.com/cockroachdb/cockroach/proto.MakeKey函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。