作者:hefj
项目:groupcach
// tests that a Getter's Get method is only called once with two
// outstanding callers. This is the proto variant.
func TestGetDupSuppressProto(t *testing.T) {
once.Do(testSetup)
// Start two getters. The first should block (waiting reading
// from stringc) and the second should latch on to the first
// one.
resc := make(chan *testpb.TestMessage, 2)
for i := 0; i < 2; i++ {
go func() {
tm := new(testpb.TestMessage)
if err := protoGroup.Get(dummyCtx, fromChan, ProtoSink(tm)); err != nil {
tm.Name = proto.String("ERROR:" + err.Error())
}
resc <- tm
}()
}
// Wait a bit so both goroutines get merged together via
// singleflight.
// TODO(bradfitz): decide whether there are any non-offensive
// debug/test hooks that could be added to singleflight to
// make a sleep here unnecessary.
time.Sleep(250 * time.Millisecond)
// Unblock the first getter, which should unblock the second
// as well.
stringc <- "Fluffy"
want := &testpb.TestMessage{
Name: proto.String("ECHO:Fluffy"),
City: proto.String("SOME-CITY"),
}
for i := 0; i < 2; i++ {
select {
case v := <-resc:
if !reflect.DeepEqual(v, want) {
t.Errorf(" Got: %v\nWant: %v", proto.CompactTextString(v), proto.CompactTextString(want))
}
case <-time.After(5 * time.Second):
t.Errorf("timeout waiting on getter #%d of 2", i+1)
}
}
}
作者:yunab
项目:codela
func main() {
p := Person{
Name: proto.String("Taro Yamada"),
Age: proto.Int32(8),
}
pet := Pet{Name: proto.String("Mike")}
p.Pet = append(p.Pet, &pet)
fmt.Println("-- p.String() --")
fmt.Println(p.String())
fmt.Println("-- MarshalText --")
fmt.Print(PrintToString(&p)) // not compact
fmt.Println("-- Marshal --")
m, _ := proto.Marshal(&p)
fmt.Println(m)
fmt.Println("-- CompactTextString --")
fmt.Println(proto.CompactTextString(&p))
}
作者:dcjone
项目:dooze
func (this *request) String() string { return proto.CompactTextString(this) }
作者:LeXa489
项目:tes
func (m *URLFetchResponse) String() string { return proto.CompactTextString(m) }
作者:brg-liuwe
项目:dspHelloWorl
func (m *MgxBidRequest) String() string { return proto.CompactTextString(m) }
作者:hortonwork
项目:kubernetes-yar
func (m *RenewDelegationTokenRequestProto) String() string { return proto.CompactTextString(m) }
作者:nekto0
项目:gome
func (m *Attribute) String() string { return proto.CompactTextString(m) }
作者:hardik
项目:goze
func (m *Entry) String() string { return proto.CompactTextString(m) }
作者:botaydotco
项目:GoMessagingTestFrameWor
func (this *VoiceModeControl) String() string { return proto.CompactTextString(this) }
作者:pguelp
项目:go-rpcge
func (this *SumMessage) String() string { return proto.CompactTextString(this) }
作者:jbeshi
项目:unanimit
func (m *Forward) String() string { return proto.CompactTextString(m) }