You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kratos/examples/event/memory/memory_test.go

34 lines
625 B

package memory
import (
"context"
"fmt"
"github.com/go-kratos/kratos/examples/event/event"
"testing"
"time"
)
func TestSendAndReceive(t *testing.T) {
send, receive := NewMemory("test")
err := receive.Receive(context.Background(), func(ctx context.Context, event event.Event) error {
t.Log(fmt.Sprintf("key:%s, value:%s\n", event.Key(), event.Value()))
return nil
})
if err != nil {
t.Error(err)
}
for i := 0; i < 5; i++ {
err := send.Send(context.Background(), &Message{
key: "kratos",
value: []byte("hello world"),
})
if err != nil {
t.Error(err)
}
}
time.Sleep(5 * time.Second)
}