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