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 | |
Roger Meier | d3b9dca | 2011-06-24 14:01:10 +0000 | [diff] [blame] | 20 | #define __STDC_FORMAT_MACROS |
| 21 | #include <inttypes.h> |
| 22 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 23 | #include <concurrency/ThreadManager.h> |
| 24 | #include <concurrency/PosixThreadFactory.h> |
| 25 | #include <protocol/TBinaryProtocol.h> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 26 | #include <protocol/TJSONProtocol.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 27 | #include <server/TSimpleServer.h> |
Mark Slee | 0c2dff3 | 2007-03-09 19:26:57 +0000 | [diff] [blame] | 28 | #include <server/TThreadedServer.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 29 | #include <server/TThreadPoolServer.h> |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame^] | 30 | #include <async/TEvhttpServer.h> |
| 31 | #include <async/TAsyncBufferProcessor.h> |
| 32 | #include <async/TAsyncProtocolProcessor.h> |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 33 | #include <server/TNonblockingServer.h> |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 34 | #include <transport/TServerSocket.h> |
Roger Meier | bb09f44 | 2011-05-31 20:35:37 +0000 | [diff] [blame] | 35 | #include <transport/TSSLServerSocket.h> |
| 36 | #include <transport/TSSLSocket.h> |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 37 | #include <transport/THttpServer.h> |
| 38 | #include <transport/THttpTransport.h> |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 39 | #include <transport/TTransportUtils.h> |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 40 | #include "ThriftTest.h" |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 41 | |
| 42 | #include <iostream> |
| 43 | #include <stdexcept> |
| 44 | #include <sstream> |
| 45 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 46 | #include <boost/program_options.hpp> |
| 47 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 48 | #include <signal.h> |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 49 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 50 | using namespace std; |
Mark Slee | 0c2dff3 | 2007-03-09 19:26:57 +0000 | [diff] [blame] | 51 | using namespace boost; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 52 | |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 53 | using namespace apache::thrift; |
| 54 | using namespace apache::thrift::concurrency; |
| 55 | using namespace apache::thrift::protocol; |
| 56 | using namespace apache::thrift::transport; |
| 57 | using namespace apache::thrift::server; |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame^] | 58 | using namespace apache::thrift::async; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 59 | |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 60 | using namespace thrift::test; |
| 61 | |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 62 | class TestHandler : public ThriftTestIf { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 63 | public: |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 64 | TestHandler() {} |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 65 | |
| 66 | void testVoid() { |
| 67 | printf("testVoid()\n"); |
| 68 | } |
| 69 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 70 | void testString(string& out, const string &thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 71 | printf("testString(\"%s\")\n", thing.c_str()); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 72 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 75 | int8_t testByte(const int8_t thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 76 | printf("testByte(%d)\n", (int)thing); |
| 77 | return thing; |
| 78 | } |
| 79 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 80 | int32_t testI32(const int32_t thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 81 | printf("testI32(%d)\n", thing); |
| 82 | return thing; |
| 83 | } |
| 84 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 85 | int64_t testI64(const int64_t thing) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 86 | printf("testI64(%"PRId64")\n", thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 87 | return thing; |
| 88 | } |
| 89 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 90 | double testDouble(const double thing) { |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 91 | printf("testDouble(%lf)\n", thing); |
| 92 | return thing; |
| 93 | } |
| 94 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 95 | void testStruct(Xtruct& out, const Xtruct &thing) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 96 | printf("testStruct({\"%s\", %d, %d, %"PRId64"})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 97 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 100 | void testNest(Xtruct2& out, const Xtruct2& nest) { |
| 101 | const Xtruct &thing = nest.struct_thing; |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 102 | printf("testNest({%d, {\"%s\", %d, %d, %"PRId64"}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 103 | out = nest; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 106 | void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 107 | printf("testMap({"); |
| 108 | map<int32_t, int32_t>::const_iterator m_iter; |
| 109 | bool first = true; |
| 110 | for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) { |
| 111 | if (first) { |
| 112 | first = false; |
| 113 | } else { |
| 114 | printf(", "); |
| 115 | } |
| 116 | printf("%d => %d", m_iter->first, m_iter->second); |
| 117 | } |
| 118 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 119 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Roger Meier | d3b9dca | 2011-06-24 14:01:10 +0000 | [diff] [blame] | 122 | void testStringMap(map<std::string, std::string> &out, const map<std::string, std::string> &thing) { |
| 123 | printf("testMap({"); |
| 124 | map<std::string, std::string>::const_iterator m_iter; |
| 125 | bool first = true; |
| 126 | for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) { |
| 127 | if (first) { |
| 128 | first = false; |
| 129 | } else { |
| 130 | printf(", "); |
| 131 | } |
| 132 | printf("%s => %s", (m_iter->first).c_str(), (m_iter->second).c_str()); |
| 133 | } |
| 134 | printf("})\n"); |
| 135 | out = thing; |
| 136 | } |
| 137 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 138 | void testSet(set<int32_t> &out, const set<int32_t> &thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 139 | printf("testSet({"); |
| 140 | set<int32_t>::const_iterator s_iter; |
| 141 | bool first = true; |
| 142 | for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) { |
| 143 | if (first) { |
| 144 | first = false; |
| 145 | } else { |
| 146 | printf(", "); |
| 147 | } |
| 148 | printf("%d", *s_iter); |
| 149 | } |
| 150 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 151 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 154 | void testList(vector<int32_t> &out, const vector<int32_t> &thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 155 | printf("testList({"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 156 | vector<int32_t>::const_iterator l_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 157 | bool first = true; |
| 158 | for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) { |
| 159 | if (first) { |
| 160 | first = false; |
| 161 | } else { |
| 162 | printf(", "); |
| 163 | } |
| 164 | printf("%d", *l_iter); |
| 165 | } |
| 166 | printf("})\n"); |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 167 | out = thing; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 170 | Numberz::type testEnum(const Numberz::type thing) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 171 | printf("testEnum(%d)\n", thing); |
| 172 | return thing; |
| 173 | } |
| 174 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 175 | UserId testTypedef(const UserId thing) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 176 | printf("testTypedef(%"PRId64")\n", thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 177 | return thing; |
| 178 | } |
| 179 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 180 | void testMapMap(map<int32_t, map<int32_t,int32_t> > &mapmap, const int32_t hello) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 181 | printf("testMapMap(%d)\n", hello); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 182 | |
| 183 | map<int32_t,int32_t> pos; |
| 184 | map<int32_t,int32_t> neg; |
| 185 | for (int i = 1; i < 5; i++) { |
| 186 | pos.insert(make_pair(i,i)); |
| 187 | neg.insert(make_pair(-i,-i)); |
| 188 | } |
| 189 | |
| 190 | mapmap.insert(make_pair(4, pos)); |
| 191 | mapmap.insert(make_pair(-4, neg)); |
| 192 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 195 | void testInsanity(map<UserId, map<Numberz::type,Insanity> > &insane, const Insanity &argument) { |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 196 | printf("testInsanity()\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 197 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 198 | Xtruct hello; |
| 199 | hello.string_thing = "Hello2"; |
| 200 | hello.byte_thing = 2; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 201 | hello.i32_thing = 2; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 202 | hello.i64_thing = 2; |
| 203 | |
| 204 | Xtruct goodbye; |
| 205 | goodbye.string_thing = "Goodbye4"; |
| 206 | goodbye.byte_thing = 4; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 207 | goodbye.i32_thing = 4; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 208 | goodbye.i64_thing = 4; |
| 209 | |
| 210 | Insanity crazy; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 211 | crazy.userMap.insert(make_pair(Numberz::EIGHT, 8)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 212 | crazy.xtructs.push_back(goodbye); |
| 213 | |
| 214 | Insanity looney; |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 215 | crazy.userMap.insert(make_pair(Numberz::FIVE, 5)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 216 | crazy.xtructs.push_back(hello); |
| 217 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 218 | map<Numberz::type, Insanity> first_map; |
| 219 | map<Numberz::type, Insanity> second_map; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 220 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 221 | first_map.insert(make_pair(Numberz::TWO, crazy)); |
| 222 | first_map.insert(make_pair(Numberz::THREE, crazy)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 223 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 224 | second_map.insert(make_pair(Numberz::SIX, looney)); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 225 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 226 | insane.insert(make_pair(1, first_map)); |
| 227 | insane.insert(make_pair(2, second_map)); |
| 228 | |
| 229 | printf("return"); |
| 230 | printf(" = {"); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 231 | map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 232 | for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 233 | printf("%"PRId64" => {", i_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 234 | map<Numberz::type,Insanity>::const_iterator i2_iter; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 235 | for (i2_iter = i_iter->second.begin(); |
| 236 | i2_iter != i_iter->second.end(); |
| 237 | ++i2_iter) { |
| 238 | printf("%d => {", i2_iter->first); |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 239 | map<Numberz::type, UserId> userMap = i2_iter->second.userMap; |
| 240 | map<Numberz::type, UserId>::const_iterator um; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 241 | printf("{"); |
| 242 | for (um = userMap.begin(); um != userMap.end(); ++um) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 243 | printf("%d => %"PRId64", ", um->first, um->second); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 244 | } |
| 245 | printf("}, "); |
| 246 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 247 | vector<Xtruct> xtructs = i2_iter->second.xtructs; |
| 248 | vector<Xtruct>::const_iterator x; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 249 | printf("{"); |
| 250 | for (x = xtructs.begin(); x != xtructs.end(); ++x) { |
David Reiss | bc3dddb | 2007-08-22 23:20:24 +0000 | [diff] [blame] | 251 | printf("{\"%s\", %d, %d, %"PRId64"}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 252 | } |
| 253 | printf("}"); |
| 254 | |
| 255 | printf("}, "); |
| 256 | } |
| 257 | printf("}, "); |
| 258 | } |
| 259 | printf("}\n"); |
| 260 | |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 261 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 262 | } |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 263 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 264 | void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> &arg3, const Numberz::type arg4, const UserId arg5) { |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 265 | printf("testMulti()\n"); |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 266 | |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 267 | hello.string_thing = "Hello2"; |
| 268 | hello.byte_thing = arg0; |
| 269 | hello.i32_thing = arg1; |
| 270 | hello.i64_thing = (int64_t)arg2; |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 271 | } |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 272 | |
David Reiss | 55ff70f | 2008-06-11 00:58:25 +0000 | [diff] [blame] | 273 | void testException(const std::string &arg) |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 274 | throw(Xception, apache::thrift::TException) |
David Reiss | 55ff70f | 2008-06-11 00:58:25 +0000 | [diff] [blame] | 275 | { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 276 | printf("testException(%s)\n", arg.c_str()); |
Mark Slee | d3d733a | 2006-09-01 22:19:06 +0000 | [diff] [blame] | 277 | if (arg.compare("Xception") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 278 | Xception e; |
| 279 | e.errorCode = 1001; |
David Reiss | 9813cbe | 2009-01-31 21:39:11 +0000 | [diff] [blame] | 280 | e.message = arg; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 281 | throw e; |
David Reiss | 55ff70f | 2008-06-11 00:58:25 +0000 | [diff] [blame] | 282 | } else if (arg.compare("ApplicationException") == 0) { |
T Jake Luciani | b5e6221 | 2009-01-31 22:36:20 +0000 | [diff] [blame] | 283 | apache::thrift::TException e; |
David Reiss | 55ff70f | 2008-06-11 00:58:25 +0000 | [diff] [blame] | 284 | throw e; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 285 | } else { |
| 286 | Xtruct result; |
| 287 | result.string_thing = arg; |
| 288 | return; |
| 289 | } |
| 290 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 291 | |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 292 | void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 293 | |
Marc Slemko | 71d4e47 | 2006-08-15 22:34:04 +0000 | [diff] [blame] | 294 | printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str()); |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 295 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 296 | if (arg0.compare("Xception") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 297 | Xception e; |
| 298 | e.errorCode = 1001; |
| 299 | e.message = "This is an Xception"; |
| 300 | throw e; |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 301 | } else if (arg0.compare("Xception2") == 0) { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 302 | Xception2 e; |
| 303 | e.errorCode = 2002; |
| 304 | e.struct_thing.string_thing = "This is an Xception2"; |
| 305 | throw e; |
| 306 | } else { |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 307 | result.string_thing = arg1; |
Mark Slee | 1921d20 | 2007-01-24 19:43:06 +0000 | [diff] [blame] | 308 | return; |
Marc Slemko | bf4fd19 | 2006-08-15 21:29:39 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 311 | |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 312 | void testOneway(int sleepFor) { |
| 313 | printf("testOneway(%d): Sleeping...\n", sleepFor); |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 314 | sleep(sleepFor); |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 315 | printf("testOneway(%d): done sleeping!\n", sleepFor); |
David Reiss | 2ab6fe8 | 2008-02-18 02:11:44 +0000 | [diff] [blame] | 316 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 317 | }; |
| 318 | |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 319 | |
| 320 | class TestProcessorEventHandler : public TProcessorEventHandler { |
David Reiss | 2324871 | 2010-10-06 17:10:08 +0000 | [diff] [blame] | 321 | virtual void* getContext(const char* fn_name, void* serverContext) { |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 322 | return new std::string(fn_name); |
| 323 | } |
| 324 | virtual void freeContext(void* ctx, const char* fn_name) { |
| 325 | delete static_cast<std::string*>(ctx); |
| 326 | } |
| 327 | virtual void preRead(void* ctx, const char* fn_name) { |
| 328 | communicate("preRead", ctx, fn_name); |
| 329 | } |
David Reiss | ef7200f | 2010-10-06 17:09:42 +0000 | [diff] [blame] | 330 | virtual void postRead(void* ctx, const char* fn_name, uint32_t bytes) { |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 331 | communicate("postRead", ctx, fn_name); |
| 332 | } |
| 333 | virtual void preWrite(void* ctx, const char* fn_name) { |
| 334 | communicate("preWrite", ctx, fn_name); |
| 335 | } |
David Reiss | ef7200f | 2010-10-06 17:09:42 +0000 | [diff] [blame] | 336 | virtual void postWrite(void* ctx, const char* fn_name, uint32_t bytes) { |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 337 | communicate("postWrite", ctx, fn_name); |
| 338 | } |
| 339 | virtual void asyncComplete(void* ctx, const char* fn_name) { |
| 340 | communicate("asyncComplete", ctx, fn_name); |
| 341 | } |
| 342 | virtual void handlerError(void* ctx, const char* fn_name) { |
| 343 | communicate("handlerError", ctx, fn_name); |
| 344 | } |
| 345 | |
| 346 | void communicate(const char* event, void* ctx, const char* fn_name) { |
| 347 | std::cout << event << ": " << *static_cast<std::string*>(ctx) << " = " << fn_name << std::endl; |
| 348 | } |
| 349 | }; |
| 350 | |
| 351 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame^] | 352 | class TestHandlerAsync : public ThriftTestCobSvIf { |
| 353 | public: |
| 354 | TestHandlerAsync(shared_ptr<TestHandler>& handler) : _delegate(handler) {} |
| 355 | virtual ~TestHandlerAsync() {} |
| 356 | |
| 357 | virtual void testVoid(std::tr1::function<void()> cob) { |
| 358 | _delegate->testVoid(); |
| 359 | cob(); |
| 360 | } |
| 361 | |
| 362 | virtual void testString(std::tr1::function<void(std::string const& _return)> cob, const std::string& thing) { |
| 363 | std::string res; |
| 364 | _delegate->testString(res, thing); |
| 365 | cob(res); |
| 366 | } |
| 367 | |
| 368 | virtual void testByte(std::tr1::function<void(int8_t const& _return)> cob, const int8_t thing) { |
| 369 | int8_t res = _delegate->testByte(thing); |
| 370 | cob(res); |
| 371 | } |
| 372 | |
| 373 | virtual void testI32(std::tr1::function<void(int32_t const& _return)> cob, const int32_t thing) { |
| 374 | int32_t res = _delegate->testI32(thing); |
| 375 | cob(res); |
| 376 | } |
| 377 | |
| 378 | virtual void testI64(std::tr1::function<void(int64_t const& _return)> cob, const int64_t thing) { |
| 379 | int64_t res = _delegate->testI64(thing); |
| 380 | cob(res); |
| 381 | } |
| 382 | |
| 383 | virtual void testDouble(std::tr1::function<void(double const& _return)> cob, const double thing) { |
| 384 | double res = _delegate->testDouble(thing); |
| 385 | cob(res); |
| 386 | } |
| 387 | |
| 388 | virtual void testStruct(std::tr1::function<void(Xtruct const& _return)> cob, const Xtruct& thing) { |
| 389 | Xtruct res; |
| 390 | _delegate->testStruct(res, thing); |
| 391 | cob(res); |
| 392 | } |
| 393 | |
| 394 | virtual void testNest(std::tr1::function<void(Xtruct2 const& _return)> cob, const Xtruct2& thing) { |
| 395 | Xtruct2 res; |
| 396 | _delegate->testNest(res, thing); |
| 397 | cob(res); |
| 398 | } |
| 399 | |
| 400 | virtual void testMap(std::tr1::function<void(std::map<int32_t, int32_t> const& _return)> cob, const std::map<int32_t, int32_t> & thing) { |
| 401 | std::map<int32_t, int32_t> res; |
| 402 | _delegate->testMap(res, thing); |
| 403 | cob(res); |
| 404 | } |
| 405 | |
| 406 | virtual void testStringMap(std::tr1::function<void(std::map<std::string, std::string> const& _return)> cob, const std::map<std::string, std::string> & thing) { |
| 407 | std::map<std::string, std::string> res; |
| 408 | _delegate->testStringMap(res, thing); |
| 409 | cob(res); |
| 410 | } |
| 411 | |
| 412 | virtual void testSet(std::tr1::function<void(std::set<int32_t> const& _return)> cob, const std::set<int32_t> & thing) { |
| 413 | std::set<int32_t> res; |
| 414 | _delegate->testSet(res, thing); |
| 415 | cob(res); |
| 416 | } |
| 417 | |
| 418 | virtual void testList(std::tr1::function<void(std::vector<int32_t> const& _return)> cob, const std::vector<int32_t> & thing) { |
| 419 | std::vector<int32_t> res; |
| 420 | _delegate->testList(res, thing); |
| 421 | cob(res); |
| 422 | } |
| 423 | |
| 424 | virtual void testEnum(std::tr1::function<void(Numberz::type const& _return)> cob, const Numberz::type thing) { |
| 425 | Numberz::type res = _delegate->testEnum(thing); |
| 426 | cob(res); |
| 427 | } |
| 428 | |
| 429 | virtual void testTypedef(std::tr1::function<void(UserId const& _return)> cob, const UserId thing) { |
| 430 | UserId res = _delegate->testTypedef(thing); |
| 431 | cob(res); |
| 432 | } |
| 433 | |
| 434 | virtual void testMapMap(std::tr1::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob, const int32_t hello) { |
| 435 | std::map<int32_t, std::map<int32_t, int32_t> > res; |
| 436 | _delegate->testMapMap(res, hello); |
| 437 | cob(res); |
| 438 | } |
| 439 | |
| 440 | virtual void testInsanity(std::tr1::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob, const Insanity& argument) { |
| 441 | std::map<UserId, std::map<Numberz::type, Insanity> > res; |
| 442 | _delegate->testInsanity(res, argument); |
| 443 | cob(res); |
| 444 | } |
| 445 | |
| 446 | virtual void testMulti(std::tr1::function<void(Xtruct const& _return)> cob, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> & arg3, const Numberz::type arg4, const UserId arg5) { |
| 447 | Xtruct res; |
| 448 | _delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5); |
| 449 | cob(res); |
| 450 | } |
| 451 | |
| 452 | virtual void testException(std::tr1::function<void()> cob, std::tr1::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, const std::string& arg) { |
| 453 | try { |
| 454 | _delegate->testException(arg); |
| 455 | } catch(const apache::thrift::TException& e) { |
| 456 | exn_cob(apache::thrift::TDelayedException::delayException(e)); |
| 457 | return; |
| 458 | } |
| 459 | cob(); |
| 460 | } |
| 461 | |
| 462 | virtual void testMultiException(std::tr1::function<void(Xtruct const& _return)> cob, std::tr1::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, const std::string& arg0, const std::string& arg1) { |
| 463 | Xtruct res; |
| 464 | try { |
| 465 | _delegate->testMultiException(res, arg0, arg1); |
| 466 | } catch(const apache::thrift::TException& e) { |
| 467 | exn_cob(apache::thrift::TDelayedException::delayException(e)); |
| 468 | return; |
| 469 | } |
| 470 | cob(res); |
| 471 | } |
| 472 | |
| 473 | virtual void testOneway(std::tr1::function<void()> cob, const int32_t secondsToSleep) { |
| 474 | _delegate->testOneway(secondsToSleep); |
| 475 | cob(); |
| 476 | } |
| 477 | |
| 478 | protected: |
| 479 | shared_ptr<TestHandler> _delegate; |
| 480 | }; |
| 481 | |
| 482 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 483 | int main(int argc, char **argv) { |
| 484 | int port = 9090; |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 485 | bool ssl = false; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 486 | string transport_type = "buffered"; |
| 487 | string protocol_type = "binary"; |
| 488 | string server_type = "simple"; |
| 489 | string domain_socket = ""; |
| 490 | size_t workers = 4; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 491 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 492 | |
| 493 | program_options::options_description desc("Allowed options"); |
| 494 | desc.add_options() |
| 495 | ("help,h", "produce help message") |
| 496 | ("port", program_options::value<int>(&port)->default_value(port), "Port number to listen") |
| 497 | ("domain-socket", program_options::value<string>(&domain_socket)->default_value(domain_socket), |
| 498 | "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)") |
| 499 | ("server-type", program_options::value<string>(&server_type)->default_value(server_type), |
| 500 | "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"") |
| 501 | ("transport", program_options::value<string>(&transport_type)->default_value(transport_type), |
| 502 | "transport: buffered, framed, http") |
| 503 | ("protocol", program_options::value<string>(&protocol_type)->default_value(protocol_type), |
| 504 | "protocol: binary, json") |
| 505 | ("ssl", "Encrypted Transport using SSL") |
| 506 | ("processor-events", "processor-events") |
| 507 | ("workers,n", program_options::value<size_t>(&workers)->default_value(workers), |
| 508 | "Number of thread pools workers. Only valid for thread-pool server type") |
| 509 | ; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 510 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 511 | program_options::variables_map vm; |
| 512 | program_options::store(program_options::parse_command_line(argc, argv, desc), vm); |
| 513 | program_options::notify(vm); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 514 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 515 | if (vm.count("help")) { |
| 516 | cout << desc << "\n"; |
| 517 | return 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 518 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 519 | |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 520 | try { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 521 | if (!server_type.empty()) { |
| 522 | if (server_type == "simple") { |
| 523 | } else if (server_type == "thread-pool") { |
| 524 | } else if (server_type == "threaded") { |
| 525 | } else if (server_type == "nonblocking") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 526 | } else { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 527 | throw invalid_argument("Unknown server type "+server_type); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | if (!protocol_type.empty()) { |
| 532 | if (protocol_type == "binary") { |
| 533 | } else if (protocol_type == "json") { |
| 534 | } else { |
| 535 | throw invalid_argument("Unknown protocol type "+protocol_type); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 539 | if (!transport_type.empty()) { |
| 540 | if (transport_type == "buffered") { |
| 541 | } else if (transport_type == "framed") { |
| 542 | } else if (transport_type == "http") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 543 | } else { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 544 | throw invalid_argument("Unknown transport type "+transport_type); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 545 | } |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 546 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 547 | |
Bryan Duxbury | 833ae49 | 2010-09-27 17:26:02 +0000 | [diff] [blame] | 548 | } catch (std::exception& e) { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 549 | cerr << e.what() << endl; |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 550 | cout << desc << "\n"; |
| 551 | return 1; |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 554 | if (vm.count("ssl")) { |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 555 | ssl = true; |
| 556 | signal(SIGPIPE, SIG_IGN); |
| 557 | } |
| 558 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 559 | // Dispatcher |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 560 | shared_ptr<TProtocolFactory> protocolFactory; |
| 561 | if (protocol_type == "json") { |
| 562 | shared_ptr<TProtocolFactory> jsonProtocolFactory(new TJSONProtocolFactory()); |
| 563 | protocolFactory = jsonProtocolFactory; |
| 564 | } else { |
| 565 | shared_ptr<TProtocolFactory> binaryProtocolFactory(new TBinaryProtocolFactoryT<TBufferBase>()); |
| 566 | protocolFactory = binaryProtocolFactory; |
| 567 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 568 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 569 | // Processor |
Mark Slee | d265552 | 2006-09-05 22:09:57 +0000 | [diff] [blame] | 570 | shared_ptr<TestHandler> testHandler(new TestHandler()); |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 571 | shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler)); |
| 572 | |
| 573 | if (vm.count("processor-events")) { |
David Reiss | d719206 | 2010-10-06 17:09:33 +0000 | [diff] [blame] | 574 | testProcessor->setEventHandler(shared_ptr<TProcessorEventHandler>( |
| 575 | new TestProcessorEventHandler())); |
| 576 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 577 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 578 | // Transport |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 579 | shared_ptr<TSSLSocketFactory> sslSocketFactory; |
| 580 | shared_ptr<TServerSocket> serverSocket; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 581 | |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 582 | if (ssl) { |
| 583 | sslSocketFactory = shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory()); |
| 584 | sslSocketFactory->loadCertificate("./server-certificate.pem"); |
| 585 | sslSocketFactory->loadPrivateKey("./server-private-key.pem"); |
| 586 | sslSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); |
| 587 | serverSocket = shared_ptr<TServerSocket>(new TSSLServerSocket(port, sslSocketFactory)); |
| 588 | } else { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 589 | if (domain_socket != "") { |
| 590 | unlink(domain_socket.c_str()); |
| 591 | serverSocket = shared_ptr<TServerSocket>(new TServerSocket(domain_socket)); |
| 592 | port = 0; |
| 593 | } |
| 594 | else { |
| 595 | serverSocket = shared_ptr<TServerSocket>(new TServerSocket(port)); |
| 596 | } |
Bryan Duxbury | cd9aea1 | 2011-02-22 18:12:06 +0000 | [diff] [blame] | 597 | } |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 598 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 599 | // Factory |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 600 | shared_ptr<TTransportFactory> transportFactory; |
| 601 | |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame^] | 602 | if (transport_type == "http" && server_type != "nonblocking") { |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 603 | shared_ptr<TTransportFactory> httpTransportFactory(new THttpServerTransportFactory()); |
| 604 | transportFactory = httpTransportFactory; |
| 605 | } else if (transport_type == "framed") { |
| 606 | shared_ptr<TTransportFactory> framedTransportFactory(new TFramedTransportFactory()); |
| 607 | transportFactory = framedTransportFactory; |
| 608 | } else { |
| 609 | shared_ptr<TTransportFactory> bufferedTransportFactory(new TBufferedTransportFactory()); |
| 610 | transportFactory = bufferedTransportFactory; |
| 611 | } |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 612 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 613 | // Server Info |
| 614 | cout << "Starting \"" << server_type << "\" server (" |
| 615 | << transport_type << "/" << protocol_type << ") listen on: " << domain_socket; |
| 616 | if (port != 0) { |
| 617 | cout << port; |
| 618 | } |
| 619 | cout << endl; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 620 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 621 | // Server |
| 622 | if (server_type == "simple") { |
Mark Slee | 018b699 | 2006-09-07 21:31:12 +0000 | [diff] [blame] | 623 | TSimpleServer simpleServer(testProcessor, |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 624 | serverSocket, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 625 | transportFactory, |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 626 | protocolFactory); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 627 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 628 | simpleServer.serve(); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 629 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 630 | } else if (server_type == "thread-pool") { |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 631 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 632 | shared_ptr<ThreadManager> threadManager = |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 633 | ThreadManager::newSimpleThreadManager(workers); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 634 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 635 | shared_ptr<PosixThreadFactory> threadFactory = |
| 636 | shared_ptr<PosixThreadFactory>(new PosixThreadFactory()); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 637 | |
| 638 | threadManager->threadFactory(threadFactory); |
| 639 | |
| 640 | threadManager->start(); |
| 641 | |
Mark Slee | 018b699 | 2006-09-07 21:31:12 +0000 | [diff] [blame] | 642 | TThreadPoolServer threadPoolServer(testProcessor, |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 643 | serverSocket, |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 644 | transportFactory, |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame] | 645 | protocolFactory, |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 646 | threadManager); |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 647 | |
Mark Slee | 794993d | 2006-09-20 01:56:10 +0000 | [diff] [blame] | 648 | threadPoolServer.serve(); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 649 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 650 | } else if (server_type == "threaded") { |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 651 | |
Mark Slee | 0c2dff3 | 2007-03-09 19:26:57 +0000 | [diff] [blame] | 652 | TThreadedServer threadedServer(testProcessor, |
| 653 | serverSocket, |
| 654 | transportFactory, |
| 655 | protocolFactory); |
| 656 | |
Mark Slee | 0c2dff3 | 2007-03-09 19:26:57 +0000 | [diff] [blame] | 657 | threadedServer.serve(); |
| 658 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 659 | } else if (server_type == "nonblocking") { |
Roger Meier | 7e056e7 | 2011-07-17 07:28:28 +0000 | [diff] [blame^] | 660 | if(transport_type == "http") { |
| 661 | shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler)); |
| 662 | shared_ptr<TAsyncProcessor> testProcessorAsync(new ThriftTestAsyncProcessor(testHandlerAsync)); |
| 663 | shared_ptr<TAsyncBufferProcessor> testBufferProcessor(new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory)); |
| 664 | |
| 665 | TEvhttpServer nonblockingServer(testBufferProcessor, port); |
| 666 | nonblockingServer.serve(); |
| 667 | } else { |
| 668 | TNonblockingServer nonblockingServer(testProcessor, port); |
| 669 | nonblockingServer.serve(); |
| 670 | } |
Marc Slemko | 6be374b | 2006-08-04 03:16:25 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Roger Meier | ca142b0 | 2011-06-07 17:59:07 +0000 | [diff] [blame] | 673 | cout << "done." << endl; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 674 | return 0; |
| 675 | } |