Search in sources :

Example 11 with SimpleLoadManagerImpl

use of org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl in project incubator-pulsar by apache.

the class SimpleLoadManagerImplTest method testBasicBrokerSelection.

@Test(enabled = true)
public void testBasicBrokerSelection() throws Exception {
    LoadManager loadManager = new SimpleLoadManagerImpl(pulsar1);
    PulsarResourceDescription rd = new PulsarResourceDescription();
    rd.put("memory", new ResourceUsage(1024, 4096));
    rd.put("cpu", new ResourceUsage(10, 100));
    rd.put("bandwidthIn", new ResourceUsage(250 * 1024, 1024 * 1024));
    rd.put("bandwidthOut", new ResourceUsage(550 * 1024, 1024 * 1024));
    ResourceUnit ru1 = new SimpleResourceUnit("http://prod2-broker7.messaging.usw.example.com:8080", rd);
    Set<ResourceUnit> rus = new HashSet<ResourceUnit>();
    rus.add(ru1);
    LoadRanker lr = new ResourceAvailabilityRanker();
    AtomicReference<Map<Long, Set<ResourceUnit>>> sortedRankingsInstance = new AtomicReference<>(Maps.newTreeMap());
    sortedRankingsInstance.get().put(lr.getRank(rd), rus);
    Field sortedRankings = SimpleLoadManagerImpl.class.getDeclaredField("sortedRankings");
    sortedRankings.setAccessible(true);
    sortedRankings.set(loadManager, sortedRankingsInstance);
    Optional<ResourceUnit> res = ((SimpleLoadManagerImpl) loadManager).getLeastLoaded(NamespaceName.get("pulsar/use/primary-ns.10"));
    // broker is not active so found should be null
    assertEquals(res, Optional.empty(), "found a broker when expected none to be found");
}
Also used : PulsarResourceDescription(org.apache.pulsar.broker.loadbalance.impl.PulsarResourceDescription) SystemResourceUsage(org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) ResourceAvailabilityRanker(org.apache.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker) AtomicReference(java.util.concurrent.atomic.AtomicReference) SimpleResourceUnit(org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit) Field(java.lang.reflect.Field) SimpleResourceUnit(org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit) SimpleLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

SimpleLoadManagerImpl (org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl)11 Test (org.testng.annotations.Test)10 Field (java.lang.reflect.Field)8 HashSet (java.util.HashSet)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 PulsarResourceDescription (org.apache.pulsar.broker.loadbalance.impl.PulsarResourceDescription)8 ResourceAvailabilityRanker (org.apache.pulsar.broker.loadbalance.impl.ResourceAvailabilityRanker)8 SimpleResourceUnit (org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit)8 HashMap (java.util.HashMap)7 Map (java.util.Map)6 ResourceUsage (org.apache.pulsar.policies.data.loadbalancer.ResourceUsage)5 SystemResourceUsage (org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage)5 LocalZooKeeperCache (org.apache.pulsar.zookeeper.LocalZooKeeperCache)5 TreeMap (java.util.TreeMap)4 Set (java.util.Set)3 ZooKeeperCache (org.apache.pulsar.zookeeper.ZooKeeperCache)3 ResourceQuota (org.apache.pulsar.common.policies.data.ResourceQuota)2 AtomicIntegerFieldUpdater (java.util.concurrent.atomic.AtomicIntegerFieldUpdater)1 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)1 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)1