@Override public long addError(long processingTimeInMs) { addProcessingTime(processingTimeInMs); inProgress.decrementAndGet(); return error.incrementAndGet(); }
@Override public void run() { underTest.addError(1); } }
@Override public void run() { underTest.addInProgress(); } }
@Test public void test_concurrent_modifications_in_any_order() throws InterruptedException { for (Runnable runnable : buildShuffleCallsToUnderTest()) { executorService.submit(runnable); } executorService.awaitTermination(1, TimeUnit.SECONDS); assertThat(underTest.getInProgressCount()).isEqualTo(1); assertThat(underTest.getErrorCount()).isEqualTo(17); assertThat(underTest.getSuccessCount()).isEqualTo(80); assertThat(underTest.getProcessingTime()).isEqualTo(177); }
@Test public void addInProgress_any_number_of_call_change_by_1_per_call() { int calls = new Random().nextInt(SOME_RANDOM_MAX); for (int i = 0; i < calls; i++) { getUnderTest().addInProgress(); } assertThat(getUnderTest().getInProgressCount()).isEqualTo(calls); assertThat(getUnderTest().getProcessingTime()).isEqualTo(0); }
@Override public void run() { underTest.addSuccess(2); } }
@Test public void workers_pause_is_false_by_default() { assertThat(getUnderTest().areWorkersPaused()).isFalse(); } }
@Test public void count_Pending_from_database() { when(getDbClient().ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(42); assertThat(underTest.getPendingCount()).isEqualTo(42); } }
@Test public void addSuccess_any_number_of_call_change_by_1_per_call() { int calls = new Random().nextInt(SOME_RANDOM_MAX); for (int i = 0; i < calls; i++) { getUnderTest().addSuccess(1); } assertThat(getUnderTest().getSuccessCount()).isEqualTo(calls); assertThat(getUnderTest().getInProgressCount()).isEqualTo(-calls); assertThat(getUnderTest().getProcessingTime()).isEqualTo(calls); }
@Test public void addSuccess_throws_IAE_if_time_is_less_than_0() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Processing time can not be < 0"); getUnderTest().addSuccess(-1); }
@Test public void workers_pause_is_loaded_from_db() { when(dbClient.internalPropertiesDao().selectByKey(any(), eq(InternalProperties.COMPUTE_ENGINE_PAUSE))).thenReturn(Optional.of("true")); assertThat(getUnderTest().areWorkersPaused()).isTrue(); }
@Test public void addSuccess_increases_Error_and_decreases_InProgress_by_1_without_check_on_InProgress() { getUnderTest().addSuccess(SOME_PROCESSING_TIME); assertThat(getUnderTest().getInProgressCount()).isEqualTo(-1); assertThat(getUnderTest().getErrorCount()).isEqualTo(0); assertThat(getUnderTest().getSuccessCount()).isEqualTo(1); assertThat(getUnderTest().getProcessingTime()).isEqualTo(SOME_PROCESSING_TIME); }
@Override public long addSuccess(long processingTimeInMs) { addProcessingTime(processingTimeInMs); inProgress.decrementAndGet(); return success.incrementAndGet(); }
@Test public void addError_throws_IAE_if_time_is_less_than_0() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Processing time can not be < 0"); getUnderTest().addError(-1); }
@Test public void addError_increases_Error_and_decreases_InProgress_by_1_without_check_on_InProgress() { getUnderTest().addError(SOME_PROCESSING_TIME); assertThat(getUnderTest().getInProgressCount()).isEqualTo(-1); assertThat(getUnderTest().getErrorCount()).isEqualTo(1); assertThat(getUnderTest().getSuccessCount()).isEqualTo(0); assertThat(getUnderTest().getProcessingTime()).isEqualTo(SOME_PROCESSING_TIME); }
@Override public long addError(long processingTimeInMs) { addProcessingTime(processingTimeInMs); inProgress.decrementAndGet(); return error.incrementAndGet(); }
@Test public void addError_any_number_of_call_change_by_1_per_call() { int calls = new Random().nextInt(SOME_RANDOM_MAX); for (int i = 0; i < calls; i++) { getUnderTest().addError(1); } assertThat(getUnderTest().getErrorCount()).isEqualTo(calls); assertThat(getUnderTest().getInProgressCount()).isEqualTo(-calls); assertThat(getUnderTest().getProcessingTime()).isEqualTo(calls); }
@Override public long addSuccess(long processingTimeInMs) { addProcessingTime(processingTimeInMs); inProgress.decrementAndGet(); return success.incrementAndGet(); }
@Test public void addInProgress_increases_InProgress() { getUnderTest().addInProgress(); assertThat(getUnderTest().getInProgressCount()).isEqualTo(1); assertThat(getUnderTest().getErrorCount()).isEqualTo(0); assertThat(getUnderTest().getSuccessCount()).isEqualTo(0); assertThat(getUnderTest().getProcessingTime()).isEqualTo(0); }
@Test public void verify_just_created_instance_metrics() { assertThat(getUnderTest().getInProgressCount()).isEqualTo(0); assertThat(getUnderTest().getErrorCount()).isEqualTo(0); assertThat(getUnderTest().getSuccessCount()).isEqualTo(0); assertThat(getUnderTest().getProcessingTime()).isEqualTo(0); }