MappingRuleValidationContextImpl implements MappingRuleValidationContext { public void addVariable(String variable) throws YarnException { if (immutableVariables.contains(variable)) { throw new YarnException("Variable '" + variable + "' is immutable " + "cannot add to the modified variable list."); } knownVariables.add(variable); } MappingRuleValidationContextImpl(CapacitySchedulerQueueManager qm); boolean validateQueuePath(String queuePath); boolean isPathStatic(String queuePath); void addVariable(String variable); void addImmutableVariable(String variable); Set<String> getVariables();  }
@Test public void testDynamicQueueValidation() { CapacitySchedulerQueueManager qm = mock(CapacitySchedulerQueueManager.class); MockQueueHierarchyBuilder.create() .withQueueManager(qm) .withQueue("root.unmanaged") .withManagedParentQueue("root.managed") .withQueue("root.unmanagedwithchild.child") .withQueue("root.leaf") .build(); when(qm.getQueue(isNull())).thenReturn(null); MappingRuleValidationContextImpl ctx = new MappingRuleValidationContextImpl(qm); try { ctx.addVariable("%dynamic"); ctx.addVariable("%user"); } catch (YarnException e) { fail("We don't expect the add variable to fail: " + e.getMessage()); } assertValidPath(ctx, "%dynamic"); assertValidPath(ctx, "root.%dynamic"); assertValidPath(ctx, "%user.%dynamic"); assertValidPath(ctx, "root.managed.%dynamic"); assertValidPath(ctx, "managed.%dynamic"); assertInvalidPath(ctx, "root.invalid.%dynamic"); assertInvalidPath(ctx, "root.umanaged.%dynamic"); assertValidPath(ctx, "root.unmanagedwithchild.%user"); assertValidPath(ctx, "unmanagedwithchild.%user"); }