Search in sources :

Example 1 with BrokerStatus

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

the class NamespaceIsolationPoliciesTest method testBrokerAssignment.

@Test
public void testBrokerAssignment() throws Exception {
    NamespaceIsolationPolicies policies = this.getDefaultTestPolicies();
    NamespaceName ns = NamespaceName.get("pulsar/use/testns-1");
    SortedSet<BrokerStatus> primaryCandidates = new TreeSet<>();
    BrokerStatus primary = new BrokerStatus("prod1-broker1.messaging.use.example.com", true, 0);
    BrokerStatus secondary = new BrokerStatus("prod1-broker4.use.example.com", true, 0);
    BrokerStatus shared = new BrokerStatus("use.example.com", true, 0);
    SortedSet<BrokerStatus> secondaryCandidates = new TreeSet<>();
    SortedSet<BrokerStatus> sharedCandidates = new TreeSet<>();
    policies.assignBroker(ns, primary, primaryCandidates, secondaryCandidates, sharedCandidates);
    assertEquals(primaryCandidates.size(), 1);
    assertEquals(secondaryCandidates.size(), 0);
    assertEquals(sharedCandidates.size(), 0);
    assertTrue(primaryCandidates.first().equals(primary));
    policies.assignBroker(ns, secondary, primaryCandidates, secondaryCandidates, sharedCandidates);
    assertEquals(primaryCandidates.size(), 1);
    assertEquals(secondaryCandidates.size(), 1);
    assertEquals(sharedCandidates.size(), 0);
    assertTrue(secondaryCandidates.first().equals(secondary));
    policies.assignBroker(NamespaceName.get("pulsar/use1/testns-1"), shared, primaryCandidates, secondaryCandidates, sharedCandidates);
    assertEquals(primaryCandidates.size(), 1);
    assertEquals(secondaryCandidates.size(), 1);
    assertEquals(sharedCandidates.size(), 1);
    assertTrue(sharedCandidates.first().equals(shared));
}
Also used : NamespaceIsolationPolicies(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) TreeSet(java.util.TreeSet) BrokerStatus(org.apache.pulsar.common.policies.data.BrokerStatus) Test(org.testng.annotations.Test)

Example 2 with BrokerStatus

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

the class NamespaceIsolationPolicyImplTest method testShouldFailover.

@Test
public void testShouldFailover() throws Exception {
    NamespaceIsolationPolicyImpl defaultPolicy = this.getDefaultPolicy();
    SortedSet<BrokerStatus> brokerStatus = new TreeSet<BrokerStatus>();
    for (int i = 0; i < 10; i++) {
        BrokerStatus status = new BrokerStatus(String.format("broker-%d", i), true, i * 10);
        brokerStatus.add(status);
    }
    assertEquals(defaultPolicy.shouldFailover(brokerStatus), false);
    List<BrokerStatus> objList = new ArrayList<BrokerStatus>();
    objList.addAll(brokerStatus);
    for (int i = 0; i < 8; i++) {
        objList.get(i).setActive(false);
    }
    assertEquals(defaultPolicy.shouldFailover(brokerStatus), true);
    objList.get(7).setActive(true);
    assertEquals(defaultPolicy.shouldFailover(brokerStatus), true);
    objList.get(9).setLoadFactor(80);
    assertEquals(defaultPolicy.shouldFailover(brokerStatus), false);
    brokerStatus = new TreeSet<BrokerStatus>();
    for (int i = 0; i < 5; i++) {
        BrokerStatus status = new BrokerStatus(String.format("broker-%d", 2 * i), true, i * 20);
        brokerStatus.add(status);
        status = new BrokerStatus(String.format("broker-%d", 2 * i + 1), true, i * 20);
        brokerStatus.add(status);
    }
    assertEquals(brokerStatus.size(), 10);
}
Also used : NamespaceIsolationPolicyImpl(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BrokerStatus(org.apache.pulsar.common.policies.data.BrokerStatus) Test(org.testng.annotations.Test)

Example 3 with BrokerStatus

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

the class NamespaceIsolationPolicyImplTest method testGetAvailablePrimaryBrokers.

@Test
public void testGetAvailablePrimaryBrokers() throws Exception {
    NamespaceIsolationPolicyImpl defaultPolicy = this.getDefaultPolicy();
    SortedSet<BrokerStatus> brokerStatus = new TreeSet<BrokerStatus>();
    SortedSet<BrokerStatus> expectedAvailablePrimaries = new TreeSet<BrokerStatus>();
    for (int i = 0; i < 10; i++) {
        BrokerStatus status = new BrokerStatus(String.format("prod1-broker%d.messaging.use.example.com", i), i % 2 == 0, i * 10);
        brokerStatus.add(status);
        if (i % 2 == 0) {
            expectedAvailablePrimaries.add(status);
        }
    }
    SortedSet<BrokerStatus> availablePrimaries = defaultPolicy.getAvailablePrimaryBrokers(brokerStatus);
    assertEquals(expectedAvailablePrimaries.size(), availablePrimaries.size());
    for (BrokerStatus bs : availablePrimaries) {
        if (!expectedAvailablePrimaries.contains(bs)) {
            fail("Should not happen");
        }
    }
}
Also used : NamespaceIsolationPolicyImpl(org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl) TreeSet(java.util.TreeSet) BrokerStatus(org.apache.pulsar.common.policies.data.BrokerStatus) Test(org.testng.annotations.Test)

Aggregations

TreeSet (java.util.TreeSet)3 BrokerStatus (org.apache.pulsar.common.policies.data.BrokerStatus)3 Test (org.testng.annotations.Test)3 NamespaceIsolationPolicyImpl (org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicyImpl)2 ArrayList (java.util.ArrayList)1 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)1 NamespaceIsolationPolicies (org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies)1