Search in sources :

Example 1 with ClientMessagingService

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);
}
Also used : InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) Injector(com.google.inject.Injector) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) ClientMessagingService(io.cdap.cdap.messaging.client.ClientMessagingService) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 2 with ClientMessagingService

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);
    }
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) ArrayList(java.util.ArrayList) MessagingService(io.cdap.cdap.messaging.MessagingService) ClientMessagingService(io.cdap.cdap.messaging.client.ClientMessagingService) TopicMetadata(io.cdap.cdap.messaging.TopicMetadata) Injector(com.google.inject.Injector) TopicId(io.cdap.cdap.proto.id.TopicId) ClientMessagingService(io.cdap.cdap.messaging.client.ClientMessagingService) RawMessage(io.cdap.cdap.messaging.data.RawMessage) Test(org.junit.Test)

Example 3 with ClientMessagingService

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);
    }
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) ArrayList(java.util.ArrayList) MessagingService(io.cdap.cdap.messaging.MessagingService) ClientMessagingService(io.cdap.cdap.messaging.client.ClientMessagingService) TopicMetadata(io.cdap.cdap.messaging.TopicMetadata) Injector(com.google.inject.Injector) TopicId(io.cdap.cdap.proto.id.TopicId) ClientMessagingService(io.cdap.cdap.messaging.client.ClientMessagingService) RawMessage(io.cdap.cdap.messaging.data.RawMessage) Test(org.junit.Test)

Example 4 with ClientMessagingService

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);
}
Also used : InMemoryDiscoveryModule(io.cdap.cdap.common.guice.InMemoryDiscoveryModule) Injector(com.google.inject.Injector) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) ClientMessagingService(io.cdap.cdap.messaging.client.ClientMessagingService) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Aggregations

Injector (com.google.inject.Injector)4 ClientMessagingService (io.cdap.cdap.messaging.client.ClientMessagingService)4 AbstractModule (com.google.inject.AbstractModule)2 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)2 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)2 RemoteClientFactory (io.cdap.cdap.common.internal.remote.RemoteClientFactory)2 NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)2 MessagingService (io.cdap.cdap.messaging.MessagingService)2 TopicMetadata (io.cdap.cdap.messaging.TopicMetadata)2 RawMessage (io.cdap.cdap.messaging.data.RawMessage)2 MessagingServerRuntimeModule (io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule)2 TopicId (io.cdap.cdap.proto.id.TopicId)2 AuthenticationContextModules (io.cdap.cdap.security.auth.context.AuthenticationContextModules)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 Test (org.junit.Test)2