Queue implements Comparable<Queue> { Queue() { } Queue();   Queue(String name, Map<String, AccessControlList> acls, QueueState state); @Override int compareTo(Queue queue); @Override boolean equals(Object o); @Override String toString(); @Override int hashCode();  }
@Test (timeout=5000) public void testQueue() throws IOException { File f = null; try { f = writeFile(); QueueManager manager = new QueueManager(f.getCanonicalPath(), true); manager.setSchedulerInfo("first", "queueInfo"); manager.setSchedulerInfo("second", "queueInfoqueueInfo"); Queue root = manager.getRoot(); assertThat(root.getChildren().size()).isEqualTo(2); Iterator<Queue> iterator = root.getChildren().iterator(); Queue firstSubQueue = iterator.next(); assertEquals("first", firstSubQueue.getName()); assertEquals( firstSubQueue.getAcls().get("mapred.queue.first.acl-submit-job") .toString(), "Users [user1, user2] and members of the groups [group1, group2] are allowed"); Queue secondSubQueue = iterator.next(); assertEquals("second", secondSubQueue.getName()); assertThat(secondSubQueue.getProperties().getProperty("key")) .isEqualTo("value"); assertThat(secondSubQueue.getProperties().getProperty("key1")) .isEqualTo("value1"); assertThat(firstSubQueue.getState().getStateName()) .isEqualTo("running"); assertThat(secondSubQueue.getState().getStateName()) .isEqualTo("stopped"); Set<String> template = new HashSet<String>(); template.add("first"); template.add("second"); assertEquals(manager.getLeafQueueNames(), template); UserGroupInformation mockUGI = mock(UserGroupInformation.class); when(mockUGI.getShortUserName()).thenReturn("user1"); String[] groups = { "group1" }; when(mockUGI.getGroupNames()).thenReturn(groups); assertTrue(manager.hasAccess("first", QueueACL.SUBMIT_JOB, mockUGI)); assertFalse(manager.hasAccess("second", QueueACL.SUBMIT_JOB, mockUGI)); assertFalse(manager.hasAccess("first", QueueACL.ADMINISTER_JOBS, mockUGI)); when(mockUGI.getShortUserName()).thenReturn("user3"); assertTrue(manager.hasAccess("first", QueueACL.ADMINISTER_JOBS, mockUGI)); QueueAclsInfo[] qai = manager.getQueueAcls(mockUGI); assertThat(qai.length).isEqualTo(1); manager.refreshQueues(getConfiguration(), null); iterator = root.getChildren().iterator(); Queue firstSubQueue1 = iterator.next(); Queue secondSubQueue1 = iterator.next(); assertThat(firstSubQueue).isEqualTo(firstSubQueue1); assertThat(firstSubQueue1.getState().getStateName()) .isEqualTo("running"); assertThat(secondSubQueue1.getState().getStateName()) .isEqualTo("stopped"); assertThat(firstSubQueue1.getSchedulingInfo()) .isEqualTo("queueInfo"); assertThat(secondSubQueue1.getSchedulingInfo()) .isEqualTo("queueInfoqueueInfo"); assertThat(firstSubQueue.getJobQueueInfo().getQueueName()) .isEqualTo("first"); assertThat(firstSubQueue.getJobQueueInfo().getState().toString()) .isEqualTo("running"); assertThat(firstSubQueue.getJobQueueInfo().getSchedulingInfo()) .isEqualTo("queueInfo"); assertThat(secondSubQueue.getJobQueueInfo().getChildren().size()) .isEqualTo(0); assertThat(manager.getSchedulerInfo("first")).isEqualTo("queueInfo"); Set<String> queueJobQueueInfos = new HashSet<String>(); for(JobQueueInfo jobInfo : manager.getJobQueueInfos()){ queueJobQueueInfos.add(jobInfo.getQueueName()); } Set<String> rootJobQueueInfos = new HashSet<String>(); for(Queue queue : root.getChildren()){ rootJobQueueInfos.add(queue.getJobQueueInfo().getQueueName()); } assertEquals(queueJobQueueInfos, rootJobQueueInfos); assertThat(manager.getJobQueueInfoMapping().get("first").getQueueName()) .isEqualTo("first"); Writer writer = new StringWriter(); Configuration conf = getConfiguration(); conf.unset(DeprecatedQueueConfigurationParser.MAPRED_QUEUE_NAMES_KEY); QueueManager.dumpConfiguration(writer, f.getAbsolutePath(), conf); String result = writer.toString(); assertTrue(result .indexOf("\"name\":\"first\",\"state\":\"running\",\"acl_submit_job\":\"user1,user2 group1,group2\",\"acl_administer_jobs\":\"user3,user4 group3,group4\",\"properties\":[],\"children\":[]") > 0); writer = new StringWriter(); QueueManager.dumpConfiguration(writer, conf); result = writer.toString(); assertTrue(result.contains("{\"queues\":[{\"name\":\"default\",\"state\":\"running\",\"acl_submit_job\":\"*\",\"acl_administer_jobs\":\"*\",\"properties\":[],\"children\":[]},{\"name\":\"q1\",\"state\":\"running\",\"acl_submit_job\":\" \",\"acl_administer_jobs\":\" \",\"properties\":[],\"children\":[{\"name\":\"q1:q2\",\"state\":\"running\",\"acl_submit_job\":\" \",\"acl_administer_jobs\":\" \",\"properties\":[")); assertTrue(result.contains("{\"key\":\"capacity\",\"value\":\"20\"}")); assertTrue(result.contains("{\"key\":\"user-limit\",\"value\":\"30\"}")); assertTrue(result.contains("],\"children\":[]}]}]}")); QueueAclsInfo qi = new QueueAclsInfo(); assertNull(qi.getQueueName()); } finally { if (f != null) { f.delete(); } } }
@Test (timeout=5000) public void testQueue() throws IOException { File f = null; try { f = writeFile(); QueueManager manager = new QueueManager(f.getCanonicalPath(), true); manager.setSchedulerInfo("first", "queueInfo"); manager.setSchedulerInfo("second", "queueInfoqueueInfo"); Queue root = manager.getRoot(); assertTrue(root.getChildren().size() == 2); Iterator<Queue> iterator = root.getChildren().iterator(); Queue firstSubQueue = iterator.next(); assertTrue(firstSubQueue.getName().equals("first")); assertEquals( firstSubQueue.getAcls().get("mapred.queue.first.acl-submit-job") .toString(), "Users [user1, user2] and members of the groups [group1, group2] are allowed"); Queue secondSubQueue = iterator.next(); assertTrue(secondSubQueue.getName().equals("second")); assertEquals(secondSubQueue.getProperties().getProperty("key"), "value"); assertEquals(secondSubQueue.getProperties().getProperty("key1"), "value1"); assertEquals(firstSubQueue.getState().getStateName(), "running"); assertEquals(secondSubQueue.getState().getStateName(), "stopped"); Set<String> template = new HashSet<String>(); template.add("first"); template.add("second"); assertEquals(manager.getLeafQueueNames(), template); UserGroupInformation mockUGI = mock(UserGroupInformation.class); when(mockUGI.getShortUserName()).thenReturn("user1"); String[] groups = { "group1" }; when(mockUGI.getGroupNames()).thenReturn(groups); assertTrue(manager.hasAccess("first", QueueACL.SUBMIT_JOB, mockUGI)); assertFalse(manager.hasAccess("second", QueueACL.SUBMIT_JOB, mockUGI)); assertFalse(manager.hasAccess("first", QueueACL.ADMINISTER_JOBS, mockUGI)); when(mockUGI.getShortUserName()).thenReturn("user3"); assertTrue(manager.hasAccess("first", QueueACL.ADMINISTER_JOBS, mockUGI)); QueueAclsInfo[] qai = manager.getQueueAcls(mockUGI); assertEquals(qai.length, 1); manager.refreshQueues(getConfiguration(), null); iterator = root.getChildren().iterator(); Queue firstSubQueue1 = iterator.next(); Queue secondSubQueue1 = iterator.next(); assertTrue(firstSubQueue.equals(firstSubQueue1)); assertEquals(firstSubQueue1.getState().getStateName(), "running"); assertEquals(secondSubQueue1.getState().getStateName(), "stopped"); assertEquals(firstSubQueue1.getSchedulingInfo(), "queueInfo"); assertEquals(secondSubQueue1.getSchedulingInfo(), "queueInfoqueueInfo"); assertEquals(firstSubQueue.getJobQueueInfo().getQueueName(), "first"); assertEquals(firstSubQueue.getJobQueueInfo().getQueueState(), "running"); assertEquals(firstSubQueue.getJobQueueInfo().getSchedulingInfo(), "queueInfo"); assertEquals(secondSubQueue.getJobQueueInfo().getChildren().size(), 0); assertEquals(manager.getSchedulerInfo("first"), "queueInfo"); Set<String> queueJobQueueInfos = new HashSet<String>(); for(JobQueueInfo jobInfo : manager.getJobQueueInfos()){ queueJobQueueInfos.add(jobInfo.getQueueName()); } Set<String> rootJobQueueInfos = new HashSet<String>(); for(Queue queue : root.getChildren()){ rootJobQueueInfos.add(queue.getJobQueueInfo().getQueueName()); } assertEquals(queueJobQueueInfos, rootJobQueueInfos); assertEquals( manager.getJobQueueInfoMapping().get("first").getQueueName(), "first"); Writer writer = new StringWriter(); Configuration conf = getConfiguration(); conf.unset(DeprecatedQueueConfigurationParser.MAPRED_QUEUE_NAMES_KEY); QueueManager.dumpConfiguration(writer, f.getAbsolutePath(), conf); String result = writer.toString(); assertTrue(result .indexOf("\"name\":\"first\",\"state\":\"running\",\"acl_submit_job\":\"user1,user2 group1,group2\",\"acl_administer_jobs\":\"user3,user4 group3,group4\",\"properties\":[],\"children\":[]") > 0); writer = new StringWriter(); QueueManager.dumpConfiguration(writer, conf); result = writer.toString(); assertEquals( "{\"queues\":[{\"name\":\"default\",\"state\":\"running\",\"acl_submit_job\":\"*\",\"acl_administer_jobs\":\"*\",\"properties\":[],\"children\":[]},{\"name\":\"q1\",\"state\":\"running\",\"acl_submit_job\":\" \",\"acl_administer_jobs\":\" \",\"properties\":[],\"children\":[{\"name\":\"q1:q2\",\"state\":\"running\",\"acl_submit_job\":\" \",\"acl_administer_jobs\":\" \",\"properties\":[{\"key\":\"capacity\",\"value\":\"20\"},{\"key\":\"user-limit\",\"value\":\"30\"}],\"children\":[]}]}]}", result); QueueAclsInfo qi = new QueueAclsInfo(); assertNull(qi.getQueueName()); } finally { if (f != null) { f.delete(); } } }