@Override public Table buildTable(final CommandStatusEntity entity) { return new Table.Builder() .withColumnHeaders("Message") .withRow(entity.getCommandStatus().getMessage().split("\n", 2)[0]) .build(); } }
private void printKsqlResponse(final RestResponse<KsqlEntityList> response) throws IOException { if (response.isSuccessful()) { final KsqlEntityList ksqlEntities = response.getResponse(); boolean noErrorFromServer = true; for (final KsqlEntity entity : ksqlEntities) { if (entity instanceof CommandStatusEntity && ( ((CommandStatusEntity) entity).getCommandStatus().getStatus() == CommandStatus.Status.ERROR) ) { final String fullMessage = ((CommandStatusEntity) entity).getCommandStatus().getMessage(); terminal.printError(fullMessage.split("\n")[0], fullMessage); noErrorFromServer = false; } } if (noErrorFromServer) { terminal.printKsqlEntityList(response.getResponse()); } } else { terminal.printErrorMessage(response.getErrorMessage()); } }
@Test public void shoudlHandleTerminateRequestCorrectly() throws InterruptedException { // When: final Response response = ksqlResource.terminateCluster(VALID_TERMINATE_REQUEST); // Then: assertThat(response.getStatus(), equalTo(200)); assertThat(response.getEntity(), instanceOf(KsqlEntityList.class)); assertThat(((KsqlEntityList) response.getEntity()).size(), equalTo(1)); assertThat(((KsqlEntityList) response.getEntity()).get(0), instanceOf(CommandStatusEntity.class)); final CommandStatusEntity commandStatusEntity = (CommandStatusEntity) ((KsqlEntityList) response.getEntity()).get(0); assertThat(commandStatusEntity.getCommandStatus().getStatus(), equalTo(CommandStatus.Status.QUEUED)); verify(commandStore).enqueueCommand( eq(TerminateCluster.TERMINATE_CLUSTER_STATEMENT_TEXT), isA(Statement.class), any(), eq(Collections.singletonMap( ClusterTerminateRequest.DELETE_TOPIC_LIST_PROP, ImmutableList.of("Foo")))); }
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 ); } }