QueuePlacementPolicy { public String assignAppToQueue(String requestedQueue, String user) throws IOException { for (QueuePlacementRule rule : rules) { String queue = rule.assignAppToQueue(requestedQueue, user, groups, configuredQueues); if (queue == null || !queue.isEmpty()) { return queue; } } throw new IllegalStateException("Should have applied a rule before " + "reaching here"); } QueuePlacementPolicy(List<QueuePlacementRule> rules,
      Set<String> configuredQueues, Configuration conf); static QueuePlacementPolicy fromXml(Element el, Set<String> configuredQueues,
      Configuration conf); static QueuePlacementPolicy fromConfiguration(Configuration conf,
      Set<String> configuredQueues); String assignAppToQueue(String requestedQueue, String user); List<QueuePlacementRule> getRules();  }
@Test public void testSpecifiedUserPolicy() throws Exception { StringBuffer sb = new StringBuffer(); sb.append("<queuePlacementPolicy>"); sb.append(" <rule name='specified' />"); sb.append(" <rule name='user' />"); sb.append("</queuePlacementPolicy>"); QueuePlacementPolicy policy = parse(sb.toString()); assertEquals("root.specifiedq",policy.assignAppToQueue("specifiedq", "someuser")); assertEquals("root.someuser", policy.assignAppToQueue("default", "someuser")); assertEquals("root.otheruser", policy.assignAppToQueue("default", "otheruser")); }
@Test public void testNoCreate() throws Exception { StringBuffer sb = new StringBuffer(); sb.append("<queuePlacementPolicy>"); sb.append(" <rule name='specified' />"); sb.append(" <rule name='user' create=\"false\" />"); sb.append(" <rule name='default' />"); sb.append("</queuePlacementPolicy>"); QueuePlacementPolicy policy = parse(sb.toString()); assertEquals("root.specifiedq", policy.assignAppToQueue("specifiedq", "someuser")); assertEquals("root.someuser", policy.assignAppToQueue("default", "someuser")); assertEquals("root.specifiedq", policy.assignAppToQueue("specifiedq", "otheruser")); assertEquals("root.default", policy.assignAppToQueue("default", "otheruser")); }
@Test public void testSpecifiedThenReject() throws Exception { StringBuffer sb = new StringBuffer(); sb.append("<queuePlacementPolicy>"); sb.append(" <rule name='specified' />"); sb.append(" <rule name='reject' />"); sb.append("</queuePlacementPolicy>"); QueuePlacementPolicy policy = parse(sb.toString()); assertEquals("root.specifiedq", policy.assignAppToQueue("specifiedq", "someuser")); assertEquals(null, policy.assignAppToQueue("default", "someuser")); }