use of io.cdap.cdap.messaging.client.ClientMessagingService in project cdap by caskdata.
the class MessagingHttpServiceTest method beforeTest.
@Before
public void beforeTest() throws IOException {
cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
cConf.set(Constants.MessagingSystem.HTTP_SERVER_BIND_ADDRESS, InetAddress.getLocalHost().getHostName());
cConf.setInt(Constants.MessagingSystem.HTTP_SERVER_CONSUME_CHUNK_SIZE, 128);
// Set max life time to a high value so that dummy tx ids that we create in the tests still work
cConf.setLong(TxConstants.Manager.CFG_TX_MAX_LIFETIME, 10000000000L);
// Reduce the buffer size for the http request buffer to test "large" message request
cConf.setInt(Constants.MessagingSystem.HTTP_SERVER_MAX_REQUEST_SIZE_MB, 1);
cConf.setBoolean(Constants.MessagingSystem.HTTP_COMPRESS_PAYLOAD, compressPayload);
Injector injector = Guice.createInjector(new ConfigModule(cConf), RemoteAuthenticatorModules.getNoOpModule(), new InMemoryDiscoveryModule(), new AuthenticationContextModules().getNoOpModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).toInstance(new NoOpMetricsCollectionService());
}
});
httpService = injector.getInstance(MessagingHttpService.class);
httpService.startAndWait();
client = new ClientMessagingService(injector.getInstance(RemoteClientFactory.class), compressPayload);
}
use of io.cdap.cdap.messaging.client.ClientMessagingService in project cdap by cdapio.
the class MessagingServiceMainTest method testMessagingService.
@Test
public void testMessagingService() throws Exception {
// Discover the TMS endpoint
Injector injector = getServiceMainInstance(MessagingServiceMain.class).getInjector();
RemoteClientFactory remoteClientFactory = injector.getInstance(RemoteClientFactory.class);
// Use a separate TMS client to create topic, then publish and then poll some messages
TopicId topicId = NamespaceId.SYSTEM.topic("test");
MessagingService messagingService = new ClientMessagingService(remoteClientFactory, true);
messagingService.createTopic(new TopicMetadata(topicId));
// Publish 10 messages
List<String> messages = new ArrayList<>();
for (int i = 0; i < 10; i++) {
String msg = "Testing Message " + i;
messagingService.publish(StoreRequestBuilder.of(topicId).addPayload(msg).build());
messages.add(msg);
}
try (CloseableIterator<RawMessage> iterator = messagingService.prepareFetch(topicId).setLimit(10).fetch()) {
List<String> received = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false).map(RawMessage::getPayload).map(ByteBuffer::wrap).map(StandardCharsets.UTF_8::decode).map(CharSequence::toString).collect(Collectors.toList());
Assert.assertEquals(messages, received);
}
}
use of io.cdap.cdap.messaging.client.ClientMessagingService in project cdap by caskdata.
the class MessagingServiceMainTest method testMessagingService.
@Test
public void testMessagingService() throws Exception {
// Discover the TMS endpoint
Injector injector = getServiceMainInstance(MessagingServiceMain.class).getInjector();
RemoteClientFactory remoteClientFactory = injector.getInstance(RemoteClientFactory.class);
// Use a separate TMS client to create topic, then publish and then poll some messages
TopicId topicId = NamespaceId.SYSTEM.topic("test");
MessagingService messagingService = new ClientMessagingService(remoteClientFactory, true);
messagingService.createTopic(new TopicMetadata(topicId));
// Publish 10 messages
List<String> messages = new ArrayList<>();
for (int i = 0; i < 10; i++) {
String msg = "Testing Message " + i;
messagingService.publish(StoreRequestBuilder.of(topicId).addPayload(msg).build());
messages.add(msg);
}
try (CloseableIterator<RawMessage> iterator = messagingService.prepareFetch(topicId).setLimit(10).fetch()) {
List<String> received = StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false).map(RawMessage::getPayload).map(ByteBuffer::wrap).map(StandardCharsets.UTF_8::decode).map(CharSequence::toString).collect(Collectors.toList());
Assert.assertEquals(messages, received);
}
}
use of io.cdap.cdap.messaging.client.ClientMessagingService in project cdap by cdapio.
the class MessagingHttpServiceTest method beforeTest.
@Before
public void beforeTest() throws IOException {
cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
cConf.set(Constants.MessagingSystem.HTTP_SERVER_BIND_ADDRESS, InetAddress.getLocalHost().getHostName());
cConf.setInt(Constants.MessagingSystem.HTTP_SERVER_CONSUME_CHUNK_SIZE, 128);
// Set max life time to a high value so that dummy tx ids that we create in the tests still work
cConf.setLong(TxConstants.Manager.CFG_TX_MAX_LIFETIME, 10000000000L);
// Reduce the buffer size for the http request buffer to test "large" message request
cConf.setInt(Constants.MessagingSystem.HTTP_SERVER_MAX_REQUEST_SIZE_MB, 1);
cConf.setBoolean(Constants.MessagingSystem.HTTP_COMPRESS_PAYLOAD, compressPayload);
Injector injector = Guice.createInjector(new ConfigModule(cConf), RemoteAuthenticatorModules.getNoOpModule(), new InMemoryDiscoveryModule(), new AuthenticationContextModules().getNoOpModule(), new MessagingServerRuntimeModule().getInMemoryModules(), new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).toInstance(new NoOpMetricsCollectionService());
}
});
httpService = injector.getInstance(MessagingHttpService.class);
httpService.startAndWait();
client = new ClientMessagingService(injector.getInstance(RemoteClientFactory.class), compressPayload);
}
Aggregations