@Test public void testWhenFailureDuringInit() throws InterruptedException { when(tokenStore.fetchSegments(anyString())) .thenThrow(new RuntimeException("Faking issue during fetchSegments")) .thenReturn(new int[]{}) .thenReturn(new int[]{0}); doThrow(new RuntimeException("Faking issue during initializeTokenSegments")) // and on further calls .doNothing() .when(tokenStore).initializeTokenSegments(anyString(), anyInt()); testSubject.start(); Thread.sleep(2500); assertEquals(1, testSubject.activeProcessorThreads()); }
@Test public void testResetRejectedIfNotAllTokensCanBeClaimed() { tokenStore.initializeTokenSegments("test", 4); when(tokenStore.fetchToken("test", 3)).thenThrow(new UnableToClaimTokenException("Mock")); try { testSubject.resetTokens(); fail("Expected exception"); } catch (UnableToClaimTokenException e) { // expected } verify(tokenStore, never()).storeToken(isNull(), anyString(), anyInt()); }
() -> { TrackingToken initialToken = initialTrackingTokenBuilder.apply(messageSource); tokenStore.initializeTokenSegments(processorName, segmentsSize, initialToken); return tokenStore.fetchSegments(processorName); });
() -> { TrackingToken initialToken = initialTrackingTokenBuilder.apply(messageSource); tokenStore.initializeTokenSegments(processorName, segmentsSize, initialToken); return tokenStore.fetchSegments(processorName); });
() -> { TrackingToken initialToken = initialTrackingTokenBuilder.apply(messageSource); tokenStore.initializeTokenSegments(processorName, segmentsSize, initialToken); return tokenStore.fetchSegments(processorName); });