Search in sources :

Example 16 with ServiceConfiguration

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();
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) Policies(org.apache.pulsar.common.policies.data.Policies) InetSocketAddress(java.net.InetSocketAddress) TopicName(org.apache.pulsar.common.naming.TopicName) ZooKeeper(org.apache.zookeeper.ZooKeeper) MockedPulsarServiceBaseTest.createMockZooKeeper(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ConfigurationCacheService(org.apache.pulsar.broker.cache.ConfigurationCacheService) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 17 with ServiceConfiguration

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();
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) Test(org.testng.annotations.Test)

Example 18 with ServiceConfiguration

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);
    }
}
Also used : BrokerFilterBadVersionException(org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException) BrokerVersionFilter(org.apache.pulsar.broker.loadbalance.impl.BrokerVersionFilter) LoadData(org.apache.pulsar.broker.loadbalance.LoadData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) Version(com.github.zafarkhaja.semver.Version) TreeSet(java.util.TreeSet) Test(org.testng.annotations.Test)

Example 19 with ServiceConfiguration

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);
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) SimpleLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Authentication(org.apache.pulsar.client.api.Authentication) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 20 with ServiceConfiguration

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());
}
Also used : LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) SystemResourceUsage(org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) Test(org.testng.annotations.Test)

Aggregations

ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)58 Test (org.testng.annotations.Test)28 PulsarService (org.apache.pulsar.broker.PulsarService)24 BeforeMethod (org.testng.annotations.BeforeMethod)14 URL (java.net.URL)11 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)10 Field (java.lang.reflect.Field)9 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)9 TopicName (org.apache.pulsar.common.naming.TopicName)9 LoadManager (org.apache.pulsar.broker.loadbalance.LoadManager)8 Authentication (org.apache.pulsar.client.api.Authentication)8 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)8 Policies (org.apache.pulsar.common.policies.data.Policies)8 LocalBookkeeperEnsemble (org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble)8 InputStream (java.io.InputStream)7 URI (java.net.URI)7 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)7 IOException (java.io.IOException)6 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)6 Map (java.util.Map)5