CoreService.this.addDefaultData(systemSensorData);
@Test public void noAddOnShutdown() throws InterruptedException, StorageException { when(disruptorStrategy.getDataBufferSize()).thenReturn(8); coreService.start(); coreService.stop(); coreService.addDefaultData(data); // need to sleep a bit so handler is notified Thread.sleep(100); verifyNoMoreInteractions(defaultDataHandler); }
@Test public void happyPath() throws InterruptedException, StorageException { when(disruptorStrategy.getDataBufferSize()).thenReturn(8); coreService.start(); coreService.addDefaultData(data); // need to sleep a bit so handler is notified Thread.sleep(100); ArgumentCaptor<DefaultDataWrapper> captor = ArgumentCaptor.forClass(DefaultDataWrapper.class); verify(defaultDataHandler).onEvent(captor.capture(), anyLong(), eq(true)); assertThat(captor.getValue().getDefaultData(), is(data)); }
@Test public void capacityReached() throws InterruptedException, StorageException { when(disruptorStrategy.getDataBufferSize()).thenReturn(2); // slow down the wrapper so we get capacity error doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Thread.sleep(1); return null; } }).when(defaultDataHandler).onEvent(Mockito.<DefaultDataWrapper> any(), anyLong(), anyBoolean()); coreService.start(); coreService.addDefaultData(data); coreService.addDefaultData(data); coreService.addDefaultData(data); coreService.addDefaultData(data); // we should report 2 times verify(statsLogger, times(2)).dataDropped(1); }