Search in sources :

Example 1 with NamespaceIsolationPolicyImpl

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"));
}
Also used : NamespaceIsolationPolicyImpl(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl) Test(org.testng.annotations.Test)

Example 2 with NamespaceIsolationPolicyImpl

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()));
}
Also used : NamespaceIsolationPolicyImpl(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl) AutoFailoverPolicyData(org.apache.pulsar.common.policies.data.AutoFailoverPolicyData) NamespaceIsolationData(org.apache.pulsar.common.policies.data.NamespaceIsolationData) OldPolicies(org.apache.pulsar.common.policies.data.OldPolicies) Test(org.testng.annotations.Test)

Example 3 with NamespaceIsolationPolicyImpl

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
    }
}
Also used : NamespaceIsolationPolicyImpl(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl) ArrayList(java.util.ArrayList) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 4 with NamespaceIsolationPolicyImpl

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);
}
Also used : NamespaceIsolationPolicies(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies) NamespaceIsolationPolicyImpl(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl) NamespaceIsolationPolicy(org.apache.pulsar.common.policies.NamespaceIsolationPolicy) Test(org.testng.annotations.Test)

Example 5 with NamespaceIsolationPolicyImpl

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);
}
Also used : NamespaceIsolationPolicies(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies) NamespaceIsolationPolicyImpl(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl) NamespaceIsolationPolicy(org.apache.pulsar.common.policies.NamespaceIsolationPolicy) Test(org.testng.annotations.Test)

Aggregations

NamespaceIsolationPolicyImpl (org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl)8 Test (org.testng.annotations.Test)8 NamespaceIsolationPolicies (org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 NamespaceIsolationPolicy (org.apache.pulsar.common.policies.NamespaceIsolationPolicy)2 BrokerStatus (org.apache.pulsar.common.policies.data.BrokerStatus)2 NamespaceIsolationData (org.apache.pulsar.common.policies.data.NamespaceIsolationData)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 URL (java.net.URL)1 AutoFailoverPolicyData (org.apache.pulsar.common.policies.data.AutoFailoverPolicyData)1 OldPolicies (org.apache.pulsar.common.policies.data.OldPolicies)1