private static void runStatement(final String statement, final KsqlRestClient restClient) {
final RestResponse response = restClient.makeKsqlRequest(statement);
Assert.assertThat(response.isSuccessful(), is(true));
final KsqlEntityList entityList = ((KsqlEntityList) response.get());
Assert.assertThat(entityList.size(), equalTo(1));
Assert.assertThat(entityList.get(0), instanceOf(CommandStatusEntity.class));
final CommandStatusEntity entity = (CommandStatusEntity) entityList.get(0);
final CommandStatus status = entity.getCommandStatus();
Assert.assertThat(status, not(CommandStatus.Status.ERROR));
if (status.getStatus() != Status.SUCCESS) {
assertThatEventually(
"",
() -> {
final RestResponse statusResponse = restClient
.makeStatusRequest(entity.getCommandId().toString());
Assert.assertThat(statusResponse.isSuccessful(), is(true));
Assert.assertThat(statusResponse.get(), instanceOf(CommandStatus.class));
return ((CommandStatus) statusResponse.get()).getStatus();
},
anyOf(
is(CommandStatus.Status.SUCCESS),
is(CommandStatus.Status.TERMINATED),
is(CommandStatus.Status.ERROR)),
120,
TimeUnit.SECONDS
);
}
}