private com.facebook.swift.service.ResultCode logSwift(int port, List<com.facebook.swift.service.LogEntry> entries) throws Exception { try ( ThriftClientManager clientManager = new ThriftClientManager(); Scribe scribe = clientManager.createClient( new FramedClientConnector(fromParts("localhost", port)), Scribe.class).get() ) { return scribe.log(entries); } }
@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 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 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"))); } }
private com.facebook.swift.service.ResultCode logSwift(int port, List<com.facebook.swift.service.LogEntry> entries) throws Exception { NettyClientConfig nettyClientConfig = NettyClientConfig.newBuilder() .setSSLClientConfiguration( new SslClientConfiguration.Builder() .caFile(new File(getClass().getResource("/rsa.crt").getFile())) .build()).build(); NiftyClient niftyClient = new NiftyClient(nettyClientConfig); try ( ThriftClientManager clientManager = new ThriftClientManager(new ThriftCodecManager(), niftyClient, ImmutableSet.of()); Scribe scribe = clientManager.createClient( new FramedClientConnector(fromParts("localhost", port)), Scribe.class).get() ) { return scribe.log(entries); } }
@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"))); } }
assertEquals(scribe.log(MESSAGES), ResultCode.OK); assertEquals(injector.getInstance(SwiftScribe.class).getMessages(), newArrayList(MESSAGES)); assertEquals(eventHandlerContexts.size(), 1);
assertEquals(scribe.log(MESSAGES), ResultCode.OK); assertEquals(injector.getInstance(Key.get(SwiftScribe.class, TestAnnotation.class)).getMessages(), newArrayList(MESSAGES));
@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"))); } }
assertEquals(scribe.log(MESSAGES), ResultCode.OK); assertEquals(injector.getInstance(Key.get(SwiftScribe.class, TestAnnotation.class)).getMessages(), newArrayList(MESSAGES));