private static void testEmulationAccuracy(Configuration conf, FakeHeapUsageEmulatorCore fakeCore, ResourceCalculatorPlugin monitor, ResourceUsageMetrics metrics, TotalHeapUsageEmulatorPlugin heapPlugin, long expectedTotalHeapUsageInMB, long expectedTotalNumCalls) throws Exception { FakeProgressive fakeProgress = new FakeProgressive(); fakeCore.resetFake(); heapPlugin.initialize(conf, metrics, monitor, fakeProgress); int numLoops = 0; while (fakeProgress.getProgress() < 1) { ++numLoops; float progress = numLoops / 100.0F; fakeProgress.setProgress(progress); heapPlugin.emulate(); } // test if the resource plugin shows the expected usage assertEquals("Cumulative heap usage emulator plugin failed (total usage)!", expectedTotalHeapUsageInMB, fakeCore.getHeapUsageInMB(), 1L); // test if the resource plugin shows the expected num calls assertEquals("Cumulative heap usage emulator plugin failed (num calls)!", expectedTotalNumCalls, fakeCore.getNumCalls(), 0L); }
private static void testEmulationBoundary(float progress, FakeHeapUsageEmulatorCore fakeCore, FakeProgressive fakeProgress, TotalHeapUsageEmulatorPlugin heapPlugin, long expectedTotalHeapUsageInMB, long expectedTotalNumCalls, String info) throws Exception { fakeProgress.setProgress(progress); heapPlugin.emulate(); // test heap usage assertEquals("Emulation interval test for heap usage failed " + info + "!", expectedTotalHeapUsageInMB, fakeCore.getHeapUsageInMB(), 0L); // test num calls assertEquals("Emulation interval test for heap usage failed " + info + "!", expectedTotalNumCalls, fakeCore.getNumCalls(), 0L); }