@Test public void onCompleteShouldExecuteOperationWhenCompleted() { AtomicInteger atomicInteger = new AtomicInteger(0); Task.Result.COMPLETED .onComplete(atomicInteger::incrementAndGet); assertThat(atomicInteger.get()) .isEqualTo(1); }
private Migration toMigration(SchemaVersion version) { return () -> { SchemaVersion newVersion = version.next(); SchemaVersion currentVersion = getCurrentVersion().orElse(DEFAULT_VERSION); if (currentVersion.isAfterOrEquals(newVersion)) { return Migration.Result.COMPLETED; } logger.info("Migrating to version {} ", newVersion); return allMigrationClazz.get(version).run() .onComplete(() -> schemaVersionDAO.updateVersion(newVersion).join(), () -> logger.info("Migrating to version {} done", newVersion)) .onFailure(() -> logger.warn(failureMessage(newVersion)), () -> throwMigrationException(newVersion)); }; }
private Migration toMigration(SchemaVersion version) { return () -> { SchemaVersion newVersion = version.next(); SchemaVersion currentVersion = getCurrentVersion().orElse(DEFAULT_VERSION); if (currentVersion.isAfterOrEquals(newVersion)) { return Migration.Result.COMPLETED; } logger.info("Migrating to version {} ", newVersion); return allMigrationClazz.get(version).run() .onComplete(() -> schemaVersionDAO.updateVersion(newVersion).join(), () -> logger.info("Migrating to version {} done", newVersion)) .onFailure(() -> logger.warn(failureMessage(newVersion)), () -> throwMigrationException(newVersion)); }; }
private void run(TaskExecutionDetails executionDetails, Task task, Consumer<TaskId> callback) { TaskExecutionDetails started = executionDetails.start(); idToExecutionDetails.put(started.getTaskId(), started); try { task.run() .onComplete(() -> success(started)) .onFailure(() -> failed(started, logger -> logger.info("Task was partially performed. Check logs for more details"))); } catch (Exception e) { failed(started, logger -> logger.error("Error while running task", executionDetails, e)); } finally { idToFuture.remove(executionDetails.getTaskId()); callback.accept(executionDetails.getTaskId()); } }
@Test public void onCompleteShouldReturnPartialWhenPartial() { assertThat( Task.Result.PARTIAL .onComplete(() -> { })) .isEqualTo(Task.Result.PARTIAL); }
@Test public void onCompleteShouldExecuteOperationWhenCompleted() { AtomicInteger atomicInteger = new AtomicInteger(0); Task.Result.COMPLETED .onComplete(atomicInteger::incrementAndGet); assertThat(atomicInteger.get()) .isEqualTo(1); }
@Test public void onCompleteShouldReturnPartialWhenOperationThrows() { assertThat( Task.Result.COMPLETED .onComplete(() -> { throw new RuntimeException(); })) .isEqualTo(Task.Result.PARTIAL); }
@Test public void onCompleteShouldReturnPartialWhenPartial() { assertThat( Task.Result.PARTIAL .onComplete(() -> { })) .isEqualTo(Task.Result.PARTIAL); }
@Test public void onCompleteShouldNotExecuteOperationWhenPartial() { AtomicInteger atomicInteger = new AtomicInteger(0); Task.Result.PARTIAL .onComplete(atomicInteger::incrementAndGet); assertThat(atomicInteger.get()) .isEqualTo(0); }
public Task.Result run(CassandraId oldMailboxId, CassandraId newMailboxId, MailboxMergingTask.Context context) { return moveMessages(oldMailboxId, newMailboxId, mailboxSession, context) .onComplete( () -> mergeRights(oldMailboxId, newMailboxId), () -> mailboxDAO.delete(oldMailboxId).join()); }
@Test public void onCompleteShouldReturnPartialWhenOperationThrows() { assertThat( Task.Result.COMPLETED .onComplete(() -> { throw new RuntimeException(); })) .isEqualTo(Task.Result.PARTIAL); }
@Test public void onCompleteShouldReturnCompletedWhenCompleted() { assertThat( Task.Result.COMPLETED .onComplete(() -> { })) .isEqualTo(Task.Result.COMPLETED); }
@Test public void onCompleteShouldReturnCompletedWhenCompleted() { assertThat( Task.Result.COMPLETED .onComplete(() -> { })) .isEqualTo(Task.Result.COMPLETED); }
@Test public void onCompleteShouldNotExecuteOperationWhenPartial() { AtomicInteger atomicInteger = new AtomicInteger(0); Task.Result.PARTIAL .onComplete(atomicInteger::incrementAndGet); assertThat(atomicInteger.get()) .isEqualTo(0); }