blob: 351fe5964a829ae749a07e9685fc0a4ac0720e1d [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
29func RunSocketTestSuite(t *testing.T, protocolFactory thrift.TProtocolFactory,
30 transportFactory thrift.TTransportFactory) {
31 // server
32 var err error
33 addr = FindAvailableTCPServerPort()
34 serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
35 if err != nil {
36 t.Fatal("Unable to create server socket", err)
37 }
38 processor := thrifttest.NewThriftTestProcessor(NewThriftTestHandler())
39 server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
40 server.Listen()
41
42 go server.Serve()
43
44 // client
lvqian81334cd2020-03-26 19:08:55 +080045 var transport thrift.TTransport = thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT, TIMEOUT)
D. Can Celasun8da0e722017-06-02 14:33:32 +020046 transport, err = transportFactory.GetTransport(transport)
47 if err != nil {
48 t.Fatal(err)
49 }
Jens Geyer5f9bdff2014-11-18 21:57:03 +010050 var protocol thrift.TProtocol = protocolFactory.GetProtocol(transport)
D. Can Celasun4f77ab82017-09-21 15:21:00 +020051 thriftTestClient := thrifttest.NewThriftTestClient(thrift.NewTStandardClient(protocol, protocol))
Jens Geyer5f9bdff2014-11-18 21:57:03 +010052 err = transport.Open()
53 if err != nil {
54 t.Fatal("Unable to open client socket", err)
55 }
56
57 driver := NewThriftTestDriver(t, thriftTestClient)
58 driver.Start()
59}
60
61// Run test suite using TJSONProtocol
62func TestTJSONProtocol(t *testing.T) {
63 RunSocketTestSuite(t,
64 thrift.NewTJSONProtocolFactory(),
65 thrift.NewTTransportFactory())
66 RunSocketTestSuite(t,
67 thrift.NewTJSONProtocolFactory(),
68 thrift.NewTBufferedTransportFactory(8912))
69 RunSocketTestSuite(t,
70 thrift.NewTJSONProtocolFactory(),
71 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
72}
73
74// Run test suite using TBinaryProtocol
75func TestTBinaryProtocol(t *testing.T) {
76 RunSocketTestSuite(t,
77 thrift.NewTBinaryProtocolFactoryDefault(),
78 thrift.NewTTransportFactory())
79 RunSocketTestSuite(t,
80 thrift.NewTBinaryProtocolFactoryDefault(),
81 thrift.NewTBufferedTransportFactory(8912))
82 RunSocketTestSuite(t,
83 thrift.NewTBinaryProtocolFactoryDefault(),
84 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
85}
86
87// Run test suite using TCompactBinaryProtocol
88func TestTCompactProtocol(t *testing.T) {
89 RunSocketTestSuite(t,
90 thrift.NewTCompactProtocolFactory(),
91 thrift.NewTTransportFactory())
92 RunSocketTestSuite(t,
93 thrift.NewTCompactProtocolFactory(),
94 thrift.NewTBufferedTransportFactory(8912))
95 RunSocketTestSuite(t,
96 thrift.NewTCompactProtocolFactory(),
97 thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
98}