Search in sources :

Example 1 with OldPolicies

use of org.apache.pulsar.common.policies.data.OldPolicies 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 2 with OldPolicies

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

the class MinAvailablePolicyTest method testMinAvailablePolicty.

@Test
public void testMinAvailablePolicty() {
    MinAvailablePolicy m = new MinAvailablePolicy(3, 10);
    Assert.assertFalse(m.equals(new OldPolicies()));
    Assert.assertFalse(m.shouldFailoverToSecondary(15));
    Assert.assertTrue(m.shouldFailoverToSecondary(2));
}
Also used : OldPolicies(org.apache.pulsar.common.policies.data.OldPolicies) MinAvailablePolicy(org.apache.pulsar.common.policies.impl.MinAvailablePolicy) Test(org.testng.annotations.Test)

Aggregations

OldPolicies (org.apache.pulsar.common.policies.data.OldPolicies)2 Test (org.testng.annotations.Test)2 AutoFailoverPolicyData (org.apache.pulsar.common.policies.data.AutoFailoverPolicyData)1 NamespaceIsolationData (org.apache.pulsar.common.policies.data.NamespaceIsolationData)1 MinAvailablePolicy (org.apache.pulsar.common.policies.impl.MinAvailablePolicy)1 NamespaceIsolationPolicyImpl (org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl)1