本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/config.SystemConfig.GetLargestObjectID方法的典型用法代码示例。如果您正苦于以下问题:Golang SystemConfig.GetLargestObjectID方法的具体用法?Golang SystemConfig.GetLargestObjectID怎么用?Golang SystemConfig.GetLargestObjectID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/config.SystemConfig
的用法示例。
在下文中一共展示了SystemConfig.GetLargestObjectID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestGetLargestID
func TestGetLargestID(t *testing.T) {
defer leaktest.AfterTest(t)()
testCases := []struct {
values []roachpb.KeyValue
largest uint32
maxID uint32
errStr string
}{
// No data.
{nil, 0, 0, "descriptor table not found"},
// Some data, but not from the system span.
{[]roachpb.KeyValue{plainKV("a", "b")}, 0, 0, "descriptor table not found"},
// Some real data, but no descriptors.
{[]roachpb.KeyValue{
sqlKV(keys.NamespaceTableID, 1, 1),
sqlKV(keys.NamespaceTableID, 1, 2),
sqlKV(keys.UsersTableID, 1, 3),
}, 0, 0, "descriptor table not found"},
// Single correct descriptor entry.
{[]roachpb.KeyValue{sqlKV(keys.DescriptorTableID, 1, 1)}, 1, 0, ""},
// Surrounded by other data.
{[]roachpb.KeyValue{
sqlKV(keys.NamespaceTableID, 1, 20),
sqlKV(keys.NamespaceTableID, 1, 30),
sqlKV(keys.DescriptorTableID, 1, 8),
sqlKV(keys.ZonesTableID, 1, 40),
}, 8, 0, ""},
// Descriptors with holes. Index ID does not matter.
{[]roachpb.KeyValue{
sqlKV(keys.DescriptorTableID, 1, 1),
sqlKV(keys.DescriptorTableID, 2, 5),
sqlKV(keys.DescriptorTableID, 3, 8),
sqlKV(keys.DescriptorTableID, 4, 12),
}, 12, 0, ""},
// Real SQL layout.
{sqlbase.MakeMetadataSchema().GetInitialValues(), keys.MaxSystemConfigDescID + 4, 0, ""},
// Test non-zero max.
{[]roachpb.KeyValue{
sqlKV(keys.DescriptorTableID, 1, 1),
sqlKV(keys.DescriptorTableID, 2, 5),
sqlKV(keys.DescriptorTableID, 3, 8),
sqlKV(keys.DescriptorTableID, 4, 12),
}, 8, 8, ""},
// Test non-zero max.
{[]roachpb.KeyValue{
sqlKV(keys.DescriptorTableID, 1, 1),
sqlKV(keys.DescriptorTableID, 2, 5),
sqlKV(keys.DescriptorTableID, 3, 8),
sqlKV(keys.DescriptorTableID, 4, 12),
}, 5, 7, ""},
}
cfg := config.SystemConfig{}
for tcNum, tc := range testCases {
cfg.Values = tc.values
ret, err := cfg.GetLargestObjectID(tc.maxID)
if !testutils.IsError(err, tc.errStr) {
t.Errorf("#%d: expected err=%q, got %v", tcNum, tc.errStr, err)
continue
}
if err != nil {
continue
}
if ret != tc.largest {
t.Errorf("#%d: expected largest=%d, got %d", tcNum, tc.largest, ret)
}
}
}