blob: cffd9c3f7e98526ead6574a02dd4fa3d874a310e [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)
D. Can Celasun8da0e722017-06-02 14:33:32 +020045 transport, err = transportFactory.GetTransport(transport)
46 if err != nil {
47 t.Fatal(err)
48 }
Jens Geyer5f9bdff2014-11-18 21:57:03 +010049 var protocol thrift.TProtocol = protocolFactory.GetProtocol(transport)
D. Can Celasun4f77ab82017-09-21 15:21:00 +020050 thriftTestClient := thrifttest.NewThriftTestClient(thrift.NewTStandardClient(protocol, protocol))
Jens Geyer5f9bdff2014-11-18 21:57:03 +010051 err = transport.Open()
52 if err != nil {
53 t.Fatal("Unable to open client socket", err)
54 }
55
56 driver := NewThriftTestDriver(t, thriftTestClient)
57 driver.Start()
58}
59
60// Run test suite using TJSONProtocol
61func TestTJSONProtocol(t *testing.T) {
62 RunSocketTestSuite(t,
63 thrift.NewTJSONProtocolFactory(),
64 thrift.NewTTransportFactory())
65 RunSocketTestSuite(t,
66 thrift.NewTJSONProtocolFactory(),
67 thrift.NewTBufferedTransportFactory(8912))
68 RunSocketTestSuite(t,
69 thrift.NewTJSONProtocolFactory(),
70 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
71}
72
73// Run test suite using TBinaryProtocol
74func TestTBinaryProtocol(t *testing.T) {
75 RunSocketTestSuite(t,
76 thrift.NewTBinaryProtocolFactoryDefault(),
77 thrift.NewTTransportFactory())
78 RunSocketTestSuite(t,
79 thrift.NewTBinaryProtocolFactoryDefault(),
80 thrift.NewTBufferedTransportFactory(8912))
81 RunSocketTestSuite(t,
82 thrift.NewTBinaryProtocolFactoryDefault(),
83 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
84}
85
86// Run test suite using TCompactBinaryProtocol
87func TestTCompactProtocol(t *testing.T) {
88 RunSocketTestSuite(t,
89 thrift.NewTCompactProtocolFactory(),
90 thrift.NewTTransportFactory())
91 RunSocketTestSuite(t,
92 thrift.NewTCompactProtocolFactory(),
93 thrift.NewTBufferedTransportFactory(8912))
94 RunSocketTestSuite(t,
95 thrift.NewTCompactProtocolFactory(),
96 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
97}