@Test public void start_triggers_recovery_run_at_fixed_rate() throws Exception { MapSettings settings = new MapSettings() .setProperty("sonar.search.recovery.initialDelayInMs", "0") .setProperty("sonar.search.recovery.delayInMs", "1"); underTest = spy(new RecoveryIndexer(system2, settings.asConfig(), db.getDbClient())); AtomicInteger calls = new AtomicInteger(0); doAnswer(invocation -> { calls.incrementAndGet(); return null; }).when(underTest).recover(); underTest.start(); // wait for 2 runs while (calls.get() < 2) { Thread.sleep(1L); } }
@Test public void display_default_configuration_at_startup() { underTest = newRecoveryIndexer(emptySettings.asConfig()); underTest.start(); underTest.stop(); assertThat(logTester.logs(LoggerLevel.DEBUG)).contains( "Elasticsearch recovery - sonar.search.recovery.delayInMs=300000", "Elasticsearch recovery - sonar.search.recovery.minAgeInMs=300000"); }
@Test public void soft_failures_are_logged_and_do_not_stop_recovery_scheduling() throws Exception { insertItem(FOO_TYPE, "f1"); SoftFailingFakeIndexer indexer = new SoftFailingFakeIndexer(FOO_TYPE); advanceInTime(); underTest = newRecoveryIndexer(indexer); underTest.start(); // all runs fail, but they are still scheduled // -> waiting for 2 runs while (indexer.called.size() < 2) { Thread.sleep(1L); } underTest.stop(); // No rows treated assertThatQueueHasSize(1); assertThatLogsContain(INFO, "Elasticsearch recovery - 1 documents processed [1 failures]"); }
@Test public void hard_failures_are_logged_and_do_not_stop_recovery_scheduling() throws Exception { insertItem(FOO_TYPE, "f1"); HardFailingFakeIndexer indexer = new HardFailingFakeIndexer(FOO_TYPE); advanceInTime(); underTest = newRecoveryIndexer(indexer); underTest.start(); // all runs fail, but they are still scheduled // -> waiting for 2 runs while (indexer.called.size() < 2) { Thread.sleep(1L); } underTest.stop(); // No rows treated assertThatQueueHasSize(1); assertThatLogsContain(ERROR, "Elasticsearch recovery - fail to recover documents"); }