Example #1
0
func (r *RPCRegistry) Connect() {
	// We want the connection operation to block and constantly reconnect using grpc backoff
	log.Info("Starting gRPC connection to fleet-engine...")
	ep_engines := []string{":fleet-engine:"}
	r.balancer = newSimpleBalancer(ep_engines)
	connection, err := grpc.Dial(ep_engines[0],
		grpc.WithTimeout(12*time.Second), grpc.WithInsecure(),
		grpc.WithDialer(r.dialer), grpc.WithBlock(), grpc.WithBalancer(r.balancer))
	if err != nil {
		log.Fatalf("Unable to dial to registry: %s", err)
	}
	r.registryConn = connection
	r.registryClient = pb.NewRegistryClient(r.registryConn)
	log.Info("Connected succesfully to fleet-engine via grpc!")
}
Example #2
0
func TestRPCRegistryClientCreation(t *testing.T) {
	lis, err := net.Listen("tcp", ":0")
	if err != nil {
		t.Fatalf("failed to listen: %v", err)
	}
	_, port, err := net.SplitHostPort(lis.Addr().String())
	if err != nil {
		t.Fatalf("failed to parse listener address: %v", err)
	}
	addr := "localhost:" + port
	b := newSimpleBalancer([]string{addr})
	conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second),
		grpc.WithBlock(), grpc.WithBalancer(b))
	if err != nil {
		t.Fatalf("failed to dial to the server %q: %v", addr, err)
	}
	// Close unaccepted connection (i.e., conn).
	lis.Close()

	registryClient := pb.NewRegistryClient(conn)
	if registryClient == nil {
		t.Fatalf("failed to create a new grpc registry to the server %q: %v", addr, err)
	}
}