blob: d4b53f27786df78cedd2b50857f6fe3e5f6ae9ac [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"
Yuxuan 'fishy' Wangb71f11e2021-03-22 15:01:00 -070024
25 "github.com/apache/thrift/lib/go/test/gopath/src/thrifttest"
26 "github.com/apache/thrift/lib/go/thrift"
Jens Geyer5f9bdff2014-11-18 21:57:03 +010027)
28
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -070029func RunSocketTestSuite(
30 t *testing.T,
31 protocolFactory thrift.TProtocolFactory,
32 transportFactory thrift.TTransportFactory,
33) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010034 // server
35 var err error
36 addr = FindAvailableTCPServerPort()
37 serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
38 if err != nil {
39 t.Fatal("Unable to create server socket", err)
40 }
41 processor := thrifttest.NewThriftTestProcessor(NewThriftTestHandler())
42 server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
43 server.Listen()
44
45 go server.Serve()
46
47 // client
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -070048 cfg := &thrift.TConfiguration{
49 ConnectTimeout: TIMEOUT,
50 SocketTimeout: TIMEOUT,
51 }
52 thrift.PropagateTConfiguration(transportFactory, cfg)
53 var transport thrift.TTransport = thrift.NewTSocketFromAddrConf(addr, cfg)
D. Can Celasun8da0e722017-06-02 14:33:32 +020054 transport, err = transportFactory.GetTransport(transport)
55 if err != nil {
56 t.Fatal(err)
57 }
Jens Geyer5f9bdff2014-11-18 21:57:03 +010058 var protocol thrift.TProtocol = protocolFactory.GetProtocol(transport)
D. Can Celasun4f77ab82017-09-21 15:21:00 +020059 thriftTestClient := thrifttest.NewThriftTestClient(thrift.NewTStandardClient(protocol, protocol))
Jens Geyer5f9bdff2014-11-18 21:57:03 +010060 err = transport.Open()
61 if err != nil {
62 t.Fatal("Unable to open client socket", err)
63 }
64
65 driver := NewThriftTestDriver(t, thriftTestClient)
66 driver.Start()
67}
68
69// Run test suite using TJSONProtocol
70func TestTJSONProtocol(t *testing.T) {
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -070071 RunSocketTestSuite(
72 t,
Jens Geyer5f9bdff2014-11-18 21:57:03 +010073 thrift.NewTJSONProtocolFactory(),
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -070074 thrift.NewTTransportFactory(),
75 )
76 RunSocketTestSuite(
77 t,
Jens Geyer5f9bdff2014-11-18 21:57:03 +010078 thrift.NewTJSONProtocolFactory(),
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -070079 thrift.NewTBufferedTransportFactory(8912),
80 )
81 RunSocketTestSuite(
82 t,
Jens Geyer5f9bdff2014-11-18 21:57:03 +010083 thrift.NewTJSONProtocolFactory(),
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -070084 thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), nil),
85 )
Jens Geyer5f9bdff2014-11-18 21:57:03 +010086}
87
88// Run test suite using TBinaryProtocol
89func TestTBinaryProtocol(t *testing.T) {
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -070090 RunSocketTestSuite(
91 t,
92 thrift.NewTBinaryProtocolFactoryConf(nil),
93 thrift.NewTTransportFactory(),
94 )
95 RunSocketTestSuite(
96 t,
97 thrift.NewTBinaryProtocolFactoryConf(nil),
98 thrift.NewTBufferedTransportFactory(8912),
99 )
100 RunSocketTestSuite(
101 t,
102 thrift.NewTBinaryProtocolFactoryConf(nil),
103 thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), nil),
104 )
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100105}
106
107// Run test suite using TCompactBinaryProtocol
108func TestTCompactProtocol(t *testing.T) {
Yuxuan 'fishy' Wang17373a32021-08-26 11:04:27 -0700109 RunSocketTestSuite(
110 t,
111 thrift.NewTCompactProtocolFactoryConf(nil),
112 thrift.NewTTransportFactory(),
113 )
114 RunSocketTestSuite(
115 t,
116 thrift.NewTCompactProtocolFactoryConf(nil),
117 thrift.NewTBufferedTransportFactory(8912),
118 )
119 RunSocketTestSuite(
120 t,
121 thrift.NewTCompactProtocolFactoryConf(nil),
122 thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), nil),
123 )
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100124}