use of io.camunda.zeebe.util.sched.Actor in project zeebe by camunda.
the class SyncLogStreamBuilder method build.
public SyncLogStream build() {
final var scheduler = Objects.requireNonNull(actorSchedulingService, "must provide an actor scheduling service through SyncLogStreamBuilder#withActorSchedulingService");
final var buildFuture = new CompletableActorFuture<SyncLogStream>();
scheduler.submitActor(new Actor() {
@Override
protected void onActorStarting() {
actor.runOnCompletionBlockingCurrentPhase(buildAsync(), (logStream, t) -> {
if (t == null) {
buildFuture.complete(new SyncLogStream(logStream));
} else {
buildFuture.completeExceptionally(t);
}
});
}
});
return buildFuture.join();
}
use of io.camunda.zeebe.util.sched.Actor in project zeebe by camunda.
the class ActorFutureTest method shouldInvokeCallbackOnFutureCompletion.
@Test
public void shouldInvokeCallbackOnFutureCompletion() {
// given
final CompletableActorFuture<Void> future = new CompletableActorFuture<>();
final AtomicInteger callbackInvocations = new AtomicInteger(0);
final Actor waitingActor = new Actor() {
@Override
protected void onActorStarted() {
actor.runOnCompletion(future, (r, t) -> callbackInvocations.incrementAndGet());
}
};
final Actor completingActor = new Actor() {
@Override
protected void onActorStarted() {
future.complete(null);
}
};
schedulerRule.submitActor(waitingActor);
schedulerRule.workUntilDone();
// when
schedulerRule.submitActor(completingActor);
schedulerRule.workUntilDone();
// then
assertThat(callbackInvocations).hasValue(1);
}
use of io.camunda.zeebe.util.sched.Actor in project zeebe by camunda.
the class ActorFutureTest method shouldInvokeCallbackOnBlockPhaseForFutureCompletion.
@Test
public void shouldInvokeCallbackOnBlockPhaseForFutureCompletion() {
// given
final CompletableActorFuture<Void> future = new CompletableActorFuture<>();
final AtomicInteger callbackInvocations = new AtomicInteger(0);
final Actor waitingActor = new Actor() {
@Override
protected void onActorStarted() {
actor.runOnCompletionBlockingCurrentPhase(future, (r, t) -> callbackInvocations.incrementAndGet());
}
};
final Actor completingActor = new Actor() {
@Override
protected void onActorStarted() {
future.complete(null);
}
};
schedulerRule.submitActor(waitingActor);
schedulerRule.workUntilDone();
// when
schedulerRule.submitActor(completingActor);
schedulerRule.workUntilDone();
// then
assertThat(callbackInvocations).hasValue(1);
}
use of io.camunda.zeebe.util.sched.Actor in project zeebe by camunda.
the class ActorFutureTest method shouldInvokeCallbackOnEmptyFutureList.
@Test
public void shouldInvokeCallbackOnEmptyFutureList() {
// given
final List<ActorFuture<Void>> futures = Collections.emptyList();
final List<Throwable> invocations = new ArrayList<>();
final Actor waitingActor = new Actor() {
@Override
protected void onActorStarted() {
actor.runOnCompletion(futures, t -> {
invocations.add(t);
});
}
};
schedulerRule.submitActor(waitingActor);
schedulerRule.workUntilDone();
// then
assertThat(invocations).hasSize(1).containsNull();
}
use of io.camunda.zeebe.util.sched.Actor in project zeebe by camunda.
the class ActorFutureTest method shouldInvokeCallbackOnCompletedFuture.
@Test
public void shouldInvokeCallbackOnCompletedFuture() {
// given
final AtomicReference<String> futureResult = new AtomicReference<>();
schedulerRule.submitActor(new Actor() {
@Override
protected void onActorStarted() {
actor.runOnCompletion(CompletableActorFuture.completed("foo"), (r, t) -> futureResult.set(r));
}
});
// when
schedulerRule.workUntilDone();
// then
assertThat(futureResult.get()).isEqualTo("foo");
}
Aggregations