use of io.confluent.ksql.rest.server.computation.CommandId in project ksql by confluentinc.
the class StatusResourceTest method getTestStatusResource.
private StatusResource getTestStatusResource() {
StatementExecutor mockStatementExecutor = mock(StatementExecutor.class);
expect(mockStatementExecutor.getStatuses()).andReturn(mockCommandStatuses);
for (Map.Entry<CommandId, CommandStatus> commandEntry : mockCommandStatuses.entrySet()) {
expect(mockStatementExecutor.getStatus(commandEntry.getKey())).andReturn(Optional.of(commandEntry.getValue()));
}
expect(mockStatementExecutor.getStatus(anyObject(CommandId.class))).andReturn(Optional.empty());
replay(mockStatementExecutor);
return new StatusResource(mockStatementExecutor);
}
use of io.confluent.ksql.rest.server.computation.CommandId in project ksql by confluentinc.
the class StatusResourceTest method testGetAllStatuses.
@Test
public void testGetAllStatuses() {
StatusResource testResource = getTestStatusResource();
Object statusesEntity = testResource.getAllStatuses().getEntity();
assertThat(statusesEntity, instanceOf(CommandStatuses.class));
CommandStatuses testCommandStatuses = (CommandStatuses) statusesEntity;
Map<CommandId, CommandStatus.Status> expectedCommandStatuses = CommandStatuses.fromFullStatuses(mockCommandStatuses);
assertEquals(expectedCommandStatuses, testCommandStatuses);
}
use of io.confluent.ksql.rest.server.computation.CommandId in project ksql by confluentinc.
the class TestUtils method getAllPriorCommandRecords.
public List<Pair<CommandId, Command>> getAllPriorCommandRecords() {
List<Pair<CommandId, Command>> priorCommands = new ArrayList<>();
Command topicCommand = new Command("REGISTER TOPIC pageview_topic WITH " + "(value_format = 'json', " + "kafka_topic='pageview_topic_json');", new HashMap<>());
CommandId topicCommandId = new CommandId(CommandId.Type.TOPIC, "_CSASTopicGen", CommandId.Action.CREATE);
priorCommands.add(new Pair<>(topicCommandId, topicCommand));
Command csCommand = new Command("CREATE STREAM pageview " + "(viewtime bigint, pageid varchar, userid varchar) " + "WITH (registered_topic = 'pageview_topic');", new HashMap<>());
CommandId csCommandId = new CommandId(CommandId.Type.STREAM, "_CSASStreamGen", CommandId.Action.CREATE);
priorCommands.add(new Pair<>(csCommandId, csCommand));
Command csasCommand = new Command("CREATE STREAM user1pv " + " AS select * from pageview WHERE userid = 'user1';", new HashMap<>());
CommandId csasCommandId = new CommandId(CommandId.Type.STREAM, "_CSASGen", CommandId.Action.CREATE);
priorCommands.add(new Pair<>(csasCommandId, csasCommand));
Command ctasCommand = new Command("CREATE TABLE user1pvtb " + " AS select * from pageview window tumbling(size 5 " + "second) WHERE userid = " + "'user1' group by pageid;", new HashMap<>());
CommandId ctasCommandId = new CommandId(CommandId.Type.TABLE, "_CTASGen", CommandId.Action.CREATE);
priorCommands.add(new Pair<>(ctasCommandId, ctasCommand));
return priorCommands;
}
use of io.confluent.ksql.rest.server.computation.CommandId in project ksql by confluentinc.
the class StatusResource method getStatus.
@GET
@Path("/{type}/{entity}/{action}")
public Response getStatus(@PathParam("type") String type, @PathParam("entity") String entity, @PathParam("action") String action) throws Exception {
CommandId commandId = new CommandId(type, entity, action);
Optional<CommandStatus> commandStatus = statementExecutor.getStatus(commandId);
if (!commandStatus.isPresent()) {
throw new Exception("Command not found");
}
return Response.ok(commandStatus.get()).build();
}
use of io.confluent.ksql.rest.server.computation.CommandId in project ksql by confluentinc.
the class KsqlRestClientTest method testStatus.
@Test
public void testStatus() {
RestResponse<CommandStatuses> commandStatusesRestResponse = ksqlRestClient.makeStatusRequest();
Assert.assertNotNull(commandStatusesRestResponse);
Assert.assertTrue(commandStatusesRestResponse.isSuccessful());
CommandStatuses commandStatuses = commandStatusesRestResponse.getResponse();
Assert.assertTrue(commandStatuses.size() == 2);
Assert.assertTrue(commandStatuses.get(new CommandId(CommandId.Type.TOPIC, "c1", CommandId.Action.CREATE)) == CommandStatus.Status.SUCCESS);
Assert.assertTrue(commandStatuses.get(new CommandId(CommandId.Type.TOPIC, "c2", CommandId.Action.CREATE)) == CommandStatus.Status.ERROR);
}
Aggregations