Search in sources :

Example 1 with BrokerStatus

use of com.yahoo.pulsar.common.policies.data.BrokerStatus in project pulsar by yahoo.

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 : TreeSet(java.util.TreeSet) BrokerStatus(com.yahoo.pulsar.common.policies.data.BrokerStatus) Test(org.testng.annotations.Test)

Example 2 with BrokerStatus

use of com.yahoo.pulsar.common.policies.data.BrokerStatus in project pulsar by yahoo.

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 : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BrokerStatus(com.yahoo.pulsar.common.policies.data.BrokerStatus) Test(org.testng.annotations.Test)

Example 3 with BrokerStatus

use of com.yahoo.pulsar.common.policies.data.BrokerStatus in project pulsar by yahoo.

the class NamespaceIsolationPoliciesTest method testBrokerAssignment.

@Test
public void testBrokerAssignment() throws Exception {
    NamespaceIsolationPolicies policies = this.getDefaultTestPolicies();
    NamespaceName ns = new NamespaceName("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(new NamespaceName("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 : NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) TreeSet(java.util.TreeSet) BrokerStatus(com.yahoo.pulsar.common.policies.data.BrokerStatus) Test(org.testng.annotations.Test)

Aggregations

BrokerStatus (com.yahoo.pulsar.common.policies.data.BrokerStatus)3 TreeSet (java.util.TreeSet)3 Test (org.testng.annotations.Test)3 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)1 ArrayList (java.util.ArrayList)1