DefaultOneOffReconciler implements OneOffReconciler<DATA> { @Override public Mono<DATA> apply(Function<DATA, Mono<DATA>> action) { return executor.apply(action); } DefaultOneOffReconciler(String id,
                                   DATA initial,
                                   Duration quickCycle,
                                   Duration longCycle,
                                   Function<DATA, List<Mono<Function<DATA, DATA>>>> reconcilerActionsProvider,
                                   Scheduler scheduler,
                                   TitusRuntime titusRuntime); @Override Mono<Void> close(); @Override DATA getCurrent(); @Override Mono<DATA> apply(Function<DATA, Mono<DATA>> action); @Override Flux<DATA> changes();  }
@Test(timeout = 30_000) public void testExternalAction() { newReconciler(current -> Collections.emptyList()); assertThat(reconciler.apply(c -> Mono.just("update")).block()).isEqualTo("update"); assertThat(changesSubscriber.takeNext()).isEqualTo("update"); assertThat(changesSubscriber.takeNext()).isNull(); }
@Test(timeout = 30_000) public void testExternalActionCancel() throws Exception { newReconciler(current -> Collections.emptyList()); CountDownLatch latch = new CountDownLatch(1); AtomicBoolean canceled = new AtomicBoolean(); Mono<String> action = Mono.<String>never() .doOnSubscribe(s -> latch.countDown()) .doOnCancel(() -> canceled.set(true)); Disposable disposable = reconciler.apply(c -> action).subscribe(); latch.await(); assertThat(disposable.isDisposed()).isFalse(); assertThat(canceled.get()).isFalse(); disposable.dispose(); await().until(canceled::get); assertThat(changesSubscriber.takeNext()).isNull(); assertThat(reconciler.apply(anything -> Mono.just("Regular")).block(TIMEOUT)).isEqualTo("Regular"); }
@Test(timeout = 30_000) public void testExternalActionMonoError() { newReconciler(current -> Collections.emptyList()); try { reconciler.apply(anything -> Mono.error(new RuntimeException("simulated error"))).block(); fail("Expected error"); } catch (Exception e) { assertThat(e).isInstanceOf(RuntimeException.class); assertThat(e.getMessage()).isEqualTo("simulated error"); } assertThat(changesSubscriber.takeNext()).isNull(); }
@Test(timeout = 30_000) public void testExternalActionFunctionError() { newReconciler(current -> Collections.emptyList()); try { reconciler.apply(c -> { throw new RuntimeException("simulated error"); }).block(); fail("Expected error"); } catch (Exception e) { assertThat(e).isInstanceOf(RuntimeException.class); assertThat(e.getMessage()).isEqualTo("simulated error"); } assertThat(changesSubscriber.takeNext()).isNull(); }