Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | package tests |
| 21 | |
| 22 | import ( |
| 23 | "testing" |
Yuxuan 'fishy' Wang | b71f11e | 2021-03-22 15:01:00 -0700 | [diff] [blame] | 24 | |
| 25 | "github.com/apache/thrift/lib/go/test/gopath/src/thrifttest" |
| 26 | "github.com/apache/thrift/lib/go/thrift" |
Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 27 | ) |
| 28 | |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame^] | 29 | func RunSocketTestSuite( |
| 30 | t *testing.T, |
| 31 | protocolFactory thrift.TProtocolFactory, |
| 32 | transportFactory thrift.TTransportFactory, |
| 33 | ) { |
Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 34 | // 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' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame^] | 48 | 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 Celasun | 8da0e72 | 2017-06-02 14:33:32 +0200 | [diff] [blame] | 54 | transport, err = transportFactory.GetTransport(transport) |
| 55 | if err != nil { |
| 56 | t.Fatal(err) |
| 57 | } |
Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 58 | var protocol thrift.TProtocol = protocolFactory.GetProtocol(transport) |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 59 | thriftTestClient := thrifttest.NewThriftTestClient(thrift.NewTStandardClient(protocol, protocol)) |
Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 60 | 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 |
| 70 | func TestTJSONProtocol(t *testing.T) { |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame^] | 71 | RunSocketTestSuite( |
| 72 | t, |
Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 73 | thrift.NewTJSONProtocolFactory(), |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame^] | 74 | thrift.NewTTransportFactory(), |
| 75 | ) |
| 76 | RunSocketTestSuite( |
| 77 | t, |
Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 78 | thrift.NewTJSONProtocolFactory(), |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame^] | 79 | thrift.NewTBufferedTransportFactory(8912), |
| 80 | ) |
| 81 | RunSocketTestSuite( |
| 82 | t, |
Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 83 | thrift.NewTJSONProtocolFactory(), |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame^] | 84 | thrift.NewTFramedTransportFactoryConf(thrift.NewTTransportFactory(), nil), |
| 85 | ) |
Jens Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | // Run test suite using TBinaryProtocol |
| 89 | func TestTBinaryProtocol(t *testing.T) { |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame^] | 90 | 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 Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | // Run test suite using TCompactBinaryProtocol |
| 108 | func TestTCompactProtocol(t *testing.T) { |
Yuxuan 'fishy' Wang | 17373a3 | 2021-08-26 11:04:27 -0700 | [diff] [blame^] | 109 | 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 Geyer | 5f9bdff | 2014-11-18 21:57:03 +0100 | [diff] [blame] | 124 | } |