Search in sources :

Example 1 with ServiceConfig

use of com.yahoo.pulsar.discovery.service.server.ServiceConfig in project pulsar by yahoo.

the class BaseDiscoveryTestSetup method setup.

protected void setup() throws Exception {
    config = new ServiceConfig();
    config.setServicePort(nextFreePort());
    config.setServicePortTls(nextFreePort());
    config.setBindOnLocalhost(true);
    config.setTlsEnabled(true);
    config.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
    config.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
    mockZookKeeper = createMockZooKeeper();
    service = spy(new DiscoveryService(config));
    doReturn(mockZooKeeperClientFactory).when(service).getZooKeeperClientFactory();
    service.start();
}
Also used : ServiceConfig(com.yahoo.pulsar.discovery.service.server.ServiceConfig)

Example 2 with ServiceConfig

use of com.yahoo.pulsar.discovery.service.server.ServiceConfig in project pulsar by yahoo.

the class BrokerServiceLookupTest method testDiscoveryLookup.

/**
     * Discovery-Service lookup over binary-protocol
     * 1. Start discovery service
     * 2. start broker
     * 3. Create Producer/Consumer: by calling Discovery service for partitionedMetadata and topic lookup
     * 
     * @throws Exception
     */
@Test
public void testDiscoveryLookup() throws Exception {
    // (1) start discovery service
    ServiceConfig config = new ServiceConfig();
    config.setServicePort(nextFreePort());
    config.setBindOnLocalhost(true);
    DiscoveryService discoveryService = spy(new DiscoveryService(config));
    doReturn(mockZooKeeperClientFactory).when(discoveryService).getZooKeeperClientFactory();
    discoveryService.start();
    // (2) lookup using discovery service
    final String discoverySvcUrl = discoveryService.getServiceUrl();
    ClientConfiguration clientConfig = new ClientConfiguration();
    PulsarClient pulsarClient2 = PulsarClient.create(discoverySvcUrl, clientConfig);
    Consumer consumer = pulsarClient2.subscribe("persistent://my-property2/use2/my-ns/my-topic1", "my-subscriber-name", new ConsumerConfiguration());
    Producer producer = pulsarClient2.createProducer("persistent://my-property2/use2/my-ns/my-topic1", new ProducerConfiguration());
    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }
    Message msg = null;
    Set<String> messageSet = Sets.newHashSet();
    for (int i = 0; i < 10; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        String receivedMessage = new String(msg.getData());
        log.debug("Received message: [{}]", receivedMessage);
        String expectedMessage = "my-message-" + i;
        testMessageOrderAndDuplicates(messageSet, receivedMessage, expectedMessage);
    }
    // Acknowledge the consumption of all messages at once
    consumer.acknowledgeCumulative(msg);
    consumer.close();
    producer.close();
}
Also used : ServiceConfig(com.yahoo.pulsar.discovery.service.server.ServiceConfig) DiscoveryService(com.yahoo.pulsar.discovery.service.DiscoveryService) Test(org.testng.annotations.Test)

Example 3 with ServiceConfig

use of com.yahoo.pulsar.discovery.service.server.ServiceConfig in project pulsar by yahoo.

the class BrokerServiceLookupTest method testDiscoveryLookupAuthorizationFailure.

@Test
public void testDiscoveryLookupAuthorizationFailure() throws Exception {
    // (1) start discovery service
    ServiceConfig config = new ServiceConfig();
    config.setServicePort(nextFreePort());
    config.setBindOnLocalhost(true);
    // set Authentication provider which returns "invalid" appid so, authorization fails 
    Set<String> providersClassNames = Sets.newHashSet(MockAuthorizationProviderFail.class.getName());
    config.setAuthenticationProviders(providersClassNames);
    // enable authentication
    config.setAuthenticationEnabled(true);
    config.setAuthorizationEnabled(true);
    DiscoveryService discoveryService = spy(new DiscoveryService(config));
    doReturn(mockZooKeeperClientFactory).when(discoveryService).getZooKeeperClientFactory();
    discoveryService.start();
    // (2) lookup using discovery service
    final String discoverySvcUrl = discoveryService.getServiceUrl();
    ClientConfiguration clientConfig = new ClientConfiguration();
    // set authentication data
    clientConfig.setAuthentication(new Authentication() {

        @Override
        public void close() throws IOException {
        }

        @Override
        public String getAuthMethodName() {
            return "auth";
        }

        @Override
        public AuthenticationDataProvider getAuthData() throws PulsarClientException {
            return new AuthenticationDataProvider() {
            };
        }

        @Override
        public void configure(Map<String, String> authParams) {
        }

        @Override
        public void start() throws PulsarClientException {
        }
    });
    PulsarClient pulsarClient = PulsarClient.create(discoverySvcUrl, clientConfig);
    try {
        pulsarClient.subscribe("persistent://my-property/use2/my-ns/my-topic1", "my-subscriber-name", new ConsumerConfiguration());
        Assert.fail("should have failed due to authentication");
    } catch (PulsarClientException e) {
        // Ok: expected
        Assert.assertTrue(e instanceof PulsarClientException.LookupException);
    }
}
Also used : IOException(java.io.IOException) ServiceConfig(com.yahoo.pulsar.discovery.service.server.ServiceConfig) DiscoveryService(com.yahoo.pulsar.discovery.service.DiscoveryService) Test(org.testng.annotations.Test)

Example 4 with ServiceConfig

use of com.yahoo.pulsar.discovery.service.server.ServiceConfig in project pulsar by yahoo.

the class BrokerServiceLookupTest method testDiscoveryLookupAuthenticationFailure.

