]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/test/org/apache/thrift/transport/TestTSSLTransportFactory.java
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / lib / java / test / org / apache / thrift / transport / TestTSSLTransportFactory.java
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 package org.apache.thrift.transport;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.thrift.TProcessor;
26 import org.apache.thrift.protocol.TBinaryProtocol;
27 import org.apache.thrift.protocol.TProtocolFactory;
28 import org.apache.thrift.server.ServerTestBase;
29 import org.apache.thrift.server.TServer;
30 import org.apache.thrift.server.TSimpleServer;
31 import org.apache.thrift.server.TServer.Args;
32
33 public class TestTSSLTransportFactory extends ServerTestBase {
34 private Thread serverThread;
35 private TServer server;
36
37 private static final List<TProtocolFactory> protocols = new ArrayList<TProtocolFactory>();
38 static {
39 // TODO: Only supported on TBinaryProtocol. Doesn't work for TCompactProtocol
40 protocols.add(new TBinaryProtocol.Factory());
41 }
42
43 @Override
44 public TTransport getClientTransport(TTransport underlyingTransport)
45 throws Exception {
46 return TSSLTransportFactory.getClientSocket(HOST, PORT);
47 }
48
49 protected TServerSocket getServerTransport() throws Exception {
50 return TSSLTransportFactory.getServerSocket(PORT);
51 }
52
53 @Override
54 public void startServer(final TProcessor processor, final TProtocolFactory protoFactory, final TTransportFactory factory)
55 throws Exception {
56 serverThread = new Thread() {
57 public void run() {
58 try {
59 TServerTransport serverTransport = getServerTransport();
60 final Args args = new Args(serverTransport).processor(processor);
61 server = new TSimpleServer(args);
62 server.serve();
63 } catch (Exception e) {
64 e.printStackTrace();
65 assert false;
66 }
67 }
68 };
69
70 serverThread.start();
71 Thread.sleep(SLEEP_DELAY);
72 }
73
74 @Override
75 public void stopServer() throws Exception {
76 server.stop();
77 serverThread.join();
78 }
79
80 @Override
81 public void open(TTransport transport) throws Exception {}
82
83 @Override
84 public List<TProtocolFactory> getProtocols() {
85 return protocols;
86 }
87
88 @Override
89 public void testTransportFactory() throws Exception {
90 // this test doesn't really apply to this suite, so let's skip it.
91 }
92 }