riMap = new HashMap<>();
+ String RESOURCE_1 = "res1";
+
+ // Initialize mandatory resources
+ ResourceInformation memory = ResourceInformation.newInstance(
+ ResourceInformation.MEMORY_MB.getName(),
+ ResourceInformation.MEMORY_MB.getUnits(),
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB);
+ ResourceInformation vcores = ResourceInformation.newInstance(
+ ResourceInformation.VCORES.getName(),
+ ResourceInformation.VCORES.getUnits(),
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES,
+ YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES);
+ riMap.put(ResourceInformation.MEMORY_URI, memory);
+ riMap.put(ResourceInformation.VCORES_URI, vcores);
+ riMap.put(RESOURCE_1, ResourceInformation.newInstance(RESOURCE_1, "", 0,
+ ResourceTypes.COUNTABLE, 0, Integer.MAX_VALUE));
+
+ ResourceUtils.initializeResourcesFromResourceInformationMap(riMap);
+
+ /**
+ * Queue structure is:
+ *
+ *
+ * root
+ * / \
+ * a b
+ * / \ / \
+ * a1 a2 b1 b2
+ *
+ *
+ * a1 and b2 are using most of resources.
+ * a2 and b1 needs more resources. Both are under served.
+ * hence demand will consider both queue's need while trying to
+ * do preemption.
+ */
+ String labelsConfig =
+ "=100,true;";
+ String nodesConfig =
+ "n1=;"; // n1 is default partition
+ String queuesConfig =
+ // guaranteed,max,used,pending
+ "root(=[100:100:10 100:100:10 100:100:10 100:100:10]);" + //root
+ "-a(=[50:80:4 100:100:10 80:90:10 30:20:4]);" + // a
+ "--a1(=[25:30:2 100:50:10 80:90:10 0]);" + // a1
+ "--a2(=[25:50:2 100:50:10 0 30:20:4]);" + // a2
+ "-b(=[50:20:6 100:100:10 20:10 40:50:8]);" + // b
+ "--b1(=[25:5:4 100:20:10 0 20:10:4]);" + // b1
+ "--b2(=[25:15:2 100:20:10 20:10 20:10:4])"; // b2
+ String appsConfig=
+ //queueName\t(priority,resource,host,expression,#repeat,reserved)
+ "a1\t" // app1 in a1
+ + "(1,8:9:1,n1,,10,false);" +
+ "b2\t" // app2 in b2
+ + "(1,2:1,n1,,10,false)"; // 80 of y
+
+ buildEnv(labelsConfig, nodesConfig, queuesConfig, appsConfig);
+ policy.editSchedule();
+
+ verify(mDisp, times(7)).handle(
+ argThat(new IsPreemptionRequestFor(getAppAttemptId(1))));
+
+ riMap.remove(RESOURCE_1);
+ ResourceUtils.initializeResourcesFromResourceInformationMap(riMap);
+ }
}