|
16 | 16 | */ |
17 | 17 | package org.apache.hadoop.yarn.server.federation.policies.router; |
18 | 18 |
|
| 19 | +import static org.apache.hadoop.test.LambdaTestUtils.intercept; |
19 | 20 | import static org.mockito.Mockito.mock; |
20 | 21 | import static org.mockito.Mockito.when; |
21 | 22 |
|
|
24 | 25 |
|
25 | 26 | import org.apache.hadoop.yarn.exceptions.YarnException; |
26 | 27 | import org.apache.hadoop.yarn.server.federation.policies.dao.WeightedPolicyInfo; |
| 28 | +import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException; |
27 | 29 | import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; |
28 | 30 | import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo; |
29 | 31 | import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo; |
@@ -82,4 +84,31 @@ public void testPickLowestWeight() throws YarnException { |
82 | 84 | Assert.assertEquals("sc5", chosen.getId()); |
83 | 85 | } |
84 | 86 |
|
| 87 | + @Test |
| 88 | + public void testZeroSubClustersWithPositiveWeight() throws Exception { |
| 89 | + Map<SubClusterIdInfo, Float> routerWeights = new HashMap<>(); |
| 90 | + Map<SubClusterIdInfo, Float> amrmWeights = new HashMap<>(); |
| 91 | + // Set negative value to all subclusters |
| 92 | + for (int i = 0; i < 5; i++) { |
| 93 | + SubClusterIdInfo sc = new SubClusterIdInfo("sc" + i); |
| 94 | + |
| 95 | + SubClusterInfo sci = mock(SubClusterInfo.class); |
| 96 | + when(sci.getState()).thenReturn(SubClusterState.SC_RUNNING); |
| 97 | + when(sci.getSubClusterId()).thenReturn(sc.toId()); |
| 98 | + getActiveSubclusters().put(sc.toId(), sci); |
| 99 | + routerWeights.put(sc, 0.0f); |
| 100 | + amrmWeights.put(sc, -1.0f); |
| 101 | + } |
| 102 | + getPolicyInfo().setRouterPolicyWeights(routerWeights); |
| 103 | + getPolicyInfo().setAMRMPolicyWeights(amrmWeights); |
| 104 | + FederationPoliciesTestUtil.initializePolicyContext(getPolicy(), |
| 105 | + getPolicyInfo(), getActiveSubclusters()); |
| 106 | + |
| 107 | + intercept(FederationPolicyException.class, |
| 108 | + "No Active Subcluster with weight vector greater than zero", |
| 109 | + () -> ((FederationRouterPolicy) getPolicy()) |
| 110 | + .getHomeSubcluster(getApplicationSubmissionContext(), null)); |
| 111 | + } |
| 112 | + |
| 113 | + |
85 | 114 | } |
0 commit comments