DriverLoadBalancing { public Map<String, String> getLoadBalancingConfigValues() { if (configuration == null) { return Collections.EMPTY_MAP; } LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); algorithm = configuration.getString(ALGORITHM); strategy = configuration.getString(STRATEGY); strategies = getStrategies(); if (isBrokenConfiguration()) { return Collections.EMPTY_MAP; } values.put(JPPFConstants.LOAD_BALANCING_ALGORITHM, algorithm); values.put(JPPFConstants.LOAD_BALANCING_STRATEGY, "cmprofile"); Map<String, String> strategyValues = strategies.get(strategy); for (Map.Entry<String, String> entry : strategyValues.entrySet()) { values.put("strategy.cmprofile." + entry.getKey(), entry.getValue()); } return values; } DriverLoadBalancing(Configuration configuration); Map<String, String> getLoadBalancingConfigValues(); static final String ROOT_KEY; static final String ALGORITHM; static final String STRATEGY; static final String STRATEGIES; }
@Test public void manualStrategy() { driverLoadBalancing = new DriverLoadBalancing(manualLoadBalancingConfig()); Map<String, String> values = driverLoadBalancing.getLoadBalancingConfigValues(); assertThat(values.size(), is(3)); assertThat(values.get(JPPFConstants.LOAD_BALANCING_ALGORITHM), equalTo("manual")); assertThat(values.get(JPPFConstants.LOAD_BALANCING_STRATEGY), equalTo("cmprofile")); assertThat(values.get("strategy.cmprofile.size"), equalTo("10")); }
@Test public void strategyNotInStrategies() { driverLoadBalancing = new DriverLoadBalancing(strategyNotInStrategiesConfig()); Map<String, String> values = driverLoadBalancing.getLoadBalancingConfigValues(); assertThat(values.isEmpty(), is(true)); }
@Test public void algorithmMissing() { driverLoadBalancing = new DriverLoadBalancing(algorithmMissingConfig()); Map<String, String> values = driverLoadBalancing.getLoadBalancingConfigValues(); assertThat(values.isEmpty(), is(true)); }
@Test public void strategyMissing() { driverLoadBalancing = new DriverLoadBalancing(strategyMissingConfig()); Map<String, String> values = driverLoadBalancing.getLoadBalancingConfigValues(); assertThat(values.isEmpty(), is(true)); }
@Test public void nullConfiguration() { driverLoadBalancing = new DriverLoadBalancing(null); Map<String, String> values = driverLoadBalancing.getLoadBalancingConfigValues(); assertThat(values.isEmpty(), is(true)); }