public static void waitUntil(final BooleanSupplier condition) { doRepeatedly(() -> null).until((r) -> condition.getAsBoolean()); }
public static Invocation<Void> doRepeatedly(Runnable runnable) { return new Invocation<>( () -> { runnable.run(); return null; }); }
public T whileConditionHolds( Function<T, Boolean> resultCondition, Function<Exception, Boolean> exceptionCondition, final int retries) { int numTries = 0; T result; do { result = null; try { if (numTries > 0) { Thread.sleep(100L); } result = callable.call(); } catch (Exception e) { if (!exceptionCondition.apply(e)) { throw new RuntimeException("Unexpected exception while checking condition", e); } } numTries++; } while (numTries < retries && resultCondition.apply(result)); return result; } }
e -> Records.isEvent(e, ValueType.DEPLOYMENT, DeploymentIntent.CREATED)) .findFirst()) .until(o -> o.isPresent()) .get();
e -> Records.isEvent(e, ValueType.DEPLOYMENT, DeploymentIntent.CREATED)) .findFirst()) .until(o -> o.isPresent()) .get();
@Test @Category(UnstableTest.class) // => https://github.com/zeebe-io/zeebe/issues/1250 public void shouldCreateDeploymentOnAllPartitionsWithRestartBroker() { // given apiRule .createCmdRequest() .partitionId(Protocol.DEPLOYMENT_PARTITION) .type(ValueType.DEPLOYMENT, DeploymentIntent.CREATE) .command() .put( "resources", Collections.singletonList(deploymentResource(bpmnXml(WORKFLOW), "process.bpmn"))) .done() .send() .await(); // when brokerRule.restartBroker(); doRepeatedly(apiRule::getPartitionIds).until(p -> !p.isEmpty()); // then assertAnyCreatedDeploymentEventOnPartition(0); assertAnyCreatedDeploymentEventOnPartition(1); assertAnyCreatedDeploymentEventOnPartition(2); }
@Test @Category(UnstableTest.class) // => https://github.com/zeebe-io/zeebe/issues/1250 public void shouldCreateDeploymentOnAllPartitionsWithRestartBroker() { // given apiRule .createCmdRequest() .partitionId(Protocol.DEPLOYMENT_PARTITION) .type(ValueType.DEPLOYMENT, DeploymentIntent.CREATE) .command() .put( "resources", Collections.singletonList(deploymentResource(bpmnXml(WORKFLOW), "process.bpmn"))) .done() .send() .await(); // when brokerRule.restartBroker(); doRepeatedly(apiRule::getPartitionIds).until(p -> !p.isEmpty()); // then assertAnyCreatedDeploymentEventOnPartition(0); assertAnyCreatedDeploymentEventOnPartition(1); assertAnyCreatedDeploymentEventOnPartition(2); }
public T whileConditionHolds( Function<T, Boolean> resultCondition, Function<Exception, Boolean> exceptionCondition, final int retries) { int numTries = 0; T result; do { result = null; try { if (numTries > 0) { Thread.sleep(100L); } result = callable.call(); } catch (Exception e) { if (!exceptionCondition.apply(e)) { throw new RuntimeException("Unexpected exception while checking condition", e); } } numTries++; } while (numTries < retries && resultCondition.apply(result)); return result; } }
@Override protected void before() throws Throwable { scheduler = ActorScheduler.newActorScheduler() .setCpuBoundActorThreadCount(1) .setActorClock(controlledActorClock) .build(); scheduler.start(); transport = Transports.newClientTransport("gateway").scheduler(scheduler).build(); msgPackHelper = new MsgPackHelper(); transport.registerEndpoint(nodeId, brokerAddressSupplier.get()); final List<Integer> partitionIds = doRepeatedly(this::getPartitionIds).until(p -> !p.isEmpty()); defaultPartitionId = partitionIds.get(0); }
public T until(Function<T, Boolean> resultCondition) { return until(resultCondition, (e) -> false); }
public T whileConditionHolds(Function<T, Boolean> resultCondition, final int retires) { return whileConditionHolds(resultCondition, (e) -> true, retires); }
public T whileConditionHolds(Function<T, Boolean> resultCondition) { return whileConditionHolds(resultCondition, (e) -> true); }
public static <T> Invocation<T> doRepeatedly(Callable<T> callable) { return new Invocation<>(callable); }
@Override protected void before() throws Throwable { scheduler = ActorScheduler.newActorScheduler() .setCpuBoundActorThreadCount(1) .setActorClock(controlledActorClock) .build(); scheduler.start(); transport = Transports.newClientTransport("gateway").scheduler(scheduler).build(); msgPackHelper = new MsgPackHelper(); transport.registerEndpoint(nodeId, brokerAddressSupplier.get()); final List<Integer> partitionIds = doRepeatedly(this::getPartitionIds).until(p -> !p.isEmpty()); defaultPartitionId = partitionIds.get(0); }
public T whileConditionHolds(Function<T, Boolean> resultCondition) { return whileConditionHolds(resultCondition, (e) -> true); }
public TypedRecord<WorkflowInstanceRecord> awaitElementInState( final String elementId, final WorkflowInstanceIntent intent) { final DirectBuffer elementIdAsBuffer = BufferUtil.wrapString(elementId); return doRepeatedly( () -> environmentRule .events() .onlyWorkflowInstanceRecords() .withIntent(intent) .filter(r -> elementIdAsBuffer.equals(r.getValue().getElementId())) .findFirst()) .until(o -> o.isPresent()) .get(); }
public T until( Function<T, Boolean> resultCondition, final String message, final Object... args) { return until(resultCondition, (e) -> false, message, args); }
public T until(Function<T, Boolean> resultCondition) { return until(resultCondition, (e) -> false); }
public static <T> Invocation<T> doRepeatedly(Callable<T> callable) { return new Invocation<>(callable); }
public TypedRecord<WorkflowInstanceRecord> awaitElementInState( final String elementId, final WorkflowInstanceIntent intent) { final DirectBuffer elementIdAsBuffer = BufferUtil.wrapString(elementId); return doRepeatedly( () -> environmentRule .events() .onlyWorkflowInstanceRecords() .withIntent(intent) .filter(r -> elementIdAsBuffer.equals(r.getValue().getElementId())) .findFirst()) .until(o -> o.isPresent()) .get(); }