Search in sources :

Example 1 with TlsConfig

use of com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig in project athenz by yahoo.

the class PulsarChangeSubscriberTest method test_subscriber_creation.

@Test
public void test_subscriber_creation() throws IOException, InterruptedException {
    System.setProperty(PROP_MESSAGING_CLI_SERVICE_URL, "some-service");
    PulsarChangeSubscriber<DomainChangeMessage> subscriber = new PulsarChangeSubscriber<>("service-url", "topic", "subs", SubscriptionType.Exclusive, new TlsConfig("cert", "key", "trust"));
    assertNotNull(getPulsarConsumer(subscriber));
}
Also used : DomainChangeMessage(com.yahoo.athenz.common.messaging.DomainChangeMessage) TlsConfig(com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig) Test(org.testng.annotations.Test)

Example 2 with TlsConfig

use of com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig in project athenz by yahoo.

the class PulsarChangePublisherTest method test_publisher_creation.

@Test
public void test_publisher_creation() {
    System.setProperty(PROP_MESSAGING_CLI_SERVICE_URL, "some-service");
    PulsarChangePublisher<DomainChangeMessage> publisher = new PulsarChangePublisher<>(serviceUrl(), "some-topic", new TlsConfig("cert", "key", "trust"));
    publisher.publish(new DomainChangeMessage());
    publisher.close();
    assertNotNull(getPulsarProducer(publisher));
    System.clearProperty(PROP_MESSAGING_CLI_SERVICE_URL);
}
Also used : DomainChangeMessage(com.yahoo.athenz.common.messaging.DomainChangeMessage) TlsConfig(com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig) Test(org.testng.annotations.Test)

Example 3 with TlsConfig

use of com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig in project athenz by yahoo.

the class PulsarChangePublisherTest method test_validate_publisher.

@Test
public void test_validate_publisher() {
    try {
        new PulsarChangePublisher<>(null, "topic", new TlsConfig("cert", "key", "trust"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid service configured");
    }
    try {
        new PulsarChangePublisher<>("service-url", null, new TlsConfig("cert", "key", "trust"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid topic configured");
    }
    try {
        new PulsarChangePublisher<>("service-url", "topic", new TlsConfig(null, "key", "trust"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid tls configured");
    }
    try {
        new PulsarChangePublisher<>("service-url", "topic", null);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid tls configured");
    }
}
Also used : TlsConfig(com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig) Test(org.testng.annotations.Test)

Example 4 with TlsConfig

use of com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig in project athenz by yahoo.

the class PulsarChangeSubscriberTest method test_validate_subscriber.

@Test
public void test_validate_subscriber() {
    try {
        new PulsarChangeSubscriber<>("service-url", null, "subs", SubscriptionType.Exclusive, new TlsConfig("cert", "key", "trust"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid topic configured");
    }
    try {
        new PulsarChangeSubscriber<>(null, "topic", "subs", SubscriptionType.Exclusive, new TlsConfig("cert", "key", "trust"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid service configured");
    }
    try {
        new PulsarChangeSubscriber<>("service-url", "topic", null, SubscriptionType.Exclusive, new TlsConfig("cert", "key", "trust"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid subscription name configured");
    }
    try {
        new PulsarChangeSubscriber<>("service-url", "topic", "subs", null, new TlsConfig("cert", "key", "trust"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid subscription type configured");
    }
    try {
        new PulsarChangeSubscriber<>("service-url", "topic", "subs", SubscriptionType.Exclusive, null);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid tls configured");
    }
    try {
        new PulsarChangeSubscriber<>("service-url", "topic", "subs", SubscriptionType.Exclusive, new TlsConfig(null, "key", "trust"));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(e.getMessage(), "invalid tls configured");
    }
}
Also used : TlsConfig(com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig) Test(org.testng.annotations.Test)

Example 5 with TlsConfig

use of com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig in project athenz by yahoo.

the class PulsarChangeSubscriberTest method test_subscribe_to_mock_msg.

@Test
public void test_subscribe_to_mock_msg() throws IOException, InterruptedException {
    System.setProperty(PROP_MESSAGING_CLI_SERVICE_URL, "some-service");
    PulsarChangeSubscriber<DomainChangeMessage> subscriber = new PulsarChangeSubscriber<>("service-url", "topic", "subs", SubscriptionType.Exclusive, new TlsConfig("cert", "key", "trust"));
    // init subscriber
    subscriber.init(this::assertDomainMessage, DomainChangeMessage.class);
    ExecutorService service = Executors.newSingleThreadExecutor();
    service.submit(subscriber);
    Thread.sleep(500);
    subscriber.close();
    Consumer<byte[]> pulsarConsumer = getPulsarConsumer(subscriber);
    assertNotNull(pulsarConsumer);
    ArgumentCaptor<Message<DomainChangeMessage>> messageCapture = ArgumentCaptor.forClass(Message.class);
    verify(pulsarConsumer, Mockito.atLeastOnce()).acknowledge(messageCapture.capture());
    assertDomainMessage(new ObjectMapper().readValue(messageCapture.getValue().getData(), DomainChangeMessage.class));
    System.clearProperty(PROP_MESSAGING_CLI_SERVICE_URL);
}
Also used : Message(org.apache.pulsar.client.api.Message) DomainChangeMessage(com.yahoo.athenz.common.messaging.DomainChangeMessage) DomainChangeMessage(com.yahoo.athenz.common.messaging.DomainChangeMessage) ExecutorService(java.util.concurrent.ExecutorService) TlsConfig(com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

TlsConfig (com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig)5 Test (org.testng.annotations.Test)5 DomainChangeMessage (com.yahoo.athenz.common.messaging.DomainChangeMessage)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ExecutorService (java.util.concurrent.ExecutorService)1 Message (org.apache.pulsar.client.api.Message)1