use of org.apache.thrift.transport.THttpClient in project airavata by apache.
the class AuroraSchedulerClientFactory method getTProtocol.
/**
* Gets the t protocol.
*
* @param connectionUrl the connection url
* @param connectionTimeout the connection timeout
* @return the t protocol
* @throws Exception the exception
*/
private static TProtocol getTProtocol(String connectionUrl, int connectionTimeout) throws Exception {
try {
THttpClient client = new THttpClient(connectionUrl);
client.setConnectTimeout(connectionTimeout);
TTransport transport = client;
transport.open();
TProtocol protocol = new TJSONProtocol(transport);
return protocol;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
throw ex;
}
}
use of org.apache.thrift.transport.THttpClient in project providence by morimekta.
the class ProvidenceServlet_ThriftClientTest method testThriftClient_oneway.
@Test
public void testThriftClient_oneway() throws TException, IOException, Failure {
ApacheHttpTransport transport = new ApacheHttpTransport();
THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
net.morimekta.test.thrift.service.TestService.Iface client = new net.morimekta.test.thrift.service.TestService.Client(protocol);
AtomicBoolean called = new AtomicBoolean();
doAnswer(i -> {
called.set(true);
return null;
}).when(impl).ping();
client.ping();
waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
verify(impl).ping();
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), isNull());
verifyNoMoreInteractions(impl, instrumentation);
}
use of org.apache.thrift.transport.THttpClient in project providence by morimekta.
the class ProvidenceServlet_ThriftClientTest method testThriftClient_failure.
@Test
public void testThriftClient_failure() throws TException, IOException, Failure {
ApacheHttpTransport transport = new ApacheHttpTransport();
THttpClient httpClient = new THttpClient(endpoint().toString(), transport.getHttpClient());
TBinaryProtocol protocol = new TBinaryProtocol(httpClient);
net.morimekta.test.thrift.service.TestService.Iface client = new net.morimekta.test.thrift.service.TestService.Client(protocol);
AtomicBoolean called = new AtomicBoolean();
doAnswer(i -> {
called.set(true);
throw new Failure("test");
}).when(impl).voidMethod(55);
try {
client.voidMethod(55);
} catch (net.morimekta.test.thrift.service.Failure e) {
assertEquals("test", e.getText());
}
waitAtMost(Duration.ONE_HUNDRED_MILLISECONDS).untilTrue(called);
verify(impl).voidMethod(55);
verify(instrumentation).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(impl, instrumentation);
}
use of org.apache.thrift.transport.THttpClient in project hbase by apache.
the class TestThriftSpnegoHttpFallbackServer method talkToThriftServer.
@Override
protected void talkToThriftServer(String url, int customHeaderSize) throws Exception {
// Close httpClient and THttpClient automatically on any failures
try (CloseableHttpClient httpClient = createHttpClient();
THttpClient tHttpClient = new THttpClient(url, httpClient)) {
tHttpClient.open();
if (customHeaderSize > 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < customHeaderSize; i++) {
sb.append("a");
}
tHttpClient.setCustomHeader(HttpHeaders.USER_AGENT, sb.toString());
}
TProtocol prot = new TBinaryProtocol(tHttpClient);
Hbase.Client client = new Hbase.Client(prot);
TestThriftServer.createTestTables(client);
TestThriftServer.checkTableList(client);
TestThriftServer.dropTestTables(client);
}
}
use of org.apache.thrift.transport.THttpClient in project hbase by apache.
the class TestThriftSpnegoHttpServer method talkToThriftServer.
@Override
protected void talkToThriftServer(String url, int customHeaderSize) throws Exception {
// Close httpClient and THttpClient automatically on any failures
try (CloseableHttpClient httpClient = createHttpClient();
THttpClient tHttpClient = new THttpClient(url, httpClient)) {
tHttpClient.open();
if (customHeaderSize > 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < customHeaderSize; i++) {
sb.append("a");
}
tHttpClient.setCustomHeader(HttpHeaders.USER_AGENT, sb.toString());
}
TProtocol prot = new TBinaryProtocol(tHttpClient);
Hbase.Client client = new Hbase.Client(prot);
List<ByteBuffer> bbs = client.getTableNames();
LOG.info("PRE-EXISTING {}", bbs.stream().map(b -> Bytes.toString(b.array())).collect(Collectors.joining(",")));
if (!bbs.isEmpty()) {
for (ByteBuffer bb : bbs) {
client.disableTable(bb);
client.deleteTable(bb);
}
}
TestThriftServer.createTestTables(client);
TestThriftServer.checkTableList(client);
TestThriftServer.dropTestTables(client);
}
}
Aggregations