use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.
the class BrokerServiceLookupTest method testMultipleBrokerLookup.
/**
* UsecaseL Multiple Broker => Lookup Redirection test
*
* 1. Broker1 is a leader
* 2. Lookup request reaches to Broker2 which redirects to leader (Broker1) with authoritative = false
* 3. Leader (Broker1) finds out least loaded broker as Broker2 and redirects request to Broker2 with authoritative = true
* 4. Broker2 receives final request to own a bundle with authoritative = true and client connects to Broker2
*
* @throws Exception
*/
@Test
public void testMultipleBrokerLookup() throws Exception {
log.info("-- Starting {} test --", methodName);
/**** start broker-2 ****/
ServiceConfiguration conf2 = new ServiceConfiguration();
conf2.setBrokerServicePort(PortManager.nextFreePort());
conf2.setBrokerServicePortTls(PortManager.nextFreePort());
conf2.setWebServicePort(PortManager.nextFreePort());
conf2.setWebServicePortTls(PortManager.nextFreePort());
conf2.setAdvertisedAddress("localhost");
conf2.setClusterName(conf.getClusterName());
PulsarService pulsar2 = startBroker(conf2);
pulsar.getLoadManager().writeLoadReportOnZookeeper();
pulsar2.getLoadManager().writeLoadReportOnZookeeper();
LoadManager loadManager1 = spy(pulsar.getLoadManager());
LoadManager loadManager2 = spy(pulsar2.getLoadManager());
Field loadManagerField = NamespaceService.class.getDeclaredField("loadManager");
loadManagerField.setAccessible(true);
// mock: redirect request to leader [2]
doReturn(true).when(loadManager2).isCentralized();
loadManagerField.set(pulsar2.getNamespaceService(), loadManager2);
// mock: return Broker2 as a Least-loaded broker when leader receies request [3]
doReturn(true).when(loadManager1).isCentralized();
SimpleResourceUnit resourceUnit = new SimpleResourceUnit(pulsar2.getWebServiceAddress(), null);
doReturn(resourceUnit).when(loadManager1).getLeastLoaded(any(ServiceUnitId.class));
loadManagerField.set(pulsar.getNamespaceService(), loadManager1);
/**** started broker-2 ****/
URI brokerServiceUrl = new URI("pulsar://localhost:" + conf2.getBrokerServicePort());
PulsarClient pulsarClient2 = PulsarClient.create(brokerServiceUrl.toString(), new ClientConfiguration());
// load namespace-bundle by calling Broker2
Consumer consumer = pulsarClient2.subscribe("persistent://my-property/use/my-ns/my-topic1", "my-subscriber-name", new ConsumerConfiguration());
Producer producer = pulsarClient.createProducer("persistent://my-property/use/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();
pulsarClient2.close();
pulsar2.close();
loadManager1 = null;
loadManager2 = null;
}
use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.
the class PulsarConfigurationLoaderTest method testPulsarConfiguraitonLoadingStream.
@Test
public void testPulsarConfiguraitonLoadingStream() throws Exception {
File testConfigFile = new File("tmp." + System.currentTimeMillis() + ".properties");
if (testConfigFile.exists()) {
testConfigFile.delete();
}
final String zkServer = "z1.example.com,z2.example.com,z3.example.com";
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(testConfigFile)));
printWriter.println("zookeeperServers=" + zkServer);
printWriter.println("globalZookeeperServers=gz1.example.com,gz2.example.com,gz3.example.com/foo");
printWriter.println("brokerDeleteInactiveTopicsEnabled=true");
printWriter.println("statusFilePath=/tmp/status.html");
printWriter.println("managedLedgerDefaultEnsembleSize=1");
printWriter.println("backlogQuotaDefaultLimitGB=18");
printWriter.println("clusterName=usc");
printWriter.println("brokerClientAuthenticationPlugin=test.xyz.client.auth.plugin");
printWriter.println("brokerClientAuthenticationParameters=role:my-role");
printWriter.println("superUserRoles=appid1,appid2");
printWriter.println("brokerServicePort=7777");
printWriter.println("managedLedgerDefaultMarkDeleteRateLimit=5.0");
printWriter.close();
testConfigFile.deleteOnExit();
InputStream stream = new FileInputStream(testConfigFile);
final ServiceConfiguration serviceConfig = PulsarConfigurationLoader.create(stream, ServiceConfiguration.class);
assertNotNull(serviceConfig);
assertEquals(serviceConfig.getZookeeperServers(), zkServer);
assertEquals(serviceConfig.isBrokerDeleteInactiveTopicsEnabled(), true);
assertEquals(serviceConfig.getBacklogQuotaDefaultLimitGB(), 18);
assertEquals(serviceConfig.getClusterName(), "usc");
assertEquals(serviceConfig.getBrokerClientAuthenticationParameters(), "role:my-role");
assertEquals(serviceConfig.getBrokerServicePort(), 7777);
}
use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.
the class PulsarConfigurationLoaderTest method testPulsarConfiguraitonLoadingProp.
@Test
public void testPulsarConfiguraitonLoadingProp() throws Exception {
final String zk = "localhost:2184";
final Properties prop = new Properties();
prop.setProperty("zookeeperServers", zk);
final ServiceConfiguration serviceConfig = PulsarConfigurationLoader.create(prop, ServiceConfiguration.class);
assertNotNull(serviceConfig);
assertEquals(serviceConfig.getZookeeperServers(), zk);
}
use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.
the class PulsarBrokerStarter method loadConfig.
private static ServiceConfiguration loadConfig(String configFile) throws Exception {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
ServiceConfiguration config = create((new FileInputStream(configFile)), ServiceConfiguration.class);
// it validates provided configuration is completed
isComplete(config);
return config;
}
use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.
the class WebSocketService method createServiceConfiguration.
private static ServiceConfiguration createServiceConfiguration(WebSocketProxyConfiguration config) {
ServiceConfiguration serviceConfig = new ServiceConfiguration();
serviceConfig.setClusterName(config.getClusterName());
serviceConfig.setWebServicePort(config.getWebServicePort());
serviceConfig.setWebServicePortTls(config.getWebServicePortTls());
serviceConfig.setAuthenticationEnabled(config.isAuthenticationEnabled());
serviceConfig.setAuthenticationProviders(config.getAuthenticationProviders());
serviceConfig.setBrokerClientAuthenticationPlugin(config.getBrokerClientAuthenticationPlugin());
serviceConfig.setBrokerClientAuthenticationParameters(config.getBrokerClientAuthenticationParameters());
serviceConfig.setAuthorizationEnabled(config.isAuthorizationEnabled());
serviceConfig.setSuperUserRoles(config.getSuperUserRoles());
serviceConfig.setGlobalZookeeperServers(config.getGlobalZookeeperServers());
serviceConfig.setZooKeeperSessionTimeoutMillis(config.getZooKeeperSessionTimeoutMillis());
serviceConfig.setTlsEnabled(config.isTlsEnabled());
serviceConfig.setTlsCertificateFilePath(config.getTlsCertificateFilePath());
serviceConfig.setTlsKeyFilePath(config.getTlsKeyFilePath());
return serviceConfig;
}
Aggregations