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()
}
Esempio n. 2
0
func RunClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory) os.Error {
	addr, err := net.ResolveTCPAddr("tcp", "localhost:9090")
	if err != nil {
		fmt.Print("Error resolving address: ", err.String(), "\n")
		return err
	}
	transport := thrift.NewTSocketAddr(addr)
	if err = transport.Open(); err != nil {
		fmt.Print("Error opening connection for protocol ", addr.Network(), " to ", addr.String(), ": ", err.String(), "\n")
		return err
	}
	useTransport := transportFactory.GetTransport(transport)
	client := tutorial.NewCalculatorClientFactory(useTransport, protocolFactory)
	Perform(client)
	return transport.Close()
}