blob: d0548b71439b3a27aeb0276acce2744a79c8d68e [file] [log] [blame]
Jake Farrellb95b0ff2012-03-22 21:49:10 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/**
21 * Various helpers used by more than a single test.
22 */
23module test_utils;
24
25import std.parallelism : TaskPool;
26import thrift.protocol.base;
27import thrift.protocol.processor;
28import thrift.server.base;
29import thrift.server.nonblocking;
30import thrift.server.simple;
31import thrift.server.taskpool;
32import thrift.server.threaded;
33import thrift.server.transport.socket;
34import thrift.transport.base;
35import thrift.transport.buffered;
36import thrift.transport.framed;
37import thrift.transport.http;
Kengo Sekif0c761e2020-01-09 18:48:29 +090038import thrift.transport.zlib;
Jake Farrellb95b0ff2012-03-22 21:49:10 +000039
40// This is a likely victim of @@BUG4744@@ when used with command argument
41// parsing.
42enum ServerType {
43 simple,
44 nonblocking,
45 pooledNonblocking,
46 taskpool,
47 threaded
48}
49
50TServer createServer(ServerType type, size_t taskPoolSize, size_t numIOThreads,
51 TProcessor processor, TServerSocket serverTransport,
52 TTransportFactory transportFactory, TProtocolFactory protocolFactory)
53{
54 final switch (type) {
55 case ServerType.simple:
56 return new TSimpleServer(processor, serverTransport,
57 transportFactory, protocolFactory);
58 case ServerType.nonblocking:
59 auto nb = new TNonblockingServer(processor, serverTransport.port,
60 transportFactory, protocolFactory);
61 nb.numIOThreads = numIOThreads;
62 return nb;
63 case ServerType.pooledNonblocking:
64 auto nb = new TNonblockingServer(processor, serverTransport.port,
65 transportFactory, protocolFactory, new TaskPool(taskPoolSize));
66 nb.numIOThreads = numIOThreads;
67 return nb;
68 case ServerType.taskpool:
69 auto tps = new TTaskPoolServer(processor, serverTransport,
70 transportFactory, protocolFactory);
71 tps.taskPool = new TaskPool(taskPoolSize);
72 return tps;
73 case ServerType.threaded:
74 return new TThreadedServer(processor, serverTransport,
75 transportFactory, protocolFactory);
76 }
77}
78
79enum TransportType {
80 buffered,
81 framed,
82 http,
Kengo Sekif0c761e2020-01-09 18:48:29 +090083 zlib,
Jake Farrellb95b0ff2012-03-22 21:49:10 +000084 raw
85}
86
87TTransportFactory createTransportFactory(TransportType type) {
88 final switch (type) {
89 case TransportType.buffered:
90 return new TBufferedTransportFactory;
91 case TransportType.framed:
92 return new TFramedTransportFactory;
93 case TransportType.http:
94 return new TServerHttpTransportFactory;
Kengo Sekif0c761e2020-01-09 18:48:29 +090095 case TransportType.zlib:
96 return new TZlibTransportFactory;
Jake Farrellb95b0ff2012-03-22 21:49:10 +000097 case TransportType.raw:
98 return new TTransportFactory;
99 }
100}