use of io.cdap.cdap.api.messaging.Message in project cdap by cdapio.
the class TetheringServerHandlerTest method testProcessControlChannelProgramUpdates.
@Test
public void testProcessControlChannelProgramUpdates() throws Exception {
// Create and accept tethering
createTethering("xyz", NAMESPACES, REQUEST_TIME, DESCRIPTION);
acceptTethering();
expectTetheringControlResponse("xyz", HttpResponseStatus.OK);
// Add program update Notifications to body
HttpRequest.Builder builder = HttpRequest.builder(HttpMethod.POST, config.resolveURL("tethering/controlchannels/xyz"));
ProgramRunId programRunId = new ProgramRunId("system", "app", ProgramType.SPARK, "program", "run");
Notification programUpdate = new Notification(Notification.Type.PROGRAM_STATUS, ImmutableMap.of(ProgramOptionConstants.PROGRAM_RUN_ID, GSON.toJson(programRunId)));
TetheringControlChannelRequest content = new TetheringControlChannelRequest(null, ImmutableList.of(programUpdate));
builder.withBody(GSON.toJson(content));
HttpResponse response = HttpRequests.execute(builder.build());
Assert.assertEquals(HttpResponseStatus.OK.code(), response.getResponseCode());
// Check that program update was persisted as a state transition in TMS
try (CloseableIterator<Message> iterator = new MultiThreadMessagingContext(messagingService).getMessageFetcher().fetch(NamespaceId.SYSTEM.getNamespace(), cConf.get(Constants.AppFabric.PROGRAM_STATUS_EVENT_TOPIC), 1, null)) {
Assert.assertTrue(iterator.hasNext());
Notification notification = iterator.next().decodePayload(r -> GSON.fromJson(r, Notification.class));
Assert.assertEquals(programUpdate, notification);
Map<String, String> properties = notification.getProperties();
Assert.assertEquals(GSON.toJson(programRunId), properties.get(ProgramOptionConstants.PROGRAM_RUN_ID));
}
// Delete tethering
deleteTethering();
}
use of io.cdap.cdap.api.messaging.Message in project cdap by cdapio.
the class TetheringRuntimeJobManagerTest method testPublishToControlChannel.
@Test
public void testPublishToControlChannel() throws Exception {
TetheringControlMessage message = new TetheringControlMessage(TetheringControlMessage.Type.START_PROGRAM, "payload".getBytes(StandardCharsets.UTF_8));
runtimeJobManager.publishToControlChannel(message);
try (CloseableIterator<Message> iterator = messageFetcher.fetch(topicId.getNamespace(), topicId.getTopic(), 1, 0)) {
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(GSON.toJson(message), iterator.next().getPayloadAsString());
}
}
use of io.cdap.cdap.api.messaging.Message in project cdap by cdapio.
the class RuntimeClientServerTest method testSmallMessage.
@Test
public void testSmallMessage() throws Exception {
ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("workflow").run(RunIds.generate());
TopicId topicId = NamespaceId.SYSTEM.topic("topic");
List<Message> messages = new ArrayList<>();
messages.add(createMessage(Math.max(1, RuntimeClient.CHUNK_SIZE / 4)));
runtimeClient.sendMessages(programRunId, topicId, messages.iterator());
assertMessages(topicId, messages);
}
use of io.cdap.cdap.api.messaging.Message in project cdap by cdapio.
the class RuntimeClientServerTest method testFutureIsNotBlockingWhenValueIsSet.
@Test
public void testFutureIsNotBlockingWhenValueIsSet() throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(1);
runtimeClient.onProgramStopRequested(() -> countDownLatch.countDown());
// Now call sendMessages which will set the future
ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("workflow").run(RunIds.generate());
TopicId topicId = NamespaceId.SYSTEM.topic("topic");
List<Message> messages = new ArrayList<>();
messages.add(createMessage(Math.max(1, RuntimeClient.CHUNK_SIZE / 4)));
runtimeClient.sendMessages(programRunId, topicId, messages.iterator());
// Assert that future is not blocking anymore
Assert.assertTrue(countDownLatch.await(5, TimeUnit.SECONDS));
}
use of io.cdap.cdap.api.messaging.Message in project cdap by cdapio.
the class RuntimeClientServerTest method testLargeMessage.
@Test
public void testLargeMessage() throws Exception {
ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("workflow").run(RunIds.generate());
TopicId topicId = NamespaceId.SYSTEM.topic(TEST_TOPIC);
List<Message> messages = new ArrayList<>();
for (int i = 0; i < 10; i++) {
messages.add(createMessage(RuntimeClient.CHUNK_SIZE * 2));
}
runtimeClient.sendMessages(programRunId, topicId, messages.iterator());
assertMessages(topicId, messages);
}
Aggregations