Пример #1
0
// connect connects the client to the server at addr.
func (connection *Connection) connect(addr string) error {
	connection.Close()
	log.Infof("connecting to %v", addr)

	conn, err := rpc.Dial(addr, connection.Opts.DialOpts...)
	if err != nil {
		log.Errorf("connection failed: %v", err)
		return err
	}

	connection.conn, connection.Stub = conn, pb.NewCapacityClient(conn)
	connection.currentMaster = addr

	return nil
}
Пример #2
0
// setUpIntermediate sets up a test intermediate server.
func setUpIntermediate(name string, addr string) (fixture, error) {
	var (
		fix fixture
		err error
	)

	fix.server, err = MakeTestIntermediateServer(
		name, addr,
		&pb.ResourceTemplate{
			IdentifierGlob: proto.String("*"),
			Capacity:       proto.Float64(100),
			SafeCapacity:   proto.Float64(2),
			Algorithm: &pb.Algorithm{
				Kind:            pb.Algorithm_PROPORTIONAL_SHARE.Enum(),
				RefreshInterval: proto.Int64(1),
				LeaseLength:     proto.Int64(2),
			},
		})
	if err != nil {
		return fixture{}, err
	}

	lis, err := net.Listen("tcp", ":0")
	if err != nil {
		return fixture{}, err
	}

	fix.lis = lis

	fix.rpcServer = rpc.NewServer()

	pb.RegisterCapacityServer(fix.rpcServer, fix.server)

	go fix.rpcServer.Serve(lis)

	conn, err := rpc.Dial(fix.Addr(), rpc.WithInsecure())
	if err != nil {
		return fixture{}, err
	}

	fix.client = pb.NewCapacityClient(conn)
	return fix, nil
}