@Override public Transceiver createTransceiver() throws Exception { return new SocketTransceiver(new InetSocketAddress(server.getPort())); }
@Override public Transceiver createTransceiver() throws Exception{ return new HttpTransceiver(new URL("http://127.0.0.1:"+server.getPort()+"/")); }
@Override public Transceiver createTransceiver() throws Exception{ return new DatagramTransceiver(new InetSocketAddress("localhost", server.getPort())); }
@Override public Transceiver createTransceiver() throws Exception{ return new HttpTransceiver(new URL("https://localhost:"+server.getPort()+"/")); }
@Override public Transceiver createTransceiver() throws Exception{ return new NettyTransceiver(new InetSocketAddress(server.getPort()), 2000L); }
public Transceiver createTransceiver() throws Exception{ return new SocketTransceiver(new InetSocketAddress(server.getPort())); }
@Test public void testBadRequest() throws IOException { int port = server.getPort(); String msg = "GET /status HTTP/1.1\n\n"; InetSocketAddress sockAddr = new InetSocketAddress("127.0.0.1", port); Socket sock = new Socket(); sock.connect(sockAddr); OutputStream out = sock.getOutputStream(); out.write(msg.getBytes(Charset.forName("UTF-8"))); out.flush(); byte[] buf = new byte[2048]; int bytesRead = sock.getInputStream().read(buf); Assert.assertTrue("Connection should have been closed", bytesRead == -1); }
@Test public void testRpcProtocol() throws Exception { // run the actual test ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); PrintStream p2 = new PrintStream(baos2, true, "UTF-8"); RpcProtocolTool testObject = new RpcProtocolTool(); testObject.run(null, p2, System.err, Arrays.asList(uriScheme + "://127.0.0.1:" + receive.server.getPort() + "/")); p2.flush(); assertEquals("Expected the simple.avpr protocol to be echoed to standout", simpleProtocol, Protocol.parse(baos2.toString("UTF-8"))); } }
@BeforeClass public static void initializeConnections() throws Exception { // start server Responder responder = new SpecificResponder(Simple.class, simpleService); server = new NettyServer(responder, new InetSocketAddress(0)); server.start(); int serverPort = server.getPort(); System.out.println("server port : " + serverPort); transceiver = new NettyTransceiver(new InetSocketAddress( serverPort), TestNettyServer.CONNECT_TIMEOUT_MILLIS); simpleClient = SpecificRequestor.getClient(Simple.Callback.class, transceiver); }
@Test(expected = FlumeException.class) public void testCreatingLbClientSingleHost() { Server server1 = null; RpcClient c = null; try { server1 = RpcTestUtils.startServer(new OKAvroHandler()); Properties p = new Properties(); p.put("host1", "127.0.0.1:" + server1.getPort()); p.put("hosts", "host1"); p.put("client.type", "default_loadbalance"); RpcClientFactory.getInstance(p); } finally { if (server1 != null) server1.close(); if (c != null) c.close(); } }
@Before public void testStartServer() throws Exception { if (server != null) return; server = new SocketServer(new ReflectResponder(Simple.class, new TestImpl()), new InetSocketAddress(0)); server.start(); client = new SocketTransceiver(new InetSocketAddress(server.getPort())); proxy = ReflectRequestor.getClient(Simple.class, client); }
@BeforeClass public static void initializeConnections()throws Exception { // start server System.out.println("starting server..."); mailService = new MailImpl(); Responder responder = new SpecificResponder(Mail.class, mailService); server = initializeServer(responder); server.start(); int serverPort = server.getPort(); System.out.println("server port : " + serverPort); transceiver = initializeTransceiver(serverPort); proxy = SpecificRequestor.getClient(Mail.class, transceiver); }
@Test public void testThreeParamBatchAppend() throws FlumeException, EventDeliveryException { int batchSize = 7; RpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcClientFactory.getDefaultInstance(localhost, server.getPort(), batchSize); List<Event> events = new ArrayList<Event>(); for (int i = 0; i < batchSize; i++) { events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8"))); } client.appendBatch(events); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }
@Test public void testTwoParamBatchAppendOverflow() throws FlumeException, EventDeliveryException { RpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcClientFactory.getDefaultInstance(localhost, server.getPort()); int batchSize = client.getBatchSize(); int moreThanBatch = batchSize + 1; List<Event> events = new ArrayList<Event>(); for (int i = 0; i < moreThanBatch; i++) { events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8"))); } client.appendBatch(events); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }
@Before public void startServer() throws Exception { if (server != null) return; server = new HttpServer(new SpecificResponder(BulkData.class, new BulkDataImpl()), 0); server.start(); client = new HttpTransceiver(new URL("http://127.0.0.1:"+server.getPort()+"/")); proxy = SpecificRequestor.getClient(BulkData.class, client); }
@Test public void testTwoParamSimpleAppend() throws FlumeException, EventDeliveryException { RpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcClientFactory.getDefaultInstance(localhost, server.getPort()); client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8"))); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }
@Test public void testTwoParamDeprecatedAppend() throws FlumeException, EventDeliveryException { RpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcClientFactory.getInstance(localhost, server.getPort()); client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8"))); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }
@Test(expected=SaslException.class) public void testAnonymousClient() throws Exception { Server s = new SaslSocketServer (new TestResponder(), new InetSocketAddress(0), DIGEST_MD5_MECHANISM, SERVICE, HOST, DIGEST_MD5_PROPS, new TestSaslCallbackHandler()); s.start(); Transceiver c = new SaslSocketTransceiver(new InetSocketAddress(s.getPort())); GenericRequestor requestor = new GenericRequestor(PROTOCOL, c); GenericRecord params = new GenericData.Record(PROTOCOL.getMessages().get("hello").getRequest()); params.put("greeting", "bob"); Utf8 response = (Utf8)requestor.request("hello", params); assertEquals(new Utf8("goodbye"), response); s.close(); c.close(); }
@Before @Override public void testStartServer() throws Exception { if (server != null) return; ReflectResponder rresp = new ReflectResponder(Simple.class, new TestImpl()); rresp.addRPCPlugin(new RPCMetaTestPlugin("key1")); rresp.addRPCPlugin(new RPCMetaTestPlugin("key2")); server = new SocketServer(rresp, new InetSocketAddress(0)); server.start(); client = new SocketTransceiver(new InetSocketAddress(server.getPort())); ReflectRequestor requestor = new ReflectRequestor(Simple.class, client); requestor.addRPCPlugin(new RPCMetaTestPlugin("key1")); requestor.addRPCPlugin(new RPCMetaTestPlugin("key2")); proxy = ReflectRequestor.getClient(Simple.class, (ReflectRequestor)requestor); }
@Test public void testThreeParamDeprecatedAppend() throws FlumeException, EventDeliveryException { RpcClient client = null; Server server = RpcTestUtils.startServer(new OKAvroHandler()); try { client = RpcClientFactory.getInstance(localhost, server.getPort(), 3); Assert.assertEquals("Batch size was specified", 3, client.getBatchSize()); client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8"))); } finally { RpcTestUtils.stopServer(server); if (client != null) client.close(); } }