本文整理匯總了Golang中github.com/hyperledger/fabric/events/producer.Send函數的典型用法代碼示例。如果您正苦於以下問題:Golang Send函數的具體用法?Golang Send怎麽用?Golang Send使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Send函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestReceiveAnyMessage
func TestReceiveAnyMessage(t *testing.T) {
var err error
adapter.count = 1
emsg := createTestBlock()
if err = producer.Send(emsg); err != nil {
t.Fail()
t.Logf("Error sending message %s", err)
}
emsg = createTestChaincodeEvent("0xffffffff", "event2")
if err = producer.Send(emsg); err != nil {
t.Fail()
t.Logf("Error sending message %s", err)
}
//receive 2 messages - a block and a chaincode event
for i := 0; i < 2; i++ {
select {
case <-adapter.notfy:
case <-time.After(5 * time.Second):
t.Fail()
t.Logf("timed out on messge")
}
}
}
示例2: TestUnregister
func TestUnregister(t *testing.T) {
var err error
obcEHClient.RegisterAsync([]*ehpb.Interest{&ehpb.Interest{EventType: ehpb.EventType_CHAINCODE, RegInfo: &ehpb.Interest_ChaincodeRegInfo{ChaincodeRegInfo: &ehpb.ChaincodeReg{ChaincodeID: "0xffffffff", EventName: "event10"}}}})
adapter.count = 1
select {
case <-adapter.notfy:
case <-time.After(2 * time.Second):
t.Fail()
t.Logf("timed out on messge")
}
emsg := createTestChaincodeEvent("0xffffffff", "event10")
if err = producer.Send(emsg); err != nil {
t.Fail()
t.Logf("Error sending message %s", err)
}
adapter.count = 1
select {
case <-adapter.notfy:
case <-time.After(2 * time.Second):
t.Fail()
t.Logf("timed out on messge")
}
obcEHClient.UnregisterAsync([]*ehpb.Interest{&ehpb.Interest{EventType: ehpb.EventType_CHAINCODE, RegInfo: &ehpb.Interest_ChaincodeRegInfo{ChaincodeRegInfo: &ehpb.ChaincodeReg{ChaincodeID: "0xffffffff", EventName: "event10"}}}})
adapter.count = 1
select {
case <-adapter.notfy:
case <-time.After(2 * time.Second):
t.Fail()
t.Logf("should have received unreg")
}
adapter.count = 1
emsg = createTestChaincodeEvent("0xffffffff", "event10")
if err = producer.Send(emsg); err != nil {
t.Fail()
t.Logf("Error sending message %s", err)
}
select {
case <-adapter.notfy:
t.Fail()
t.Logf("should NOT have received event1")
case <-time.After(5 * time.Second):
}
}
示例3: sendProducerBlockEvent
func sendProducerBlockEvent(block *protos.Block) {
// Remove payload from deploy transactions. This is done to make block
// events more lightweight as the payload for these types of transactions
// can be very large.
blockTransactions := block.GetTransactions()
for _, transaction := range blockTransactions {
if transaction.Type == protos.Transaction_CHAINCODE_DEPLOY {
deploymentSpec := &protos.ChaincodeDeploymentSpec{}
err := proto.Unmarshal(transaction.Payload, deploymentSpec)
if err != nil {
ledgerLogger.Errorf("Error unmarshalling deployment transaction for block event: %s", err)
continue
}
deploymentSpec.CodePackage = nil
deploymentSpecBytes, err := proto.Marshal(deploymentSpec)
if err != nil {
ledgerLogger.Errorf("Error marshalling deployment transaction for block event: %s", err)
continue
}
transaction.Payload = deploymentSpecBytes
}
}
producer.Send(producer.CreateBlockEvent(block))
}
示例4: BenchmarkMessages
func BenchmarkMessages(b *testing.B) {
numMessages := 10000
adapter.count = numMessages
var err error
//b.ResetTimer()
for i := 0; i < numMessages; i++ {
go func() {
//emsg := createTestBlock()
emsg := createTestChaincodeEvent("0xffffffff", "event1")
if err = producer.Send(emsg); err != nil {
b.Fail()
b.Logf("Error sending message %s", err)
}
}()
}
select {
case <-adapter.notfy:
case <-time.After(5 * time.Second):
b.Fail()
b.Logf("timed out on messge")
}
}
示例5: sendChaincodeEvents
//send chaincode events created by transactions in the block
func sendChaincodeEvents(block *protos.Block) {
nonHashData := block.GetNonHashData()
if nonHashData != nil {
trs := nonHashData.GetTransactionResults()
for _, tr := range trs {
if tr.ChaincodeEvent != nil {
producer.Send(producer.CreateChaincodeEvent(tr.ChaincodeEvent))
}
}
}
}
示例6: sendChaincodeEvents
//send chaincode events created by transactions
func sendChaincodeEvents(trs []*protos.TransactionResult) {
if trs != nil {
for _, tr := range trs {
//we store empty chaincode events in the protobuf repeated array to make protobuf happy.
//when we replay off a block ignore empty events
if tr.ChaincodeEvent != nil && tr.ChaincodeEvent.ChaincodeID != "" {
producer.Send(producer.CreateChaincodeEvent(tr.ChaincodeEvent))
}
}
}
}
示例7: TestFailReceive
func TestFailReceive(t *testing.T) {
var err error
adapter.count = 1
emsg := createTestChaincodeEvent("badcc", "event1")
if err = producer.Send(emsg); err != nil {
t.Fail()
t.Logf("Error sending message %s", err)
}
select {
case <-adapter.notfy:
t.Fail()
t.Logf("should NOT have received event1")
case <-time.After(2 * time.Second):
}
}
示例8: TestReceiveMessage
// Test the invocation of a transaction.
func TestReceiveMessage(t *testing.T) {
var err error
adapter.count = 1
emsg := createTestBlock()
if err = producer.Send(emsg); err != nil {
t.Fail()
t.Logf("Error sending message %s", err)
}
select {
case <-adapter.notfy:
case <-time.After(5 * time.Second):
t.Fail()
t.Logf("timed out on messge")
}
}
示例9: TestReceiveCCWildcard
func TestReceiveCCWildcard(t *testing.T) {
var err error
adapter.count = 1
obcEHClient.RegisterAsync([]*ehpb.Interest{&ehpb.Interest{EventType: ehpb.EventType_CHAINCODE, RegInfo: &ehpb.Interest_ChaincodeRegInfo{ChaincodeRegInfo: &ehpb.ChaincodeReg{ChaincodeID: "0xffffffff", EventName: ""}}}})
select {
case <-adapter.notfy:
case <-time.After(2 * time.Second):
t.Fail()
t.Logf("timed out on messge")
}
adapter.count = 1
emsg := createTestChaincodeEvent("0xffffffff", "wildcardevent")
if err = producer.Send(emsg); err != nil {
t.Fail()
t.Logf("Error sending message %s", err)
}
select {
case <-adapter.notfy:
case <-time.After(2 * time.Second):
t.Fail()
t.Logf("timed out on messge")
}
adapter.count = 1
obcEHClient.UnregisterAsync([]*ehpb.Interest{&ehpb.Interest{EventType: ehpb.EventType_CHAINCODE, RegInfo: &ehpb.Interest_ChaincodeRegInfo{ChaincodeRegInfo: &ehpb.ChaincodeReg{ChaincodeID: "0xffffffff", EventName: ""}}}})
select {
case <-adapter.notfy:
case <-time.After(2 * time.Second):
t.Fail()
t.Logf("timed out on messge")
}
}
示例10: sendTxRejectedEvent
func sendTxRejectedEvent(tx *pb.Transaction, errorMsg string) {
producer.Send(producer.CreateRejectionEvent(tx, errorMsg))
}