use of org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl in project incubator-pulsar by apache.
the class NamespaceIsolationPolicyImplTest method testIsPrimaryOrSecondaryBroker.
@Test
public void testIsPrimaryOrSecondaryBroker() throws Exception {
NamespaceIsolationPolicyImpl defaultPolicy = this.getDefaultPolicy();
assertTrue(defaultPolicy.isPrimaryBroker("prod1-broker2.messaging.use.example.com"));
assertTrue(!defaultPolicy.isPrimaryBroker("prod1-broker5.messaging.use.example.com"));
assertTrue(defaultPolicy.isSecondaryBroker("prod1-broker5.messaging.use.example.com"));
assertTrue(!defaultPolicy.isSecondaryBroker("broker-X.messaging.use.example.com"));
}
use of org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl in project incubator-pulsar by apache.
the class NamespaceIsolationPolicyImplTest method testConstructor.
@Test
public void testConstructor() throws Exception {
NamespaceIsolationPolicyImpl defaultPolicy = this.getDefaultPolicy();
NamespaceIsolationData policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/test.*");
policyData.primary = new ArrayList<String>();
policyData.primary.add("prod1-broker[1-3].messaging.use.example.com");
policyData.secondary = new ArrayList<String>();
policyData.secondary.add("prod1-broker.*.use.example.com");
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "3");
policyData.auto_failover_policy.parameters.put("usage_threshold", "90");
NamespaceIsolationPolicyImpl newPolicy = new NamespaceIsolationPolicyImpl(policyData);
assertTrue(defaultPolicy.equals(newPolicy));
policyData.auto_failover_policy.parameters.put("usage_threshold", "80");
newPolicy = new NamespaceIsolationPolicyImpl(policyData);
assertTrue(!defaultPolicy.equals(newPolicy));
assertTrue(!newPolicy.equals(new OldPolicies()));
}
use of org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl in project incubator-pulsar by apache.
the class NamespaceIsolationPolicyImplTest method testFindBrokers.
@Test
public void testFindBrokers() throws Exception {
NamespaceIsolationPolicyImpl defaultPolicy = this.getDefaultPolicy();
List<URL> brokers = new ArrayList<URL>();
for (int i = 0; i < 10; i++) {
String broker = String.format("prod1-broker%d.messaging.use.example.com", i);
brokers.add(new URL(String.format("http://%s:8080", broker)));
}
List<URL> otherBrokers = new ArrayList<URL>();
for (int i = 0; i < 10; i++) {
String broker = String.format("prod1-broker%d.messaging.usw.example.com", i);
brokers.add(new URL(String.format("http://%s:8080", broker)));
}
List<URL> primaryBrokers = defaultPolicy.findPrimaryBrokers(brokers, NamespaceName.get("pulsar/use/testns-1"));
assertEquals(primaryBrokers.size(), 3);
for (URL primaryBroker : primaryBrokers) {
assertTrue(primaryBroker.getHost().matches("prod1-broker[1-3].messaging.use.example.com"));
}
primaryBrokers = defaultPolicy.findPrimaryBrokers(otherBrokers, NamespaceName.get("pulsar/use/testns-1"));
assertTrue(primaryBrokers.isEmpty());
try {
primaryBrokers = defaultPolicy.findPrimaryBrokers(brokers, NamespaceName.get("no/such/namespace"));
} catch (IllegalArgumentException iae) {
// OK
}
List<URL> secondaryBrokers = defaultPolicy.findSecondaryBrokers(brokers, NamespaceName.get("pulsar/use/testns-1"));
assertEquals(secondaryBrokers.size(), 10);
for (URL secondaryBroker : secondaryBrokers) {
assertTrue(secondaryBroker.getHost().matches("prod1-broker.*.messaging.use.example.com"));
}
secondaryBrokers = defaultPolicy.findSecondaryBrokers(otherBrokers, NamespaceName.get("pulsar/use/testns-1"));
assertTrue(secondaryBrokers.isEmpty());
try {
secondaryBrokers = defaultPolicy.findSecondaryBrokers(brokers, NamespaceName.get("no/such/namespace"));
} catch (IllegalArgumentException iae) {
// OK
}
}
use of org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl in project incubator-pulsar by apache.
the class NamespaceIsolationPoliciesTest method testGetNamespaceIsolationPolicyByNamespace.
@Test
public void testGetNamespaceIsolationPolicyByNamespace() throws Exception {
NamespaceIsolationPolicies policies = this.getDefaultTestPolicies();
NamespaceIsolationPolicy nsPolicy = policies.getPolicyByNamespace(NamespaceName.get("no/such/namespace"));
assertTrue(nsPolicy == null);
nsPolicy = policies.getPolicyByNamespace(NamespaceName.get("pulsar/use/testns-1"));
assertNotNull(nsPolicy);
assertEquals(new NamespaceIsolationPolicyImpl(policies.getPolicies().get("policy1")), nsPolicy);
}
use of org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl in project incubator-pulsar by apache.
the class NamespaceIsolationPoliciesTest method testGetNamespaceIsolationPolicyByName.
@Test
public void testGetNamespaceIsolationPolicyByName() throws Exception {
NamespaceIsolationPolicies policies = this.getDefaultTestPolicies();
NamespaceIsolationPolicy nsPolicy = policies.getPolicyByName("non-existing-policy");
assertTrue(nsPolicy == null);
nsPolicy = policies.getPolicyByName("policy1");
assertNotNull(nsPolicy);
assertEquals(new NamespaceIsolationPolicyImpl(policies.getPolicies().get("policy1")), nsPolicy);
}
Aggregations