/**
* Test {@link ResourceUsageMatcher}.
*/
@Test
public void testResourceUsageMatcher() throws Exception {
ResourceUsageMatcher matcher = new ResourceUsageMatcher();
Configuration conf = new Configuration();
conf.setClass(ResourceUsageMatcher.RESOURCE_USAGE_EMULATION_PLUGINS,
TestResourceUsageEmulatorPlugin.class,
ResourceUsageEmulatorPlugin.class);
long currentTime = System.currentTimeMillis();
matcher.configure(conf, null, null, null);
matcher.matchResourceUsage();
String id = TestResourceUsageEmulatorPlugin.DEFAULT_IDENTIFIER;
long result =
TestResourceUsageEmulatorPlugin.testInitialization(id, conf);
assertTrue("Resource usage matcher failed to initialize the configured"
+ " plugin", result > currentTime);
result = TestResourceUsageEmulatorPlugin.testEmulation(id, conf);
assertTrue("Resource usage matcher failed to load and emulate the"
+ " configured plugin", result > currentTime);
// test plugin order to first emulate cpu and then others
conf.setStrings(ResourceUsageMatcher.RESOURCE_USAGE_EMULATION_PLUGINS,
TestCpu.class.getName() + "," + TestOthers.class.getName());
matcher.configure(conf, null, null, null);
// test the initialization order
long time1 =
TestResourceUsageEmulatorPlugin.testInitialization(TestCpu.ID, conf);
long time2 =
TestResourceUsageEmulatorPlugin.testInitialization(TestOthers.ID,
conf);
assertTrue("Resource usage matcher failed to initialize the configured"
+ " plugins in order", time1 < time2);
matcher.matchResourceUsage();
// Note that the cpu usage emulator plugin is configured 1st and then the
// others plugin.
time1 =
TestResourceUsageEmulatorPlugin.testInitialization(TestCpu.ID, conf);