本文整理匯總了Golang中github.com/cockroachdb/cockroach/proto.Method函數的典型用法代碼示例。如果您正苦於以下問題:Golang Method函數的具體用法?Golang Method怎麽用?Golang Method使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Method函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateCountString
// updateCountString describes the update counts that were recorded by
// storeEventReader. The formatting is appropriate to paste into this test if
// as a new expected value.
func (ser *storeEventReader) updateCountString() string {
var buffer bytes.Buffer
w := tabwriter.NewWriter(&buffer, 2, 1, 2, ' ', 0)
var storeIDs sort.IntSlice
for storeID := range ser.perStoreUpdateCount {
storeIDs = append(storeIDs, int(storeID))
}
sort.Sort(storeIDs)
for _, storeID := range storeIDs {
if countset, ok := ser.perStoreUpdateCount[proto.StoreID(storeID)]; ok {
fmt.Fprintf(w, "proto.StoreID(%d): {\n", storeID)
var methodIDs sort.IntSlice
for methodID := range countset {
methodIDs = append(methodIDs, int(methodID))
}
sort.Sort(methodIDs)
for _, methodID := range methodIDs {
method := proto.Method(methodID)
if count, okCount := countset[method]; okCount {
fmt.Fprintf(w, "\tproto.%s:\t%d,\n", method, count)
} else {
panic("unreachable!")
}
}
} else {
panic("unreachable!")
}
fmt.Fprintf(w, "},\n")
}
return buffer.String()
}
示例2: usesTimestampCache
// usesTimestampCache returns true if the request affects or is
// affected by the timestamp cache.
func usesTimestampCache(r proto.Request) bool {
m := r.Method()
if m < 0 || m >= proto.Method(len(tsCacheMethods)) {
return false
}
return tsCacheMethods[m]
}
示例3: RegisterRPC
// RegisterRPC registers the RPC endpoints.
func (s *DBServer) RegisterRPC(rpcServer *rpc.Server) error {
for i, reqType := range allExternalMethods {
if reqType == nil {
continue
}
method := proto.Method(i)
if err := rpcServer.Register(fmt.Sprintf("Server.%s", method), s.executeCmd, reqType); err != nil {
return err
}
}
return nil
}
示例4: Unmarshal
//.........這裏部分代碼省略.........
}
var v github_com_cockroachdb_cockroach_proto.StoreID
for shift := uint(0); ; shift += 7 {
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
v |= (github_com_cockroachdb_cockroach_proto.StoreID(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
m.StoreID = &v
case 10:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field RangeID", wireType)
}
var v github_com_cockroachdb_cockroach_proto.RangeID
for shift := uint(0); ; shift += 7 {
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
v |= (github_com_cockroachdb_cockroach_proto.RangeID(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
m.RangeID = &v
case 11:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Method", wireType)
}
var v github_com_cockroachdb_cockroach_proto.Method
for shift := uint(0); ; shift += 7 {
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
v |= (github_com_cockroachdb_cockroach_proto.Method(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
m.Method = &v
case 12:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := data[iNdEx]
iNdEx++
byteLen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
postIndex := iNdEx + byteLen
if postIndex > l {
示例5: TestMultiStoreEventFeed
//.........這裏部分代碼省略.........
// AdminSplit an empty range at the end of the second range.
if err := mtc.db.AdminSplit("z"); err != nil {
t.Fatalf("error splitting second range: %s", err)
}
// AdminMerge the empty range back into the second range.
if err := mtc.db.AdminMerge("c"); err != nil {
t.Fatalf("error merging final range: %s", err)
}
// Add an additional put through the system and wait for all
// replicas to receive it.
if _, err := mtc.db.Inc("aa", 5); err != nil {
t.Fatalf("error putting data to db: %s", err)
}
util.SucceedsWithin(t, time.Second, func() error {
for _, eng := range mtc.engines {
val, _, err := engine.MVCCGet(eng, proto.Key("aa"), mtc.clock.Now(), true, nil)
if err != nil {
return err
}
if a, e := mustGetInteger(val), int64(5); a != e {
return util.Errorf("expected aa = %d, got %d", e, a)
}
}
return nil
})
// Close feed and wait for reader to receive all events.
feed.Close()
readStopper.Stop()
// Compare events to expected values.
expected := map[proto.StoreID][]string{
proto.StoreID(1): {
"StartStore",
"BeginScanRanges",
"RegisterRange scan=true, rid=1, live=.*",
"EndScanRanges",
"SplitRange origId=1, newId=2, origKey=316, newKey=15",
"SplitRange origId=2, newId=3, origKey=15, newKey=0",
"MergeRange rid=2, subId=3, key=15, subKey=0",
},
proto.StoreID(2): {
"StartStore",
"BeginScanRanges",
"EndScanRanges",
"RegisterRange scan=false, rid=1, live=.*",
"SplitRange origId=1, newId=2, origKey=316, newKey=15",
"SplitRange origId=2, newId=3, origKey=15, newKey=0",
"MergeRange rid=2, subId=3, key=15, subKey=0",
},
proto.StoreID(3): {
"StartStore",
"BeginScanRanges",
"EndScanRanges",
"RegisterRange scan=false, rid=1, live=.*",
"SplitRange origId=1, newId=2, origKey=316, newKey=15",
"SplitRange origId=2, newId=3, origKey=15, newKey=0",
"MergeRange rid=2, subId=3, key=15, subKey=0",
},
}
if a, e := ser.perStoreFeeds, expected; !checkMatch(e, a) {
t.Errorf("event feed did not match expected value. Actual values have been printed to compare with above expectation.\n")
t.Logf("Event feed information:\n%s", ser.eventFeedString())
}
// Expected count of update events on a per-method basis.
expectedUpdateCount := map[proto.StoreID]map[proto.Method]int{
proto.StoreID(1): {
proto.Method(22): 3, //InternalLeaderLease
proto.Method(2): 7, //ConditionalPut
proto.Method(1): 18, //Put
proto.Method(7): 6, //EndTransaction
proto.Method(3): 2, //Increment
proto.Method(4): 2, //Delete
},
proto.StoreID(2): {
proto.Method(22): 2, //InternalLeaderLease
proto.Method(4): 2, //Delete
proto.Method(2): 6, //ConditionalPut
proto.Method(1): 16, //Put
proto.Method(7): 5, //EndTransaction
proto.Method(3): 2, //Increment
},
proto.StoreID(3): {
proto.Method(1): 14, //Put
proto.Method(7): 4, //EndTransaction
proto.Method(3): 2, //Increment
proto.Method(2): 5, //ConditionalPut
proto.Method(22): 2, //InternalLeaderLease
proto.Method(4): 2, //Delete
},
}
if a, e := ser.perStoreUpdateCount, expectedUpdateCount; !reflect.DeepEqual(a, e) {
t.Errorf("update counts did not match expected value. Actual values have been printed to compare with above expectation.\n")
t.Logf("Update count information:\n%s", ser.updateCountString())
}
}