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();
}
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();
}
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);
}
}
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
}
}
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();
}
Aggregations