Search in sources :

Example 11 with DomainChangeMessage

use of com.yahoo.athenz.common.messaging.DomainChangeMessage 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

DomainChangeMessage (com.yahoo.athenz.common.messaging.DomainChangeMessage)11 Test (org.testng.annotations.Test)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Authorizer (com.yahoo.athenz.auth.Authorizer)3 TlsConfig (com.yahoo.athenz.common.messaging.pulsar.client.AthenzPulsarClient.TlsConfig)3 AuthorityList (com.yahoo.athenz.common.server.rest.Http.AuthorityList)3 AuthzDetailsEntity (com.yahoo.athenz.common.config.AuthzDetailsEntity)2 MockDomainChangePublisher (com.yahoo.athenz.common.messaging.MockDomainChangePublisher)2 Metric (com.yahoo.athenz.common.metrics.Metric)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 Strings (com.google.common.base.Strings)1 JOSEException (com.nimbusds.jose.JOSEException)1 JWSObject (com.nimbusds.jose.JWSObject)1 JWSVerifier (com.nimbusds.jose.JWSVerifier)1 RSASSAVerifier (com.nimbusds.jose.crypto.RSASSAVerifier)1 Base64URL (com.nimbusds.jose.util.Base64URL)1 Authority (com.yahoo.athenz.auth.Authority)1