blob: 422b5c889c6932ef7d76742df18f937c94c6fd76 [file] [log] [blame]
Jens Geyer5f9bdff2014-11-18 21:57:03 +01001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package tests
21
22import (
23 "testing"
24 "thrift"
25 "thrifttest"
26)
27
28func RunSocketTestSuite(t *testing.T, protocolFactory thrift.TProtocolFactory,
29 transportFactory thrift.TTransportFactory) {
30 // server
31 var err error
32 addr = FindAvailableTCPServerPort()
33 serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
34 if err != nil {
35 t.Fatal("Unable to create server socket", err)
36 }
37 processor := thrifttest.NewThriftTestProcessor(NewThriftTestHandler())
38 server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
39 server.Listen()
40
41 go server.Serve()
42
43 // client
44 var transport thrift.TTransport = thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
45 transport = transportFactory.GetTransport(transport)
46 var protocol thrift.TProtocol = protocolFactory.GetProtocol(transport)
47 thriftTestClient := thrifttest.NewThriftTestClientProtocol(transport, protocol, protocol)
48 err = transport.Open()
49 if err != nil {
50 t.Fatal("Unable to open client socket", err)
51 }
52
53 driver := NewThriftTestDriver(t, thriftTestClient)
54 driver.Start()
55}
56
57// Run test suite using TJSONProtocol
58func TestTJSONProtocol(t *testing.T) {
59 RunSocketTestSuite(t,
60 thrift.NewTJSONProtocolFactory(),
61 thrift.NewTTransportFactory())
62 RunSocketTestSuite(t,
63 thrift.NewTJSONProtocolFactory(),
64 thrift.NewTBufferedTransportFactory(8912))
65 RunSocketTestSuite(t,
66 thrift.NewTJSONProtocolFactory(),
67 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
68}
69
70// Run test suite using TBinaryProtocol
71func TestTBinaryProtocol(t *testing.T) {
72 RunSocketTestSuite(t,
73 thrift.NewTBinaryProtocolFactoryDefault(),
74 thrift.NewTTransportFactory())
75 RunSocketTestSuite(t,
76 thrift.NewTBinaryProtocolFactoryDefault(),
77 thrift.NewTBufferedTransportFactory(8912))
78 RunSocketTestSuite(t,
79 thrift.NewTBinaryProtocolFactoryDefault(),
80 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
81}
82
83// Run test suite using TCompactBinaryProtocol
84func TestTCompactProtocol(t *testing.T) {
85 RunSocketTestSuite(t,
86 thrift.NewTCompactProtocolFactory(),
87 thrift.NewTTransportFactory())
88 RunSocketTestSuite(t,
89 thrift.NewTCompactProtocolFactory(),
90 thrift.NewTBufferedTransportFactory(8912))
91 RunSocketTestSuite(t,
92 thrift.NewTCompactProtocolFactory(),
93 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
94}