@Test public void testHighLoadEventSendingToServer() throws IOException, InterruptedException { StreamDefinition streamDefinition = new StreamDefinition() .id("analyticsStats") .attribute("meta_ipAdd", Attribute.Type.STRING) .attribute("meta_index", Attribute.Type.LONG) .attribute("meta_timestamp", Attribute.Type.LONG) .attribute("meta_nanoTime", Attribute.Type.LONG) .attribute("userID", Attribute.Type.STRING) .attribute("searchTerms", Attribute.Type.STRING); TestStreamCallback streamCallback = new TestStreamCallback(); TCPEventServer TCPEventServer = new TCPEventServer(new TCPEventServerConfig("0.0.0.0", 7612), streamCallback, null); TCPEventServer.addStreamDefinition(streamDefinition); TCPEventServer.start(); Thread.sleep(1000); for (int i = 0; i < TOTAL_CLIENTS; i++) { threadPool.submit( new ClientThread( streamDefinition, new AnalyticStatDataProvider(), EVENTS_PER_CLIENT, false, 0)); } while (streamCallback.getEventCount() < TOTAL_CLIENTS * EVENTS_PER_CLIENT) { Thread.sleep(5000); } Assert.assertEquals(TOTAL_CLIENTS * EVENTS_PER_CLIENT, streamCallback.getEventCount()); log.info("Shutting down server..."); TCPEventServer.shutdown(); }
@Test public void testAddressAlreadyExisted() throws Exception { StreamDefinition streamDefinition = new StreamDefinition() .id("TestStream") .attribute("att1", Attribute.Type.INT) .attribute("att2", Attribute.Type.FLOAT) .attribute("att3", Attribute.Type.STRING) .attribute("att4", Attribute.Type.INT); TestStreamCallback streamCallback = new TestStreamCallback(); TCPEventServer tcpEventServer = new TCPEventServer(new TCPEventServerConfig("0.0.0.0", 7612), streamCallback, null); TCPEventServer tcpEventServer1 = new TCPEventServer(new TCPEventServerConfig("0.0.0.0", 7612), streamCallback, null); boolean errorOccurred = false; try { tcpEventServer.addStreamDefinition(streamDefinition); tcpEventServer.start(); Thread.sleep(1000); try { tcpEventServer1.addStreamDefinition(streamDefinition); tcpEventServer1.start(); Thread.sleep(1000); } catch (BindException e) { log.error("Address already exist", e); errorOccurred = true; } catch (IOException e) { throw new Exception(e); } } finally { log.info("Shutting down server 1..."); tcpEventServer.shutdown(); log.info("Shutting down server 2..."); tcpEventServer1.shutdown(); Assert.assertEquals(true, errorOccurred); } }
@Test public void testEventSendingToServer() throws InterruptedException, IOException { StreamDefinition streamDefinition = new StreamDefinition() .id("TestStream") .attribute("att1", Attribute.Type.INT) .attribute("att2", Attribute.Type.FLOAT) .attribute("att3", Attribute.Type.STRING) .attribute("att4", Attribute.Type.INT); TestStreamCallback streamCallback = new TestStreamCallback(); TCPEventServer TCPEventServer = new TCPEventServer(new TCPEventServerConfig("0.0.0.0", 7612), streamCallback, null); TCPEventServer.addStreamDefinition(streamDefinition); TCPEventServer.start(); Thread.sleep(1000); threadPool.submit(new ClientThread(streamDefinition, new SimpleDataProvider(), 100, false, 0)); Thread.sleep(5000); Assert.assertEquals(100, streamCallback.getEventCount()); log.info("Shutting down server..."); TCPEventServer.shutdown(); }