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));
}
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);
}
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");
}
}
}
Aggregations