Search in sources :

Example 6 with LocalPolicies

use of org.apache.pulsar.common.policies.data.LocalPolicies in project incubator-pulsar by apache.

the class LocalPolicesTest method testLocalPolices.

@Test
public void testLocalPolices() {
    LocalPolicies localPolicy0 = new LocalPolicies();
    LocalPolicies localPolicy1 = new LocalPolicies();
    List<String> boundaries0 = new ArrayList<>();
    List<String> boundaries1 = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        boundaries0.add(String.valueOf(i));
        boundaries0.add(String.valueOf(i));
        boundaries1.add(String.valueOf(i));
    }
    localPolicy0.bundles.setBoundaries(boundaries0);
    localPolicy0.bundles.setNumBundles(boundaries0.size() - 1);
    localPolicy1.bundles.setBoundaries(boundaries1);
    localPolicy1.bundles.setNumBundles(boundaries1.size() - 1);
    assertFalse(localPolicy0.equals(localPolicy1));
    assertFalse(localPolicy0.equals(new OldPolicies()));
    localPolicy1.bundles.setBoundaries(boundaries0);
    localPolicy1.bundles.setNumBundles(boundaries0.size() - 1);
    assertTrue(localPolicy0.equals(localPolicy1));
}
Also used : LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 7 with LocalPolicies

use of org.apache.pulsar.common.policies.data.LocalPolicies in project incubator-pulsar by apache.

the class BrokerServiceTest method testCreateNamespacePolicy.

/**
 * It verifies that policiesCache() copies global-policy data into local-policy data and returns combined result
 *
 * @throws Exception
 */
@Test
public void testCreateNamespacePolicy() throws Exception {
    final String namespace = "prop/use/testPolicy";
    final int totalBundle = 3;
    admin.namespaces().createNamespace(namespace, new BundlesData(totalBundle));
    String globalPath = joinPath(LOCAL_POLICIES_ROOT, namespace);
    pulsar.getLocalZkCacheService().policiesCache().clear();
    Optional<LocalPolicies> policy = pulsar.getLocalZkCacheService().policiesCache().get(globalPath);
    assertTrue(policy.isPresent());
    assertEquals(policy.get().bundles.numBundles, totalBundle);
}
Also used : BundlesData(org.apache.pulsar.common.policies.data.BundlesData) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) Test(org.testng.annotations.Test)

Example 8 with LocalPolicies

use of org.apache.pulsar.common.policies.data.LocalPolicies in project incubator-pulsar by apache.

the class NamespaceBundleTest method getNamespaceBundleFactory.

@SuppressWarnings("unchecked")
private NamespaceBundleFactory getNamespaceBundleFactory() {
    PulsarService pulsar = mock(PulsarService.class);
    LocalZooKeeperCacheService localZkCache = mock(LocalZooKeeperCacheService.class);
    ZooKeeperDataCache<LocalPolicies> poilciesCache = mock(ZooKeeperDataCache.class);
    when(pulsar.getLocalZkCacheService()).thenReturn(localZkCache);
    when(localZkCache.policiesCache()).thenReturn(poilciesCache);
    doNothing().when(poilciesCache).registerListener(any());
    return NamespaceBundleFactory.createFactory(pulsar, Hashing.crc32());
}
Also used : PulsarService(org.apache.pulsar.broker.PulsarService) LocalPolicies(org.apache.pulsar.common.policies.data.LocalPolicies) LocalZooKeeperCacheService(org.apache.pulsar.broker.cache.LocalZooKeeperCacheService)

Aggregations

LocalPolicies (org.apache.pulsar.common.policies.data.LocalPolicies)8 PulsarService (org.apache.pulsar.broker.PulsarService)4 LocalZooKeeperCacheService (org.apache.pulsar.broker.cache.LocalZooKeeperCacheService)3 NamespaceBundleFactory (org.apache.pulsar.common.naming.NamespaceBundleFactory)2 LocalZooKeeperCache (org.apache.pulsar.zookeeper.LocalZooKeeperCache)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Test (org.testng.annotations.Test)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Maps (com.google.common.collect.Maps)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ZkUtils (org.apache.bookkeeper.util.ZkUtils)1 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)1 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)1 POLICIES_ROOT (org.apache.pulsar.broker.cache.ConfigurationCacheService.POLICIES_ROOT)1 NamespaceEphemeralData (org.apache.pulsar.broker.namespace.NamespaceEphemeralData)1 BrokerService (org.apache.pulsar.broker.service.BrokerService)1 PulsarWebResource.joinPath (org.apache.pulsar.broker.web.PulsarWebResource.joinPath)1