func RunSocketTestSuite(t *testing.T, protocolFactory thrift.TProtocolFactory,
	transportFactory thrift.TTransportFactory) {
	// server
	var err error
	addr = FindAvailableTCPServerPort()
	serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
	if err != nil {
		t.Fatal("Unable to create server socket", err)
	}
	processor := thrifttest.NewThriftTestProcessor(NewThriftTestHandler())
	server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	server.Listen()

	go server.Serve()

	// client
	var transport thrift.TTransport = thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
	transport = transportFactory.GetTransport(transport)
	var protocol thrift.TProtocol = protocolFactory.GetProtocol(transport)
	thriftTestClient := thrifttest.NewThriftTestClientProtocol(transport, protocol, protocol)
	err = transport.Open()
	if err != nil {
		t.Fatal("Unable to open client socket", err)
	}

	driver := NewThriftTestDriver(t, thriftTestClient)
	driver.Start()
}
Exemple #2
0
func TestInitOneway(t *testing.T) {
	var err error
	addr = findPort()
	serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
	if err != nil {
		t.Fatal("Unable to create server socket", err)
	}
	processor := onewaytest.NewOneWayProcessor(&impl{})
	server = thrift.NewTSimpleServer2(processor, serverTransport)

	go server.Serve()
}
func TestInitTwoServers(t *testing.T) {
	var err error
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTTransportFactory()
	transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	addr = FindAvailableTCPServerPort()
	serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
	if err != nil {
		t.Fatal("Unable to create server socket", err)
	}
	server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)

	firstProcessor := multiplexedprotocoltest.NewFirstProcessor(&FirstImpl{})
	processor.RegisterProcessor("FirstService", firstProcessor)

	secondProcessor := multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{})
	processor.RegisterProcessor("SecondService", secondProcessor)

	go server.Serve()
}