protected final TTransport newTransport(String scheme, String path) throws TTransportException { return newTransport(scheme, path, HttpHeaders.EMPTY_HEADERS); }
protected abstract TTransport newTransport(String uri, HttpHeaders headers) throws TTransportException;
@Test public void testOnewayAsyncInvocation() throws Exception { recordMessageLogs = true; try (TTransport transport = newTransport("http", "/hello_oneway_async")) { final OnewayHelloService.Client client = new OnewayHelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); // Success client.hello("success"); verifyOneWayInvocation(OnewayHelloService.AsyncIface.class, "success"); } try (TTransport transport = newTransport("http", "/hello_oneway_async")) { final OnewayHelloService.Client client = new OnewayHelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); // Failure client.hello("failure"); verifyOneWayInvocation(OnewayHelloService.AsyncIface.class, "failure"); } }
@Test public void testOnewaySyncInvocation() throws Exception { recordMessageLogs = true; try (TTransport transport = newTransport("http", "/hello_oneway_sync")) { final OnewayHelloService.Client client = new OnewayHelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); // Success client.hello("success"); verifyOneWayInvocation(OnewayHelloService.Iface.class, "success"); } try (TTransport transport = newTransport("http", "/hello_oneway_sync")) { final OnewayHelloService.Client client = new OnewayHelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); // Failure client.hello("failure"); verifyOneWayInvocation(OnewayHelloService.Iface.class, "failure"); } }
@Test public void testInheritedThriftService() throws Exception { try (TTransport transport = newTransport("http", "/hellochild")) { final HelloService.Client client = new HelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); assertThat(client.hello("Trustin")).isEqualTo("Goodbye, Trustin!"); } }
@Test public void testHttpsInvocation() throws Exception { try (TTransport transport = newTransport("https", "/hello")) { final HelloService.Client client = new HelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); assertThat(client.hello("Trustin")).isEqualTo("Hello, Trustin!"); } }
@Test public void testLargeHttpsInvocation() throws Exception { try (TTransport transport = newTransport("https", "/large")) { final HelloService.Client client = new HelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); assertThat(client.hello("Trustin")).isEqualTo(LARGER_THAN_TLS); } }
@Test public void testHttpInvocation() throws Exception { try (TTransport transport = newTransport("http", "/hello")) { final HelloService.Client client = new HelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); assertThat(client.hello("Trustin")).isEqualTo("Hello, Trustin!"); } }
@Test public void testAcceptHeaderWithCommaSeparatedMediaTypes() throws Exception { try (TTransport transport = newTransport("http", "/hello", HttpHeaders.of(HttpHeaderNames.ACCEPT, "text/plain, */*"))) { final HelloService.Client client = new HelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); assertThat(client.hello("Trustin")).isEqualTo("Hello, Trustin!"); } }
@Test public void testAcceptHeaderWithUnsupportedMediaTypes() throws Exception { // Server should choose TBINARY because it does not support the media type // with the highest preference (text/plain). try (TTransport transport = newTransport( "http", "/hello", HttpHeaders.of(HttpHeaderNames.ACCEPT, "application/x-thrift; protocol=TBINARY; q=0.2, text/plain"))) { final HelloService.Client client = new HelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); assertThat(client.hello("Trustin")).isEqualTo("Hello, Trustin!"); } }
@Test public void testAcceptHeaderWithQValues() throws Exception { // Server should choose TBINARY because it has higher q-value (0.5) than that of TTEXT (0.2) try (TTransport transport = newTransport( "http", "/hello", HttpHeaders.of(HttpHeaderNames.ACCEPT, "application/x-thrift; protocol=TTEXT; q=0.2, " + "application/x-thrift; protocol=TBINARY; q=0.5"))) { final HelloService.Client client = new HelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); assertThat(client.hello("Trustin")).isEqualTo("Hello, Trustin!"); } }
@Test public void testAcceptHeaderWithDefaultQValues() throws Exception { // Server should choose TBINARY because it has higher q-value (default 1.0) than that of TTEXT (0.2) try (TTransport transport = newTransport( "http", "/hello", HttpHeaders.of(HttpHeaderNames.ACCEPT, "application/x-thrift; protocol=TTEXT; q=0.2, " + "application/x-thrift; protocol=TBINARY"))) { final HelloService.Client client = new HelloService.Client.Factory().getClient( ThriftProtocolFactories.BINARY.getProtocol(transport)); assertThat(client.hello("Trustin")).isEqualTo("Hello, Trustin!"); } }
@Test(timeout = 10000) public void testMessageLogsForException() throws Exception { try (TTransport transport = newTransport("http", "/exception")) { final HelloService.Client client = new HelloService.Client.Factory().getClient(
@Test(timeout = 10000) public void testMessageLogsForCall() throws Exception { try (TTransport transport = newTransport("http", "/hello")) { final HelloService.Client client = new HelloService.Client.Factory().getClient(