Search in sources :

Example 1 with LeastLongTermMessageRate

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

the class ModularLoadManagerStrategyTest method testLeastLongTermMessageRate.

// Test that least long term message rate works correctly.
@Test
public void testLeastLongTermMessageRate() {
    BundleData bundleData = new BundleData();
    BrokerData brokerData1 = initBrokerData();
    BrokerData brokerData2 = initBrokerData();
    BrokerData brokerData3 = initBrokerData();
    brokerData1.getTimeAverageData().setLongTermMsgRateIn(100);
    brokerData2.getTimeAverageData().setLongTermMsgRateIn(200);
    brokerData3.getTimeAverageData().setLongTermMsgRateIn(300);
    LoadData loadData = new LoadData();
    Map<String, BrokerData> brokerDataMap = loadData.getBrokerData();
    brokerDataMap.put("1", brokerData1);
    brokerDataMap.put("2", brokerData2);
    brokerDataMap.put("3", brokerData3);
    ServiceConfiguration conf = new ServiceConfiguration();
    ModularLoadManagerStrategy strategy = new LeastLongTermMessageRate(conf);
    assertEquals(strategy.selectBroker(brokerDataMap.keySet(), bundleData, loadData, conf), Optional.of("1"));
    brokerData1.getTimeAverageData().setLongTermMsgRateIn(400);
    assertEquals(strategy.selectBroker(brokerDataMap.keySet(), bundleData, loadData, conf), Optional.of("2"));
    brokerData2.getLocalData().setCpu(new ResourceUsage(90, 100));
    assertEquals(strategy.selectBroker(brokerDataMap.keySet(), bundleData, loadData, conf), Optional.of("3"));
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) BrokerData(org.apache.pulsar.broker.BrokerData) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) TimeAverageBrokerData(org.apache.pulsar.broker.TimeAverageBrokerData) ResourceUsage(org.apache.pulsar.policies.data.loadbalancer.ResourceUsage) LeastLongTermMessageRate(org.apache.pulsar.broker.loadbalance.impl.LeastLongTermMessageRate) BundleData(org.apache.pulsar.broker.BundleData) Test(org.testng.annotations.Test)

Aggregations

BrokerData (org.apache.pulsar.broker.BrokerData)1 BundleData (org.apache.pulsar.broker.BundleData)1 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)1 TimeAverageBrokerData (org.apache.pulsar.broker.TimeAverageBrokerData)1 LeastLongTermMessageRate (org.apache.pulsar.broker.loadbalance.impl.LeastLongTermMessageRate)1 LocalBrokerData (org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData)1 ResourceUsage (org.apache.pulsar.policies.data.loadbalancer.ResourceUsage)1 Test (org.testng.annotations.Test)1