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