ResourceCalculatorProcessTree extends Configured { public static ResourceCalculatorProcessTree getResourceCalculatorProcessTree( String pid, Class<? extends ResourceCalculatorProcessTree> clazz, Configuration conf) { if (clazz != null) { try { Constructor <? extends ResourceCalculatorProcessTree> c = clazz.getConstructor(String.class); ResourceCalculatorProcessTree rctree = c.newInstance(pid); rctree.setConf(conf); rctree.initialize(); return rctree; } catch(Exception e) { throw new RuntimeException(e); } } if (ProcfsBasedProcessTree.isAvailable()) { return new ProcfsBasedProcessTree(pid); } if (WindowsBasedProcessTree.isAvailable()) { return new WindowsBasedProcessTree(pid); } return null; } ResourceCalculatorProcessTree(String root); void initialize(); abstract void updateProcessTree(); abstract String getProcessTreeDump(); long getVirtualMemorySize(); long getRssMemorySize(); long getVirtualMemorySize(int olderThanAge); long getRssMemorySize(int olderThanAge); long getCumulativeCpuTime(); float getCpuUsagePercent(); abstract boolean checkPidPgrpidForMatch(); static ResourceCalculatorProcessTree getResourceCalculatorProcessTree(
    String pid, Class<? extends ResourceCalculatorProcessTree> clazz, Configuration conf); static final int UNAVAILABLE; }
@Test public void testCreateInstance() { ResourceCalculatorProcessTree tree; tree = ResourceCalculatorProcessTree.getResourceCalculatorProcessTree("1", EmptyProcessTree.class, new Configuration()); assertNotNull(tree); assertThat(tree, instanceOf(EmptyProcessTree.class)); }
@Test public void testCreatedInstanceConfigured() { ResourceCalculatorProcessTree tree; Configuration conf = new Configuration(); tree = ResourceCalculatorProcessTree.getResourceCalculatorProcessTree("1", EmptyProcessTree.class, conf); assertNotNull(tree); assertThat(tree.getConf(), sameInstance(conf)); }