@Override public com.facebook.swift.service.LogEntry apply(@Nullable LogEntry input) { return new com.facebook.swift.service.LogEntry(input.category, input.message); } });
@Override public com.facebook.swift.service.LogEntry apply(@Nullable LogEntry input) { return new com.facebook.swift.service.LogEntry(input.category, input.message); } });
@Override public void onSuccess(AsyncScribe client) { try { ListenableFuture<ResultCode> methodFuture = client.log(Lists.newArrayList(new LogEntry("testCategory", "testMessage"))); Futures.addCallback(methodFuture, new FutureCallback<ResultCode>() { @Override public void onSuccess(ResultCode result) { resultHolder[0] = result; latch.countDown(); } @Override public void onFailure(Throwable t) { latch.countDown(); } }); } catch (TException e) { latch.countDown(); } }
@Test public void testCompactProtocolClient() throws Exception { // Server and client use compact protocol try (ScopedServer server = new ScopedServer(new TCompactProtocol.Factory()); ThriftClientManager manager = new ThriftClientManager(); Scribe client = createScribeClient(manager, server, new TCompactProtocol.Factory())) { client.log(ImmutableList.of(new LogEntry("testCategory1", "testMessage1"), new LogEntry("testCategory2", "testMessage2"))); } }
@Test public void testUnframedSyncMethod() throws Exception { TestServerInfo info = startServer(); ThriftClientManager clientManager = new ThriftClientManager(); try (Scribe client = createUnframedClient(clientManager, Scribe.class, info.port).get()) { ResultCode result = client.log(Lists.newArrayList( new LogEntry("testCategory", "testMessage"))); assertEquals(result, ResultCode.OK); } stopServer(info); }
@Test public void testBinaryProtocolClient() throws Exception { // Server and client use binary protocol try (ScopedServer server = new ScopedServer(new TBinaryProtocol.Factory()); ThriftClientManager manager = new ThriftClientManager(); Scribe client = createScribeClient(manager, server, new TBinaryProtocol.Factory())) { client.log(ImmutableList.of(new LogEntry("testCategory1", "testMessage1"), new LogEntry("testCategory2", "testMessage2"))); } }
@Override public void onSuccess(AsyncScribe client) { try { ListenableFuture<ResultCode> methodFuture = client.log(Lists.newArrayList(new LogEntry("testCategory", "testMessage"))); // Connected a client, and made an async call against it, but the call shouldn't // be completed right away. Check that it isn't. assertEquals(server.getLogEntries().size(), 0); Futures.addCallback(methodFuture, new FutureCallback<ResultCode>() { @Override public void onSuccess(ResultCode result) { latch.countDown(); } @Override public void onFailure(Throwable t) { latch.countDown(); } }); } catch (Throwable th) { onFailure(th); } }
@Test public void testHttpClient() throws Exception { try (HttpScribeServer server = new HttpScribeServer()) { server.start(); // Server was just started, it shouldn't have recorded any messages yet assertEquals(server.getLogEntries().size(), 0); int serverPort = server.getLocalPort(); try (Scribe client = createHttpClient(Scribe.class, serverPort).get()) { client.log(Lists.newArrayList(new LogEntry("testCategory", "testMessage"))); } // Blocking call completed, check that it was successful in logging a message. assertEquals(server.getLogEntries().size(), 1); } }
@Test(expectedExceptions = { TTransportException.class }) public void testUnmatchedProtocols() throws Exception { // Setup a server to accept compact protocol, and try to send it a message with a binary // protocol client. Server should disconnect the client while client is trying to read the // response, so we should get a TTransportException try (ScopedServer server = new ScopedServer(new TCompactProtocol.Factory()); ThriftClientManager manager = new ThriftClientManager(); Scribe client = createScribeClient(manager, server, new TBinaryProtocol.Factory())) { client.log(ImmutableList.of(new LogEntry("testCategory1", "testMessage1"), new LogEntry("testCategory2", "testMessage2"))); } }
client.log(Lists.newArrayList(new LogEntry("testCategory", "testMessage"))); Futures.addCallback(methodFuture, new FutureCallback<ResultCode>()
ListenableFuture<ResultCode> methodFuture = client.log(Lists.newArrayList(new LogEntry("testCategory", "testMessage")));