|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with this |
| 4 | + * work for additional information regarding copyright ownership. The ASF |
| 5 | + * licenses this file to you under the Apache License, Version 2.0 (the |
| 6 | + * "License"); you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | + * License for the specific language governing permissions and limitations under |
| 15 | + * the License. |
| 16 | + */ |
| 17 | +package org.apache.hadoop.yarn.server.federation.policies.manager; |
| 18 | + |
| 19 | +import org.apache.hadoop.yarn.server.federation.policies.amrmproxy.HomeAMRMProxyPolicy; |
| 20 | +import org.apache.hadoop.yarn.server.federation.policies.dao.WeightedPolicyInfo; |
| 21 | +import org.apache.hadoop.yarn.server.federation.policies.router.WeightedRandomRouterPolicy; |
| 22 | +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; |
| 23 | +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo; |
| 24 | +import org.junit.Assert; |
| 25 | +import org.junit.Before; |
| 26 | +import org.junit.Test; |
| 27 | + |
| 28 | +import java.util.HashMap; |
| 29 | +import java.util.Map; |
| 30 | + |
| 31 | +public class TestWeightedHomePolicyManager extends BasePolicyManagerTest { |
| 32 | + private WeightedPolicyInfo policyInfo; |
| 33 | + |
| 34 | + @Before |
| 35 | + public void setup() { |
| 36 | + // configure a policy |
| 37 | + WeightedHomePolicyManager whpm = new WeightedHomePolicyManager(); |
| 38 | + whpm.setQueue("queue1"); |
| 39 | + |
| 40 | + SubClusterId sc1 = SubClusterId.newInstance("sc1"); |
| 41 | + policyInfo = new WeightedPolicyInfo(); |
| 42 | + Map<SubClusterIdInfo, Float> routerWeights = new HashMap<>(); |
| 43 | + routerWeights.put(new SubClusterIdInfo(sc1), 0.2f); |
| 44 | + policyInfo.setRouterPolicyWeights(routerWeights); |
| 45 | + |
| 46 | + whpm.setWeightedPolicyInfo(policyInfo); |
| 47 | + this.wfp = whpm; |
| 48 | + |
| 49 | + //set expected params that the base test class will use for tests |
| 50 | + expectedPolicyManager = WeightedHomePolicyManager.class; |
| 51 | + expectedAMRMProxyPolicy = HomeAMRMProxyPolicy.class; |
| 52 | + expectedRouterPolicy = WeightedRandomRouterPolicy.class; |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testPolicyInfoSetCorrectly() throws Exception { |
| 57 | + serializeAndDeserializePolicyManager(wfp, expectedPolicyManager, |
| 58 | + expectedAMRMProxyPolicy, expectedRouterPolicy); |
| 59 | + // check the policyInfo propagates through ser/der correctly |
| 60 | + Assert.assertEquals(((WeightedHomePolicyManager) wfp) |
| 61 | + .getWeightedPolicyInfo(), policyInfo); |
| 62 | + } |
| 63 | +} |
0 commit comments