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.

47 lines
1017 B

  1. package broker
  2. import (
  3. "context"
  4. "fmt"
  5. "net"
  6. "testing"
  7. "time"
  8. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  9. "google.golang.org/grpc"
  10. "google.golang.org/grpc/test/bufconn"
  11. )
  12. var lis *bufconn.Listener
  13. func init() {
  14. lis = bufconn.Listen(1024 * 1024)
  15. server := grpc.NewServer()
  16. mq_pb.RegisterSeaweedMessagingServer(server, &MessageQueueBroker{})
  17. go func() {
  18. if err := server.Serve(lis); err != nil {
  19. fmt.Printf("Server exited with error: %v", err)
  20. }
  21. }()
  22. }
  23. func bufDialer(string, time.Duration) (net.Conn, error) {
  24. return lis.Dial()
  25. }
  26. func TestMessageQueueBroker_ListTopics(t *testing.T) {
  27. conn, err := grpc.DialContext(context.Background(), "bufnet", grpc.WithDialer(bufDialer), grpc.WithInsecure())
  28. if err != nil {
  29. t.Fatalf("Failed to dial bufnet: %v", err)
  30. }
  31. defer conn.Close()
  32. client := mq_pb.NewSeaweedMessagingClient(conn)
  33. request := &mq_pb.ListTopicsRequest{}
  34. _, err = client.ListTopics(context.Background(), request)
  35. if err == nil {
  36. t.Fatalf("Add failed: %v", err)
  37. }
  38. }