@Test
public void testDiscoveryLookupAuthenticationFailure() throws Exception {
    // (1) start discovery service
    ServiceConfig config = new ServiceConfig();
    config.setServicePort(nextFreePort());
    config.setBindOnLocalhost(true);
    // set Authentication provider which fails authentication
    Set<String> providersClassNames = Sets.newHashSet(MockAuthenticationProviderFail.class.getName());
    config.setAuthenticationProviders(providersClassNames);
    // enable authentication
    config.setAuthenticationEnabled(true);
    config.setAuthorizationEnabled(true);
    DiscoveryService discoveryService = spy(new DiscoveryService(config));
    doReturn(mockZooKeeperClientFactory).when(discoveryService).getZooKeeperClientFactory();
    discoveryService.start();
    // (2) lookup using discovery service
    final String discoverySvcUrl = discoveryService.getServiceUrl();
    ClientConfiguration clientConfig = new ClientConfiguration();
    // set authentication data
    clientConfig.setAuthentication(new Authentication() {

        @Override
        public void close() throws IOException {
        }

        @Override
        public String getAuthMethodName() {
            return "auth";
        }

        @Override
        public AuthenticationDataProvider getAuthData() throws PulsarClientException {
            return new AuthenticationDataProvider() {
            };
        }

        @Override
        public void configure(Map<String, String> authParams) {
        }

        @Override
        public void start() throws PulsarClientException {
        }
    });
    PulsarClient pulsarClient = PulsarClient.create(discoverySvcUrl, clientConfig);
    try {
        pulsarClient.subscribe("persistent://my-property/use2/my-ns/my-topic1", "my-subscriber-name", new ConsumerConfiguration());
        Assert.fail("should have failed due to authentication");
    } catch (PulsarClientException e) {
    // Ok: expected
    }
}
Also used : IOException(java.io.IOException) ServiceConfig(com.yahoo.pulsar.discovery.service.server.ServiceConfig) DiscoveryService(com.yahoo.pulsar.discovery.service.DiscoveryService) Test(org.testng.annotations.Test)

Example 5 with ServiceConfig

use of com.yahoo.pulsar.discovery.service.server.ServiceConfig in project pulsar by yahoo.

the class BrokerServiceLookupTest method testDiscoveryLookupAuthAndAuthSuccess.

@Test
public void testDiscoveryLookupAuthAndAuthSuccess() throws Exception {
    // (1) start discovery service
    ServiceConfig config = new ServiceConfig();
    config.setServicePort(nextFreePort());
    config.setBindOnLocalhost(true);
    // add Authentication Provider
    Set<String> providersClassNames = Sets.newHashSet(MockAuthenticationProvider.class.getName());
    config.setAuthenticationProviders(providersClassNames);
    // enable authentication and authorization
    config.setAuthenticationEnabled(true);
    config.setAuthorizationEnabled(true);
    DiscoveryService discoveryService = spy(new DiscoveryService(config));
    doReturn(mockZooKeeperClientFactory).when(discoveryService).getZooKeeperClientFactory();
    discoveryService.start();
    // (2) lookup using discovery service
    final String discoverySvcUrl = discoveryService.getServiceUrl();
    ClientConfiguration clientConfig = new ClientConfiguration();
    // set authentication data
    clientConfig.setAuthentication(new Authentication() {

        @Override
        public void close() throws IOException {
        }

        @Override
        public String getAuthMethodName() {
            return "auth";
        }

        @Override
        public AuthenticationDataProvider getAuthData() throws PulsarClientException {
            return new AuthenticationDataProvider() {
            };
        }

        @Override
        public void configure(Map<String, String> authParams) {
        }

        @Override
        public void start() throws PulsarClientException {
        }
    });
    PulsarClient pulsarClient = PulsarClient.create(discoverySvcUrl, clientConfig);
    Consumer consumer = pulsarClient.subscribe("persistent://my-property/use2/my-ns/my-topic1", "my-subscriber-name", new ConsumerConfiguration());
    Producer producer = pulsarClient.createProducer("persistent://my-property/use2/my-ns/my-topic1", new ProducerConfiguration());
    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }
    Message msg = null;
    Set<String> messageSet = Sets.newHashSet();
    for (int i = 0; i < 10; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        String receivedMessage = new String(msg.getData());
        log.debug("Received message: [{}]", receivedMessage);
        String expectedMessage = "my-message-" + i;
        testMessageOrderAndDuplicates(messageSet, receivedMessage, expectedMessage);
    }
    // Acknowledge the consumption of all messages at once
    consumer.acknowledgeCumulative(msg);
    consumer.close();
    producer.close();
}
Also used : IOException(java.io.IOException) ServiceConfig(com.yahoo.pulsar.discovery.service.server.ServiceConfig) DiscoveryService(com.yahoo.pulsar.discovery.service.DiscoveryService) Test(org.testng.annotations.Test)

Aggregations

ServiceConfig (com.yahoo.pulsar.discovery.service.server.ServiceConfig)8 Test (org.testng.annotations.Test)7 DiscoveryService (com.yahoo.pulsar.discovery.service.DiscoveryService)5 IOException (java.io.IOException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 LoadReport (com.yahoo.pulsar.common.policies.data.loadbalancer.LoadReport)2 ServerManager (com.yahoo.pulsar.discovery.service.server.ServerManager)2 TreeMap (java.util.TreeMap)2 KeeperException (org.apache.zookeeper.KeeperException)2 AuthenticationTls (com.yahoo.pulsar.client.impl.auth.AuthenticationTls)1 BundlesData (com.yahoo.pulsar.common.policies.data.BundlesData)1 RestException (com.yahoo.pulsar.discovery.service.web.RestException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 SecureRandom (java.security.SecureRandom)1 HashMap (java.util.HashMap)1 KeyManager (javax.net.ssl.KeyManager)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManager (javax.net.ssl.TrustManager)1