David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [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 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 20 | #include <thrift/async/TAsyncBufferProcessor.h> |
| 21 | #include <thrift/async/TAsyncProtocolProcessor.h> |
| 22 | #include <thrift/async/TEvhttpServer.h> |
cyy | ca8af9b | 2019-01-11 22:13:12 +0800 | [diff] [blame] | 23 | #include <thrift/concurrency/ThreadFactory.h> |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 24 | #include <thrift/concurrency/ThreadManager.h> |
| 25 | #include <thrift/processor/TMultiplexedProcessor.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 26 | #include <thrift/protocol/TBinaryProtocol.h> |
Roger Meier | 023192f | 2014-02-12 09:35:12 +0100 | [diff] [blame] | 27 | #include <thrift/protocol/TCompactProtocol.h> |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 28 | #include <thrift/protocol/THeaderProtocol.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 29 | #include <thrift/protocol/TJSONProtocol.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 30 | #include <thrift/server/TNonblockingServer.h> |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 31 | #include <thrift/server/TSimpleServer.h> |
| 32 | #include <thrift/server/TThreadPoolServer.h> |
| 33 | #include <thrift/server/TThreadedServer.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 34 | #include <thrift/transport/THttpServer.h> |
| 35 | #include <thrift/transport/THttpTransport.h> |
James E. King III | 70b33fb | 2018-03-11 10:57:10 -0400 | [diff] [blame] | 36 | #include <thrift/transport/TNonblockingSSLServerSocket.h> |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 37 | #include <thrift/transport/TNonblockingServerSocket.h> |
| 38 | #include <thrift/transport/TSSLServerSocket.h> |
| 39 | #include <thrift/transport/TSSLSocket.h> |
| 40 | #include <thrift/transport/TServerSocket.h> |
Roger Meier | 49ff8b1 | 2012-04-13 09:12:31 +0000 | [diff] [blame] | 41 | #include <thrift/transport/TTransportUtils.h> |
penenin | 1ab096c | 2020-05-18 12:27:31 -0700 | [diff] [blame^] | 42 | #include <thrift/transport/TWebSocketServer.h> |
James E. King III | b2b767e | 2018-09-15 20:32:04 +0000 | [diff] [blame] | 43 | #include <thrift/transport/TZlibTransport.h> |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 44 | |
| 45 | #include "SecondService.h" |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 46 | #include "ThriftTest.h" |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 47 | |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 48 | #ifdef HAVE_STDINT_H |
| 49 | #include <stdint.h> |
| 50 | #endif |
| 51 | #ifdef HAVE_INTTYPES_H |
| 52 | #include <inttypes.h> |
| 53 | #endif |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 54 | #ifdef HAVE_SIGNAL_H |
| 55 | #include <signal.h> |
| 56 | #endif |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 57 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 58 | #include <iostream> |
| 59 | #include <stdexcept> |
| 60 | #include <sstream> |
| 61 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 62 | #include <boost/algorithm/string.hpp> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 63 | #include <boost/program_options.hpp> |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 64 | #include <boost/filesystem.hpp> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 65 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 66 | #if _WIN32 |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 67 | #include <thrift/windows/TWinsockSingleton.h> |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 68 | #endif |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 69 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 70 | using namespace std; |
| 71 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 72 | using namespace apache::thrift; |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 73 | using namespace apache::thrift::async; |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 74 | using namespace apache::thrift::concurrency; |
| 75 | using namespace apache::thrift::protocol; |
| 76 | using namespace apache::thrift::transport; |
| 77 | using namespace apache::thrift::server; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 78 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 79 | using namespace thrift::test; |
| 80 | |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 81 | // to handle a controlled shutdown, signal handling is mandatory |
| 82 | #ifdef HAVE_SIGNAL_H |
| 83 | apache::thrift::concurrency::Monitor gMonitor; |
| 84 | void signal_handler(int signum) |
| 85 | { |
| 86 | if (signum == SIGINT) { |
| 87 | gMonitor.notifyAll(); |
| 88 | } |
| 89 | } |
| 90 | #endif |
| 91 | |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 92 | class TestHandler : public ThriftTestIf { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 93 | public: |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 94 | TestHandler() = default; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 95 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 96 | void testVoid() override { printf("testVoid()\n"); } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 97 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 98 | void testString(string& out, const string& thing) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 99 | printf("testString(\"%s\")\n", thing.c_str()); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 100 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 103 | bool testBool(const bool thing) override { |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 104 | printf("testBool(%s)\n", thing ? "true" : "false"); |
| 105 | return thing; |
| 106 | } |
| 107 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 108 | int8_t testByte(const int8_t thing) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 109 | printf("testByte(%d)\n", (int)thing); |
| 110 | return thing; |
| 111 | } |
| 112 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 113 | int32_t testI32(const int32_t thing) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 114 | printf("testI32(%d)\n", thing); |
| 115 | return thing; |
| 116 | } |
| 117 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 118 | int64_t testI64(const int64_t thing) override { |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 119 | printf("testI64(%" PRId64 ")\n", thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 120 | return thing; |
| 121 | } |
| 122 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 123 | double testDouble(const double thing) override { |
Roger Meier | a8cef6e | 2011-07-17 18:55:59 +0000 | [diff] [blame] | 124 | printf("testDouble(%f)\n", thing); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 125 | return thing; |
| 126 | } |
| 127 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 128 | void testBinary(std::string& _return, const std::string& thing) override { |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 129 | std::ostringstream hexstr; |
| 130 | hexstr << std::hex << thing; |
James E. King III | 3ae3042 | 2018-03-12 07:33:22 -0400 | [diff] [blame] | 131 | printf("testBinary(%lu: %s)\n", safe_numeric_cast<unsigned long>(thing.size()), hexstr.str().c_str()); |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 132 | _return = thing; |
| 133 | } |
| 134 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 135 | void testStruct(Xtruct& out, const Xtruct& thing) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 136 | printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n", |
| 137 | thing.string_thing.c_str(), |
| 138 | (int)thing.byte_thing, |
| 139 | thing.i32_thing, |
| 140 | thing.i64_thing); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 141 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 144 | void testNest(Xtruct2& out, const Xtruct2& nest) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 145 | const Xtruct& thing = nest.struct_thing; |
| 146 | printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n", |
| 147 | (int)nest.byte_thing, |
| 148 | thing.string_thing.c_str(), |
| 149 | (int)thing.byte_thing, |
| 150 | thing.i32_thing, |
| 151 | thing.i64_thing, |
| 152 | nest.i32_thing); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 153 | out = nest; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 156 | void testMap(map<int32_t, int32_t>& out, const map<int32_t, int32_t>& thing) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 157 | printf("testMap({"); |
| 158 | map<int32_t, int32_t>::const_iterator m_iter; |
| 159 | bool first = true; |
| 160 | for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) { |
| 161 | if (first) { |
| 162 | first = false; |
| 163 | } else { |
| 164 | printf(", "); |
| 165 | } |
| 166 | printf("%d => %d", m_iter->first, m_iter->second); |
| 167 | } |
| 168 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 169 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 172 | void testStringMap(map<std::string, std::string>& out, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 173 | const map<std::string, std::string>& thing) override { |
Roger Meier | d3b9dca | 2011-06-24 14:01:10 +0000 | [diff] [blame] | 174 | printf("testMap({"); |
| 175 | map<std::string, std::string>::const_iterator m_iter; |
| 176 | bool first = true; |
| 177 | for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) { |
| 178 | if (first) { |
| 179 | first = false; |
| 180 | } else { |
| 181 | printf(", "); |
| 182 | } |
| 183 | printf("%s => %s", (m_iter->first).c_str(), (m_iter->second).c_str()); |
| 184 | } |
| 185 | printf("})\n"); |
| 186 | out = thing; |
| 187 | } |
| 188 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 189 | void testSet(set<int32_t>& out, const set<int32_t>& thing) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 190 | printf("testSet({"); |
| 191 | set<int32_t>::const_iterator s_iter; |
| 192 | bool first = true; |
| 193 | for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) { |
| 194 | if (first) { |
| 195 | first = false; |
| 196 | } else { |
| 197 | printf(", "); |
| 198 | } |
| 199 | printf("%d", *s_iter); |
| 200 | } |
| 201 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 202 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 205 | void testList(vector<int32_t>& out, const vector<int32_t>& thing) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 206 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 207 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 208 | bool first = true; |
| 209 | for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) { |
| 210 | if (first) { |
| 211 | first = false; |
| 212 | } else { |
| 213 | printf(", "); |
| 214 | } |
| 215 | printf("%d", *l_iter); |
| 216 | } |
| 217 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 218 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 221 | Numberz::type testEnum(const Numberz::type thing) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 222 | printf("testEnum(%d)\n", thing); |
| 223 | return thing; |
| 224 | } |
| 225 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 226 | UserId testTypedef(const UserId thing) override { |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 227 | printf("testTypedef(%" PRId64 ")\n", thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 228 | return thing; |
| 229 | } |
| 230 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 231 | void testMapMap(map<int32_t, map<int32_t, int32_t> >& mapmap, const int32_t hello) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 232 | printf("testMapMap(%d)\n", hello); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 233 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 234 | map<int32_t, int32_t> pos; |
| 235 | map<int32_t, int32_t> neg; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 236 | for (int i = 1; i < 5; i++) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 237 | pos.insert(make_pair(i, i)); |
| 238 | neg.insert(make_pair(-i, -i)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | mapmap.insert(make_pair(4, pos)); |
| 242 | mapmap.insert(make_pair(-4, neg)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 245 | void testInsanity(map<UserId, map<Numberz::type, Insanity> >& insane, const Insanity& argument) override { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 246 | printf("testInsanity()\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 247 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 248 | Insanity looney; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 249 | map<Numberz::type, Insanity> first_map; |
| 250 | map<Numberz::type, Insanity> second_map; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 251 | |
Nobuaki Sukegawa | 01ede04 | 2015-09-29 02:16:53 +0900 | [diff] [blame] | 252 | first_map.insert(make_pair(Numberz::TWO, argument)); |
| 253 | first_map.insert(make_pair(Numberz::THREE, argument)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 254 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 255 | second_map.insert(make_pair(Numberz::SIX, looney)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 256 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 257 | insane.insert(make_pair(1, first_map)); |
| 258 | insane.insert(make_pair(2, second_map)); |
| 259 | |
| 260 | printf("return"); |
| 261 | printf(" = {"); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 262 | map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 263 | for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) { |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 264 | printf("%" PRId64 " => {", i_iter->first); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 265 | map<Numberz::type, Insanity>::const_iterator i2_iter; |
| 266 | for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 267 | printf("%d => {", i2_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 268 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 269 | map<Numberz::type, UserId>::const_iterator um; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 270 | printf("{"); |
| 271 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
Roger Meier | 0e81480 | 2014-01-17 21:07:58 +0100 | [diff] [blame] | 272 | printf("%d => %" PRId64 ", ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 273 | } |
| 274 | printf("}, "); |
| 275 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 276 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 277 | vector<Xtruct>::const_iterator x; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 278 | printf("{"); |
| 279 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 280 | printf("{\"%s\", %d, %d, %" PRId64 "}, ", |
| 281 | x->string_thing.c_str(), |
| 282 | (int)x->byte_thing, |
| 283 | x->i32_thing, |
| 284 | x->i64_thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 285 | } |
| 286 | printf("}"); |
| 287 | |
| 288 | printf("}, "); |
| 289 | } |
| 290 | printf("}, "); |
| 291 | } |
| 292 | printf("}\n"); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 293 | } |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 294 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 295 | void testMulti(Xtruct& hello, |
| 296 | const int8_t arg0, |
| 297 | const int32_t arg1, |
| 298 | const int64_t arg2, |
| 299 | const std::map<int16_t, std::string>& arg3, |
| 300 | const Numberz::type arg4, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 301 | const UserId arg5) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 302 | (void)arg3; |
| 303 | (void)arg4; |
| 304 | (void)arg5; |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 305 | |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 306 | printf("testMulti()\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 307 | |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 308 | hello.string_thing = "Hello2"; |
| 309 | hello.byte_thing = arg0; |
| 310 | hello.i32_thing = arg1; |
| 311 | hello.i64_thing = (int64_t)arg2; |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 312 | } |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 313 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 314 | void testException(const std::string& arg) override { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 315 | printf("testException(%s)\n", arg.c_str()); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 316 | if (arg.compare("Xception") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 317 | Xception e; |
| 318 | e.errorCode = 1001; |
David Reiss | 9813cbe | 2009-01-31 21:39:11 +0000 | [diff] [blame] | 319 | e.message = arg; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 320 | throw e; |
Roger Meier | 1f8b48f | 2012-05-02 22:56:47 +0000 | [diff] [blame] | 321 | } else if (arg.compare("TException") == 0) { |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 322 | apache::thrift::TException e; |
David Reiss | 55ff70f | 2008-06-11 00:58:25 +0000 | [diff] [blame] | 323 | throw e; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 324 | } else { |
| 325 | Xtruct result; |
| 326 | result.string_thing = arg; |
| 327 | return; |
| 328 | } |
| 329 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 330 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 331 | void testMultiException(Xtruct& result, |
| 332 | const std::string& arg0, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 333 | const std::string& arg1) override { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 334 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 335 | printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 336 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 337 | if (arg0.compare("Xception") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 338 | Xception e; |
| 339 | e.errorCode = 1001; |
| 340 | e.message = "This is an Xception"; |
| 341 | throw e; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 342 | } else if (arg0.compare("Xception2") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 343 | Xception2 e; |
| 344 | e.errorCode = 2002; |
| 345 | e.struct_thing.string_thing = "This is an Xception2"; |
| 346 | throw e; |
| 347 | } else { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 348 | result.string_thing = arg1; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 349 | return; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 350 | } |
| 351 | } |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 352 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 353 | void testOneway(const int32_t aNum) override { |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 354 | printf("testOneway(%d): call received\n", aNum); |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 355 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 356 | }; |
| 357 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 358 | class SecondHandler : public SecondServiceIf |
| 359 | { |
| 360 | public: |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 361 | void secondtestString(std::string& result, const std::string& thing) override |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 362 | { result = "testString(\"" + thing + "\")"; } |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 363 | }; |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 364 | |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 365 | class TestProcessorEventHandler : public TProcessorEventHandler { |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 366 | void* getContext(const char* fn_name, void* serverContext) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 367 | (void)serverContext; |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 368 | return new std::string(fn_name); |
| 369 | } |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 370 | void freeContext(void* ctx, const char* fn_name) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 371 | (void)fn_name; |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 372 | delete static_cast<std::string*>(ctx); |
| 373 | } |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 374 | void preRead(void* ctx, const char* fn_name) override { communicate("preRead", ctx, fn_name); } |
| 375 | void postRead(void* ctx, const char* fn_name, uint32_t bytes) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 376 | (void)bytes; |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 377 | communicate("postRead", ctx, fn_name); |
| 378 | } |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 379 | void preWrite(void* ctx, const char* fn_name) override { communicate("preWrite", ctx, fn_name); } |
| 380 | void postWrite(void* ctx, const char* fn_name, uint32_t bytes) override { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 381 | (void)bytes; |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 382 | communicate("postWrite", ctx, fn_name); |
| 383 | } |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 384 | void asyncComplete(void* ctx, const char* fn_name) override { |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 385 | communicate("asyncComplete", ctx, fn_name); |
| 386 | } |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 387 | void handlerError(void* ctx, const char* fn_name) override { |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 388 | communicate("handlerError", ctx, fn_name); |
| 389 | } |
| 390 | |
| 391 | void communicate(const char* event, void* ctx, const char* fn_name) { |
| 392 | std::cout << event << ": " << *static_cast<std::string*>(ctx) << " = " << fn_name << std::endl; |
| 393 | } |
| 394 | }; |
| 395 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 396 | class TestHandlerAsync : public ThriftTestCobSvIf { |
| 397 | public: |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 398 | TestHandlerAsync(std::shared_ptr<TestHandler>& handler) : _delegate(handler) {} |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 399 | ~TestHandlerAsync() override = default; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 400 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 401 | void testVoid(std::function<void()> cob) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 402 | _delegate->testVoid(); |
| 403 | cob(); |
| 404 | } |
| 405 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 406 | void testString(std::function<void(std::string const& _return)> cob, |
| 407 | const std::string& thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 408 | std::string res; |
| 409 | _delegate->testString(res, thing); |
| 410 | cob(res); |
| 411 | } |
| 412 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 413 | void testBool(std::function<void(bool const& _return)> cob, const bool thing) override { |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 414 | bool res = _delegate->testBool(thing); |
| 415 | cob(res); |
| 416 | } |
| 417 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 418 | void testByte(std::function<void(int8_t const& _return)> cob, const int8_t thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 419 | int8_t res = _delegate->testByte(thing); |
| 420 | cob(res); |
| 421 | } |
| 422 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 423 | void testI32(std::function<void(int32_t const& _return)> cob, const int32_t thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 424 | int32_t res = _delegate->testI32(thing); |
| 425 | cob(res); |
| 426 | } |
| 427 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 428 | void testI64(std::function<void(int64_t const& _return)> cob, const int64_t thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 429 | int64_t res = _delegate->testI64(thing); |
| 430 | cob(res); |
| 431 | } |
| 432 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 433 | void testDouble(std::function<void(double const& _return)> cob, const double thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 434 | double res = _delegate->testDouble(thing); |
| 435 | cob(res); |
| 436 | } |
| 437 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 438 | void testBinary(std::function<void(std::string const& _return)> cob, |
| 439 | const std::string& thing) override { |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 440 | std::string res; |
| 441 | _delegate->testBinary(res, thing); |
| 442 | cob(res); |
| 443 | } |
| 444 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 445 | void testStruct(std::function<void(Xtruct const& _return)> cob, const Xtruct& thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 446 | Xtruct res; |
| 447 | _delegate->testStruct(res, thing); |
| 448 | cob(res); |
| 449 | } |
| 450 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 451 | void testNest(std::function<void(Xtruct2 const& _return)> cob, const Xtruct2& thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 452 | Xtruct2 res; |
| 453 | _delegate->testNest(res, thing); |
| 454 | cob(res); |
| 455 | } |
| 456 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 457 | void testMap(std::function<void(std::map<int32_t, int32_t> const& _return)> cob, |
| 458 | const std::map<int32_t, int32_t>& thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 459 | std::map<int32_t, int32_t> res; |
| 460 | _delegate->testMap(res, thing); |
| 461 | cob(res); |
| 462 | } |
| 463 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 464 | void testStringMap( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 465 | std::function<void(std::map<std::string, std::string> const& _return)> cob, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 466 | const std::map<std::string, std::string>& thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 467 | std::map<std::string, std::string> res; |
| 468 | _delegate->testStringMap(res, thing); |
| 469 | cob(res); |
| 470 | } |
| 471 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 472 | void testSet(std::function<void(std::set<int32_t> const& _return)> cob, |
| 473 | const std::set<int32_t>& thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 474 | std::set<int32_t> res; |
| 475 | _delegate->testSet(res, thing); |
| 476 | cob(res); |
| 477 | } |
| 478 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 479 | void testList(std::function<void(std::vector<int32_t> const& _return)> cob, |
| 480 | const std::vector<int32_t>& thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 481 | std::vector<int32_t> res; |
| 482 | _delegate->testList(res, thing); |
| 483 | cob(res); |
| 484 | } |
| 485 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 486 | void testEnum(std::function<void(Numberz::type const& _return)> cob, |
| 487 | const Numberz::type thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 488 | Numberz::type res = _delegate->testEnum(thing); |
| 489 | cob(res); |
| 490 | } |
| 491 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 492 | void testTypedef(std::function<void(UserId const& _return)> cob, const UserId thing) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 493 | UserId res = _delegate->testTypedef(thing); |
| 494 | cob(res); |
| 495 | } |
| 496 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 497 | void testMapMap( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 498 | std::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 499 | const int32_t hello) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 500 | std::map<int32_t, std::map<int32_t, int32_t> > res; |
| 501 | _delegate->testMapMap(res, hello); |
| 502 | cob(res); |
| 503 | } |
| 504 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 505 | void testInsanity( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 506 | std::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 507 | const Insanity& argument) override { |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 508 | std::map<UserId, std::map<Numberz::type, Insanity> > res; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 509 | _delegate->testInsanity(res, argument); |
| 510 | cob(res); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 511 | } |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 512 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 513 | void testMulti(std::function<void(Xtruct const& _return)> cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 514 | const int8_t arg0, |
| 515 | const int32_t arg1, |
| 516 | const int64_t arg2, |
| 517 | const std::map<int16_t, std::string>& arg3, |
| 518 | const Numberz::type arg4, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 519 | const UserId arg5) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 520 | Xtruct res; |
| 521 | _delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5); |
| 522 | cob(res); |
| 523 | } |
| 524 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 525 | void testException( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 526 | std::function<void()> cob, |
| 527 | std::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 528 | const std::string& arg) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 529 | try { |
| 530 | _delegate->testException(arg); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 531 | } catch (const apache::thrift::TException& e) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 532 | exn_cob(apache::thrift::TDelayedException::delayException(e)); |
| 533 | return; |
| 534 | } |
| 535 | cob(); |
| 536 | } |
| 537 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 538 | void testMultiException( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 539 | std::function<void(Xtruct const& _return)> cob, |
| 540 | std::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 541 | const std::string& arg0, |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 542 | const std::string& arg1) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 543 | Xtruct res; |
| 544 | try { |
| 545 | _delegate->testMultiException(res, arg0, arg1); |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 546 | } catch (const apache::thrift::TException& e) { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 547 | exn_cob(apache::thrift::TDelayedException::delayException(e)); |
| 548 | return; |
| 549 | } |
| 550 | cob(res); |
| 551 | } |
| 552 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 553 | void testOneway(std::function<void()> cob, const int32_t secondsToSleep) override { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 554 | _delegate->testOneway(secondsToSleep); |
| 555 | cob(); |
| 556 | } |
| 557 | |
| 558 | protected: |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 559 | std::shared_ptr<TestHandler> _delegate; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 560 | }; |
| 561 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 562 | namespace po = boost::program_options; |
| 563 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 564 | int main(int argc, char** argv) { |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 565 | |
Nobuaki Sukegawa | c874408 | 2016-03-09 19:55:56 +0900 | [diff] [blame] | 566 | string testDir = boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string(); |
| 567 | string certPath = testDir + "/keys/server.crt"; |
| 568 | string keyPath = testDir + "/keys/server.key"; |
cdwijayarathna | a07ec0b | 2014-08-09 17:45:56 +0530 | [diff] [blame] | 569 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 570 | #if _WIN32 |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 571 | transport::TWinsockSingleton::create(); |
| 572 | #endif |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 573 | int port = 9090; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 574 | bool ssl = false; |
James E. King III | b2b767e | 2018-09-15 20:32:04 +0000 | [diff] [blame] | 575 | bool zlib = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 576 | string transport_type = "buffered"; |
| 577 | string protocol_type = "binary"; |
| 578 | string server_type = "simple"; |
| 579 | string domain_socket = ""; |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 580 | bool abstract_namespace = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 581 | size_t workers = 4; |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 582 | int string_limit = 0; |
| 583 | int container_limit = 0; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 584 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 585 | po::options_description desc("Allowed options"); |
| 586 | desc.add_options() |
| 587 | ("help,h", "produce help message") |
| 588 | ("port", po::value<int>(&port)->default_value(port), "Port number to listen") |
| 589 | ("domain-socket", po::value<string>(&domain_socket) ->default_value(domain_socket), "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)") |
| 590 | ("abstract-namespace", "Create the domain socket in the Abstract Namespace (no connection with filesystem pathnames)") |
| 591 | ("server-type", po::value<string>(&server_type)->default_value(server_type), "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"") |
penenin | 1ab096c | 2020-05-18 12:27:31 -0700 | [diff] [blame^] | 592 | ("transport", po::value<string>(&transport_type)->default_value(transport_type), "transport: buffered, framed, http, websocket, zlib") |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 593 | ("protocol", po::value<string>(&protocol_type)->default_value(protocol_type), "protocol: binary, compact, header, json, multi, multic, multih, multij") |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 594 | ("ssl", "Encrypted Transport using SSL") |
James E. King III | b2b767e | 2018-09-15 20:32:04 +0000 | [diff] [blame] | 595 | ("zlib", "Wrapped Transport using Zlib") |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 596 | ("processor-events", "processor-events") |
| 597 | ("workers,n", po::value<size_t>(&workers)->default_value(workers), "Number of thread pools workers. Only valid for thread-pool server type") |
| 598 | ("string-limit", po::value<int>(&string_limit)) |
| 599 | ("container-limit", po::value<int>(&container_limit)); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 600 | |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 601 | po::variables_map vm; |
| 602 | po::store(po::parse_command_line(argc, argv, desc), vm); |
| 603 | po::notify(vm); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 604 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 605 | if (vm.count("help")) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 606 | cout << desc << "\n"; |
| 607 | return 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 608 | } |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 609 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 610 | try { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 611 | if (!server_type.empty()) { |
| 612 | if (server_type == "simple") { |
| 613 | } else if (server_type == "thread-pool") { |
| 614 | } else if (server_type == "threaded") { |
| 615 | } else if (server_type == "nonblocking") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 616 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 617 | throw invalid_argument("Unknown server type " + server_type); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 618 | } |
| 619 | } |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 620 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 621 | if (!protocol_type.empty()) { |
| 622 | if (protocol_type == "binary") { |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 623 | } else if (protocol_type == "compact") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 624 | } else if (protocol_type == "json") { |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 625 | } else if (protocol_type == "header") { |
James E. King, III | 39eaae6 | 2017-11-19 20:17:33 -0500 | [diff] [blame] | 626 | } else if (protocol_type == "multi") { // multiplexed binary |
| 627 | } else if (protocol_type == "multic") { // multiplexed compact |
| 628 | } else if (protocol_type == "multih") { // multiplexed header |
| 629 | } else if (protocol_type == "multij") { // multiplexed json |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 630 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 631 | throw invalid_argument("Unknown protocol type " + protocol_type); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
Roger Meier | 284101c | 2014-03-11 21:20:35 +0100 | [diff] [blame] | 635 | if (!transport_type.empty()) { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 636 | if (transport_type == "buffered") { |
| 637 | } else if (transport_type == "framed") { |
| 638 | } else if (transport_type == "http") { |
penenin | 1ab096c | 2020-05-18 12:27:31 -0700 | [diff] [blame^] | 639 | } else if (transport_type == "websocket") { |
James E. King III | b2b767e | 2018-09-15 20:32:04 +0000 | [diff] [blame] | 640 | } else if (transport_type == "zlib") { |
| 641 | // crosstester will pass zlib as a flag and a transport right now... |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 642 | } else { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 643 | throw invalid_argument("Unknown transport type " + transport_type); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 644 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 645 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 646 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 647 | } catch (std::exception& e) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 648 | cerr << e.what() << endl; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 649 | cout << desc << "\n"; |
| 650 | return 1; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 653 | if (vm.count("ssl")) { |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 654 | ssl = true; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 655 | } |
| 656 | |
James E. King III | b2b767e | 2018-09-15 20:32:04 +0000 | [diff] [blame] | 657 | if (vm.count("zlib")) { |
| 658 | zlib = true; |
| 659 | } |
| 660 | |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 661 | #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE) |
| 662 | if (ssl) { |
| 663 | signal(SIGPIPE, SIG_IGN); // for OpenSSL, otherwise we end abruptly |
| 664 | } |
| 665 | #endif |
| 666 | |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 667 | if (vm.count("abstract-namespace")) { |
| 668 | abstract_namespace = true; |
| 669 | } |
| 670 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 671 | // Dispatcher |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 672 | std::shared_ptr<TProtocolFactory> protocolFactory; |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 673 | if (protocol_type == "json" || protocol_type == "multij") { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 674 | std::shared_ptr<TProtocolFactory> jsonProtocolFactory(new TJSONProtocolFactory()); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 675 | protocolFactory = jsonProtocolFactory; |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 676 | } else if (protocol_type == "compact" || protocol_type == "multic") { |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 677 | auto *compactProtocolFactory = new TCompactProtocolFactoryT<TBufferBase>(); |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 678 | compactProtocolFactory->setContainerSizeLimit(container_limit); |
| 679 | compactProtocolFactory->setStringSizeLimit(string_limit); |
| 680 | protocolFactory.reset(compactProtocolFactory); |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 681 | } else if (protocol_type == "header" || protocol_type == "multih") { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 682 | std::shared_ptr<TProtocolFactory> headerProtocolFactory(new THeaderProtocolFactory()); |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 683 | protocolFactory = headerProtocolFactory; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 684 | } else { |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 685 | auto* binaryProtocolFactory = new TBinaryProtocolFactoryT<TBufferBase>(); |
Nobuaki Sukegawa | 8565061 | 2016-01-08 03:26:44 +0900 | [diff] [blame] | 686 | binaryProtocolFactory->setContainerSizeLimit(container_limit); |
| 687 | binaryProtocolFactory->setStringSizeLimit(string_limit); |
| 688 | protocolFactory.reset(binaryProtocolFactory); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 689 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 690 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 691 | // Processors |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 692 | std::shared_ptr<TestHandler> testHandler(new TestHandler()); |
| 693 | std::shared_ptr<TProcessor> testProcessor(new ThriftTestProcessor(testHandler)); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 694 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 695 | if (vm.count("processor-events")) { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 696 | testProcessor->setEventHandler( |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 697 | std::shared_ptr<TProcessorEventHandler>(new TestProcessorEventHandler())); |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 698 | } |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 699 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 700 | // Transport |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 701 | std::shared_ptr<TSSLSocketFactory> sslSocketFactory; |
| 702 | std::shared_ptr<TServerSocket> serverSocket; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 703 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 704 | if (ssl) { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 705 | sslSocketFactory = std::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
Nobuaki Sukegawa | c874408 | 2016-03-09 19:55:56 +0900 | [diff] [blame] | 706 | sslSocketFactory->loadCertificate(certPath.c_str()); |
| 707 | sslSocketFactory->loadPrivateKey(keyPath.c_str()); |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 708 | sslSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
James E. King III | 70b33fb | 2018-03-11 10:57:10 -0400 | [diff] [blame] | 709 | if (server_type != "nonblocking") { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 710 | serverSocket = std::shared_ptr<TServerSocket>(new TSSLServerSocket(port, sslSocketFactory)); |
James E. King III | 70b33fb | 2018-03-11 10:57:10 -0400 | [diff] [blame] | 711 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 712 | } else { |
Roger Meier | c94b293 | 2014-02-22 20:07:33 +0100 | [diff] [blame] | 713 | if (domain_socket != "") { |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 714 | if (abstract_namespace) { |
| 715 | std::string abstract_socket("\0", 1); |
| 716 | abstract_socket += domain_socket; |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 717 | serverSocket = std::shared_ptr<TServerSocket>(new TServerSocket(abstract_socket)); |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 718 | } else { |
| 719 | unlink(domain_socket.c_str()); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 720 | serverSocket = std::shared_ptr<TServerSocket>(new TServerSocket(domain_socket)); |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 721 | } |
Roger Meier | c94b293 | 2014-02-22 20:07:33 +0100 | [diff] [blame] | 722 | port = 0; |
| 723 | } else { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 724 | serverSocket = std::shared_ptr<TServerSocket>(new TServerSocket(port)); |
Roger Meier | c94b293 | 2014-02-22 20:07:33 +0100 | [diff] [blame] | 725 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 726 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 727 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 728 | // Factory |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 729 | std::shared_ptr<TTransportFactory> transportFactory; |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 730 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 731 | if (transport_type == "http" && server_type != "nonblocking") { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 732 | transportFactory = std::make_shared<THttpServerTransportFactory>(); |
penenin | 1ab096c | 2020-05-18 12:27:31 -0700 | [diff] [blame^] | 733 | } else if (transport_type == "websocket" && server_type != "nonblocking") { |
| 734 | if (protocol_type == "json" || protocol_type == "multij") { |
| 735 | transportFactory = std::make_shared<TTextWebSocketServerTransportFactory>(); |
| 736 | } else { |
| 737 | transportFactory = std::make_shared<TBinaryWebSocketServerTransportFactory>(); |
| 738 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 739 | } else if (transport_type == "framed") { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 740 | transportFactory = std::make_shared<TFramedTransportFactory>(); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 741 | } else { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 742 | transportFactory = std::make_shared<TBufferedTransportFactory>(); |
James E. King III | b2b767e | 2018-09-15 20:32:04 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | if (zlib) { |
Mario Emmenlauer | 2d2df9e | 2020-04-24 18:02:18 +0200 | [diff] [blame] | 746 | // currently TZlibTransportFactory is the only factory than can wrap another: |
| 747 | transportFactory = std::make_shared<TZlibTransportFactory>(transportFactory); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 748 | } |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 749 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 750 | // Server Info |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 751 | cout << "Starting \"" << server_type << "\" server (" << transport_type << "/" << protocol_type |
pavlo | dd08f6e | 2015-10-08 16:43:56 -0400 | [diff] [blame] | 752 | << ") listen on: "; |
| 753 | if (abstract_namespace) { |
| 754 | cout << '@'; |
| 755 | } |
| 756 | cout << domain_socket; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 757 | if (port != 0) { |
| 758 | cout << port; |
| 759 | } |
| 760 | cout << endl; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 761 | |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 762 | // Multiplexed Processor if needed |
| 763 | if (boost::starts_with(protocol_type, "multi")) { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 764 | std::shared_ptr<SecondHandler> secondHandler(new SecondHandler()); |
| 765 | std::shared_ptr<SecondServiceProcessor> secondProcessor(new SecondServiceProcessor(secondHandler)); |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 766 | |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 767 | std::shared_ptr<TMultiplexedProcessor> multiplexedProcessor(new TMultiplexedProcessor()); |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 768 | multiplexedProcessor->registerDefault(testProcessor); // non-multi clients go to the default processor (multi:binary, multic:compact, ...) |
| 769 | multiplexedProcessor->registerProcessor("ThriftTest", testProcessor); |
| 770 | multiplexedProcessor->registerProcessor("SecondService", secondProcessor); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 771 | testProcessor = std::dynamic_pointer_cast<TProcessor>(multiplexedProcessor); |
James E. King, III | 58402ff | 2017-11-17 14:41:46 -0500 | [diff] [blame] | 772 | } |
| 773 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 774 | // Server |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 775 | std::shared_ptr<apache::thrift::server::TServer> server; |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 776 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 777 | if (server_type == "simple") { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 778 | server.reset(new TSimpleServer(testProcessor, serverSocket, transportFactory, protocolFactory)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 779 | } else if (server_type == "thread-pool") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 780 | |
cyy | ca8af9b | 2019-01-11 22:13:12 +0800 | [diff] [blame] | 781 | std::shared_ptr<ThreadFactory> threadFactory |
| 782 | = std::shared_ptr<ThreadFactory>(new ThreadFactory()); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 783 | |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 784 | std::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workers); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 785 | threadManager->threadFactory(threadFactory); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 786 | threadManager->start(); |
| 787 | |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 788 | server.reset(new TThreadPoolServer(testProcessor, |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 789 | serverSocket, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 790 | transportFactory, |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 791 | protocolFactory, |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 792 | threadManager)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 793 | } else if (server_type == "threaded") { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 794 | server.reset( |
| 795 | new TThreadedServer(testProcessor, serverSocket, transportFactory, protocolFactory)); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 796 | } else if (server_type == "nonblocking") { |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 797 | if (transport_type == "http") { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 798 | std::shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler)); |
| 799 | std::shared_ptr<TAsyncProcessor> testProcessorAsync( |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 800 | new ThriftTestAsyncProcessor(testHandlerAsync)); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 801 | std::shared_ptr<TAsyncBufferProcessor> testBufferProcessor( |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 802 | new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory)); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 803 | |
| 804 | // not loading nonblockingServer into "server" because |
| 805 | // TEvhttpServer doesn't inherit from TServer, and doesn't |
| 806 | // provide a stop method. |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 807 | TEvhttpServer nonblockingServer(testBufferProcessor, port); |
| 808 | nonblockingServer.serve(); |
James E. King III | 70b33fb | 2018-03-11 10:57:10 -0400 | [diff] [blame] | 809 | } else if (transport_type == "framed") { |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 810 | std::shared_ptr<transport::TNonblockingServerTransport> nbSocket; |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 811 | nbSocket.reset( |
| 812 | ssl ? new transport::TNonblockingSSLServerSocket(port, sslSocketFactory) |
| 813 | : new transport::TNonblockingServerSocket(port)); |
Divya Thaluru | 808d143 | 2017-08-06 16:36:36 -0700 | [diff] [blame] | 814 | server.reset(new TNonblockingServer(testProcessor, protocolFactory, nbSocket)); |
James E. King III | 70b33fb | 2018-03-11 10:57:10 -0400 | [diff] [blame] | 815 | } else { |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 816 | cerr << "server-type nonblocking requires transport of http or framed" << endl; |
| 817 | exit(1); |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame] | 818 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 821 | if (server.get() != nullptr) { |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 822 | if (protocol_type == "header") { |
James E. King, III | df89913 | 2016-11-12 15:16:30 -0500 | [diff] [blame] | 823 | // Tell the server to use the same protocol for input / output |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 824 | // if using header |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 825 | server->setOutputProtocolFactory(std::shared_ptr<TProtocolFactory>()); |
Dave Watson | 792db4e | 2015-01-16 11:22:01 -0800 | [diff] [blame] | 826 | } |
Mario Emmenlauer | 2d2df9e | 2020-04-24 18:02:18 +0200 | [diff] [blame] | 827 | |
cyy | ca8af9b | 2019-01-11 22:13:12 +0800 | [diff] [blame] | 828 | apache::thrift::concurrency::ThreadFactory factory; |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 829 | factory.setDetached(false); |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 830 | std::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server); |
| 831 | std::shared_ptr<apache::thrift::concurrency::Thread> thread |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame] | 832 | = factory.newThread(serverThreadRunner); |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 833 | |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 834 | #ifdef HAVE_SIGNAL_H |
| 835 | signal(SIGINT, signal_handler); |
| 836 | #endif |
| 837 | |
| 838 | thread->start(); |
| 839 | gMonitor.waitForever(); // wait for a shutdown signal |
Mario Emmenlauer | 2d2df9e | 2020-04-24 18:02:18 +0200 | [diff] [blame] | 840 | |
James E. King III | 9bea32f | 2018-03-16 16:07:42 -0400 | [diff] [blame] | 841 | #ifdef HAVE_SIGNAL_H |
| 842 | signal(SIGINT, SIG_DFL); |
| 843 | #endif |
Jake Farrell | 5d02b80 | 2014-01-07 21:42:01 -0500 | [diff] [blame] | 844 | |
| 845 | server->stop(); |
| 846 | thread->join(); |
| 847 | server.reset(); |
| 848 | } |
| 849 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 850 | cout << "done." << endl; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 851 | return 0; |
| 852 | } |