@Override public void run() { try { while (getFlattenedQueries(new ArrayList<>(dryRunData)).size() != threadCount * queryCount) { mDispatcher.setDispatchInterval(new Random().nextInt(20 - -1) + -1); } } catch (Exception e) {e.printStackTrace();} } }).start();
@Override public void run() { try { while (getFlattenedQueries(new ArrayList<>(dryRunData)).size() != threadCount * queryCount) { mDispatcher.setDispatchInterval(new Random().nextInt(20 - -1) + -1); } } catch (Exception e) {e.printStackTrace();} } }).start();
@Test public void testMultiThreadDispatch() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(20); final int threadCount = 20; final int queryCount = 100; final List<String> createdEvents = Collections.synchronizedList(new ArrayList<String>()); launchTestThreads(mApiUrl, mDispatcher, threadCount, queryCount, createdEvents); checkForMIAs(threadCount * queryCount, createdEvents, dryRunData); }
@Test public void testMultiThreadDispatch() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(20); final int threadCount = 20; final int queryCount = 100; final List<String> createdEvents = Collections.synchronizedList(new ArrayList<String>()); launchTestThreads(mApiUrl, mDispatcher, threadCount, queryCount, createdEvents); checkForMIAs(threadCount * queryCount, createdEvents, dryRunData); }
@Test public void testDispatchInterval() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(500); assertThat(dryRunData.isEmpty(), is(true)); mDispatcher.submit(getTestEvent()); await().atLeast(500, TimeUnit.MILLISECONDS).until(() -> dryRunData.size() == 1); }
@Test public void testDispatchInterval() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(500); assertThat(dryRunData.isEmpty(), is(true)); mDispatcher.submit(getTestEvent()); await().atLeast(500, TimeUnit.MILLISECONDS).until(() -> dryRunData.size() == 1); }
@Test public void testForceDispatch() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(-1L); final int threadCount = 10; final int queryCount = 10; final List<String> createdEvents = Collections.synchronizedList(new ArrayList<String>()); launchTestThreads(mApiUrl, mDispatcher, threadCount, queryCount, createdEvents); TestHelper.sleep(500); assertEquals(threadCount * queryCount, createdEvents.size()); assertEquals(0, dryRunData.size()); mDispatcher.forceDispatch(); checkForMIAs(threadCount * queryCount, createdEvents, dryRunData); }
@Test public void testForceDispatch() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(-1L); final int threadCount = 10; final int queryCount = 10; final List<String> createdEvents = Collections.synchronizedList(new ArrayList<String>()); launchTestThreads(mApiUrl, mDispatcher, threadCount, queryCount, createdEvents); TestHelper.sleep(500); assertEquals(threadCount * queryCount, createdEvents.size()); assertEquals(0, dryRunData.size()); mDispatcher.forceDispatch(); checkForMIAs(threadCount * queryCount, createdEvents, dryRunData); }
@Test public void testBatchDispatch() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(1500); final int threadCount = 5; final int queryCount = 5; final List<String> createdEvents = Collections.synchronizedList(new ArrayList<String>()); launchTestThreads(mApiUrl, mDispatcher, threadCount, queryCount, createdEvents); await().atMost(2, TimeUnit.SECONDS).until(() -> createdEvents.size(), is(threadCount * queryCount)); assertEquals(0, dryRunData.size()); await().atMost(2, TimeUnit.SECONDS).until(() -> createdEvents.size(), is(threadCount * queryCount)); checkForMIAs(threadCount * queryCount, createdEvents, dryRunData); }
@Test public void testBatchDispatch() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(1500); final int threadCount = 5; final int queryCount = 5; final List<String> createdEvents = Collections.synchronizedList(new ArrayList<String>()); launchTestThreads(mApiUrl, mDispatcher, threadCount, queryCount, createdEvents); await().atMost(2, TimeUnit.SECONDS).until(() -> createdEvents.size(), is(threadCount * queryCount)); assertEquals(0, dryRunData.size()); await().atMost(2, TimeUnit.SECONDS).until(() -> createdEvents.size(), is(threadCount * queryCount)); checkForMIAs(threadCount * queryCount, createdEvents, dryRunData); }
@Test public void testDispatchRetryWithBackoff() throws Exception { AtomicInteger cnt = new AtomicInteger(0); when(mPacketSender.send(any())).then(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { return cnt.incrementAndGet() > 5; } }); mDispatcher.setDispatchInterval(100); mDispatcher.submit(getTestEvent()); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 1); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 2); await().atMost(1900, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 5); mDispatcher.submit(getTestEvent()); await().atMost(150, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 5); }
@Test public void testDispatchRetryWithBackoff() throws Exception { AtomicInteger cnt = new AtomicInteger(0); when(mPacketSender.send(any())).then(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { return cnt.incrementAndGet() > 5; } }); mDispatcher.setDispatchInterval(100); mDispatcher.submit(getTestEvent()); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 1); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 2); await().atMost(1900, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 5); mDispatcher.submit(getTestEvent()); await().atMost(150, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 5); }
@Test public void testForceDispatchTwice() throws Exception { mDispatcher.setDispatchInterval(-1); mDispatcher.setConnectionTimeOut(20); mDispatcher.submit(getTestEvent()); assertTrue(mDispatcher.forceDispatch()); assertFalse(mDispatcher.forceDispatch()); }
@Test public void testForceDispatchTwice() throws Exception { mDispatcher.setDispatchInterval(-1); mDispatcher.setConnectionTimeOut(20); mDispatcher.submit(getTestEvent()); assertTrue(mDispatcher.forceDispatch()); assertFalse(mDispatcher.forceDispatch()); }