YARN-9054. Fix FederationStateStoreFacade#buildGetSubClustersCacheRequest. Contributed by Bibin A Chundatt.

This commit is contained in:
Giovanni Matteo Fumarola 2018-11-26 10:57:38 -08:00
parent a9d96948ed
commit 0d8406135f
3 changed files with 21 additions and 3 deletions

View File

@ -463,8 +463,9 @@ public final class FederationStateStoreFacade {
private Object buildGetSubClustersCacheRequest( private Object buildGetSubClustersCacheRequest(
final boolean filterInactiveSubClusters) { final boolean filterInactiveSubClusters) {
final String cacheKey = buildCacheKey(getClass().getSimpleName(), final String cacheKey =
GET_SUBCLUSTERS_CACHEID, null); buildCacheKey(getClass().getSimpleName(), GET_SUBCLUSTERS_CACHEID,
Boolean.toString(filterInactiveSubClusters));
CacheRequest<String, Map<SubClusterId, SubClusterInfo>> cacheRequest = CacheRequest<String, Map<SubClusterId, SubClusterInfo>> cacheRequest =
new CacheRequest<String, Map<SubClusterId, SubClusterInfo>>(cacheKey, new CacheRequest<String, Map<SubClusterId, SubClusterInfo>>(cacheKey,
new Func<String, Map<SubClusterId, SubClusterInfo>>() { new Func<String, Map<SubClusterId, SubClusterInfo>>() {

View File

@ -172,7 +172,7 @@ public class FederationStateStoreTestUtil {
} }
} }
private void deRegisterSubCluster(SubClusterId subClusterId) public void deRegisterSubCluster(SubClusterId subClusterId)
throws YarnException { throws YarnException {
stateStore.deregisterSubCluster(SubClusterDeregisterRequest stateStore.deregisterSubCluster(SubClusterDeregisterRequest
.newInstance(subClusterId, SubClusterState.SC_UNREGISTERED)); .newInstance(subClusterId, SubClusterState.SC_UNREGISTERED));

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.server.federation.utils; package org.apache.hadoop.yarn.server.federation.utils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
@ -135,6 +136,22 @@ public class TestFederationStateStoreFacade {
} }
} }
@Test
public void testSubClustersCache() throws YarnException {
Map<SubClusterId, SubClusterInfo> allClusters =
facade.getSubClusters(false);
Assert.assertEquals(numSubClusters, allClusters.size());
SubClusterId clusterId = new ArrayList<>(allClusters.keySet()).get(0);
// make one subcluster down unregister
stateStoreTestUtil.deRegisterSubCluster(clusterId);
Map<SubClusterId, SubClusterInfo> activeClusters =
facade.getSubClusters(true);
Assert.assertEquals(numSubClusters - 1, activeClusters.size());
// Recheck false case.
allClusters = facade.getSubClusters(false);
Assert.assertEquals(numSubClusters, allClusters.size());
}
@Test @Test
public void testInvalidGetPolicyConfiguration() throws YarnException { public void testInvalidGetPolicyConfiguration() throws YarnException {
Assert.assertNull( Assert.assertNull(