use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.
the class PersistentTopicTest method setup.
@BeforeMethod
public void setup() throws Exception {
ServiceConfiguration svcConfig = spy(new ServiceConfiguration());
pulsar = spy(new PulsarService(svcConfig));
doReturn(svcConfig).when(pulsar).getConfiguration();
mlFactoryMock = mock(ManagedLedgerFactory.class);
doReturn(mlFactoryMock).when(pulsar).getManagedLedgerFactory();
ZooKeeper mockZk = createMockZooKeeper();
doReturn(mockZk).when(pulsar).getZkClient();
doReturn(createMockBookKeeper(mockZk)).when(pulsar).getBookKeeperClient();
configCacheService = mock(ConfigurationCacheService.class);
@SuppressWarnings("unchecked") ZooKeeperDataCache<Policies> zkDataCache = mock(ZooKeeperDataCache.class);
doReturn(zkDataCache).when(configCacheService).policiesCache();
doReturn(configCacheService).when(pulsar).getConfigurationCache();
doReturn(Optional.empty()).when(zkDataCache).get(anyString());
LocalZooKeeperCacheService zkCache = mock(LocalZooKeeperCacheService.class);
doReturn(CompletableFuture.completedFuture(Optional.empty())).when(zkDataCache).getAsync(any());
doReturn(zkDataCache).when(zkCache).policiesCache();
doReturn(configCacheService).when(pulsar).getConfigurationCache();
doReturn(zkCache).when(pulsar).getLocalZkCacheService();
brokerService = spy(new BrokerService(pulsar));
doReturn(brokerService).when(pulsar).getBrokerService();
serverCnx = spy(new ServerCnx(brokerService));
doReturn(true).when(serverCnx).isActive();
doReturn(true).when(serverCnx).isWritable();
doReturn(new InetSocketAddress("localhost", 1234)).when(serverCnx).clientAddress();
NamespaceService nsSvc = mock(NamespaceService.class);
doReturn(nsSvc).when(pulsar).getNamespaceService();
doReturn(true).when(nsSvc).isServiceUnitOwned(any(NamespaceBundle.class));
doReturn(true).when(nsSvc).isServiceUnitActive(any(TopicName.class));
setupMLAsyncCallbackMocks();
}
use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.
the class PersistentTopicTest method testMaxProducersForBroker.
@Test
public void testMaxProducersForBroker() throws Exception {
// set max clients
ServiceConfiguration svcConfig = spy(new ServiceConfiguration());
doReturn(2).when(svcConfig).getMaxProducersPerTopic();
doReturn(svcConfig).when(pulsar).getConfiguration();
testMaxProducers();
}
use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.
the class BrokerVersionFilterTest method testLatestVersion.
@Test
public void testLatestVersion() {
LoadData loadData = initLoadData();
Set<String> brokers = new TreeSet<>();
brokers.add("broker1");
brokers.add("broker2");
brokers.add("broker3");
BrokerVersionFilter filter = new BrokerVersionFilter();
try {
Version latestVersion = filter.getLatestVersionNumber(brokers, loadData);
Assert.assertEquals(latestVersion.getMajorVersion(), 1);
Assert.assertEquals(latestVersion.getMinorVersion(), 2);
Assert.assertEquals(latestVersion.getPatchVersion(), 0);
} catch (BrokerFilterBadVersionException bad) {
Assert.fail(bad.getMessage(), bad);
}
ServiceConfiguration configuration = new ServiceConfiguration();
configuration.setPreferLaterVersions(true);
try {
filter.filter(brokers, null, loadData, configuration);
// Only one broker is running the latest version
Assert.assertEquals(brokers.size(), 1);
} catch (BrokerFilterBadVersionException bad) {
Assert.fail(bad.getMessage(), bad);
}
}
use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.
the class LoadBalancerTest method setup.
@BeforeMethod
void setup() throws Exception {
// Start local bookkeeper ensemble
bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, PortManager.nextFreePort());
bkEnsemble.start();
ZkUtils.createFullPathOptimistic(bkEnsemble.getZkClient(), SimpleLoadManagerImpl.LOADBALANCER_DYNAMIC_SETTING_STRATEGY_ZPATH, "{\"loadBalancerStrategy\":\"leastLoadedServer\"}".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
final String localhost = InetAddress.getLocalHost().getHostName();
// start brokers
for (int i = 0; i < BROKER_COUNT; i++) {
brokerWebServicePorts[i] = PortManager.nextFreePort();
brokerNativeBrokerPorts[i] = PortManager.nextFreePort();
ServiceConfiguration config = new ServiceConfiguration();
config.setBrokerServicePort(brokerNativeBrokerPorts[i]);
config.setClusterName("use");
config.setAdvertisedAddress("localhost");
config.setWebServicePort(brokerWebServicePorts[i]);
config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
config.setBrokerServicePort(brokerNativeBrokerPorts[i]);
config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
config.setAdvertisedAddress(localhost + i);
config.setLoadBalancerEnabled(false);
pulsarServices[i] = new PulsarService(config);
pulsarServices[i].start();
brokerUrls[i] = new URL("http://127.0.0.1" + ":" + brokerWebServicePorts[i]);
lookupAddresses[i] = pulsarServices[i].getAdvertisedAddress() + ":" + config.getWebServicePort();
pulsarAdmins[i] = new PulsarAdmin(brokerUrls[i], (Authentication) null);
}
createNamespacePolicies(pulsarServices[0]);
Thread.sleep(100);
}
use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.
the class ModularLoadManagerImplTest method testNeedBrokerDataUpdate.
// Test that ModularLoadManagerImpl will determine that writing local data to ZooKeeper is necessary if certain
// metrics change by a percentage threshold.
@Test
public void testNeedBrokerDataUpdate() throws Exception {
final LocalBrokerData lastData = new LocalBrokerData();
final LocalBrokerData currentData = new LocalBrokerData();
final ServiceConfiguration conf = pulsar1.getConfiguration();
// Set this manually in case the default changes.
conf.setLoadBalancerReportUpdateThresholdPercentage(5);
// Easier to test using an uninitialized ModularLoadManagerImpl.
final ModularLoadManagerImpl loadManager = new ModularLoadManagerImpl();
setField(loadManager, "lastData", lastData);
setField(loadManager, "localData", currentData);
setField(loadManager, "conf", conf);
Supplier<Boolean> needUpdate = () -> {
try {
return (Boolean) invokeSimpleMethod(loadManager, "needBrokerDataUpdate");
} catch (Exception e) {
throw new RuntimeException(e);
}
};
lastData.setMsgRateIn(100);
currentData.setMsgRateIn(104);
// 4% difference: shouldn't trigger an update.
assert (!needUpdate.get());
currentData.setMsgRateIn(105.1);
// 5% difference: should trigger an update (exactly 5% is flaky due to precision).
assert (needUpdate.get());
// Do similar tests for lower values.
currentData.setMsgRateIn(94);
assert (needUpdate.get());
currentData.setMsgRateIn(95.1);
assert (!needUpdate.get());
// 0 to non-zero should always trigger an update.
lastData.setMsgRateIn(0);
currentData.setMsgRateIn(1e-8);
assert (needUpdate.get());
// non-zero to zero should trigger an update as long as the threshold is less than 100.
lastData.setMsgRateIn(1e-8);
currentData.setMsgRateIn(0);
assert (needUpdate.get());
// zero to zero should never trigger an update.
currentData.setMsgRateIn(0);
lastData.setMsgRateIn(0);
assert (!needUpdate.get());
// Minimally test other absolute values to ensure they are included.
lastData.getCpu().usage = 100;
lastData.getCpu().limit = 1000;
currentData.getCpu().usage = 106;
currentData.getCpu().limit = 1000;
assert (!needUpdate.get());
// Minimally test other absolute values to ensure they are included.
lastData.getCpu().usage = 100;
lastData.getCpu().limit = 1000;
currentData.getCpu().usage = 206;
currentData.getCpu().limit = 1000;
assert (needUpdate.get());
lastData.setCpu(new ResourceUsage());
currentData.setCpu(new ResourceUsage());
lastData.setMsgThroughputIn(100);
currentData.setMsgThroughputIn(106);
assert (needUpdate.get());
currentData.setMsgThroughputIn(100);
lastData.setNumBundles(100);
currentData.setNumBundles(106);
assert (needUpdate.get());
currentData.setNumBundles(100);
assert (!needUpdate.get());
}
Aggregations