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