@Override protected void onTerminating() { this.monitoringController.terminateMonitoring(); try { this.monitoringController.waitForTermination(WAIT_TIMEOUT_IN_MS); } catch (final InterruptedException e) { throw new IllegalStateException(e); } finally { super.onTerminating(); } } }
/** * Test if enabling of a terminated controller fails (as expected). */ @Test public void testMonitoringTerminatedToEnabledMustFail() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Change to terminated Assert.assertTrue("Failed to enableMonitoring", kieker.enableMonitoring()); kieker.terminateMonitoring(); Assert.assertFalse("Must not transition from terminated to enabled", kieker.enableMonitoring()); kieker.terminateMonitoring(); }
/** * Test if disabling of a terminated controller fails (as expected). */ @Test public void testMonitoringTerminatedToDisabledMustFail() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Change to terminated Assert.assertTrue("Failed to disableMonitoring", kieker.disableMonitoring()); kieker.terminateMonitoring(); Assert.assertTrue("Transition to Disabled is always possible", kieker.disableMonitoring()); kieker.terminateMonitoring(); } }
Assert.assertEquals("Unexpected number of triggering events before removal", 3, numEventsAfterRemoval); monitoringController.terminateMonitoring();
/** * Test if terminating an enabled controller works. */ @Test public void testMonitoringEnabledToTerminated() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); configuration.setProperty(ConfigurationKeys.MONITORING_ENABLED, "true"); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Change to terminated kieker.terminateMonitoring(); // Check values when terminated Assert.assertEquals("Unexpected monitoringEnabled value", false, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", true, kieker.isMonitoringTerminated()); kieker.terminateMonitoring(); }
@Test public void testDeactivationAndReactivation() throws InterruptedException { final long period = 1500; // 1500 ms final long offset = 300; // i.e., 1st event after 300 ms final ISigarSamplerFactory sigarFactory = SigarSamplerFactory.INSTANCE; final MemSwapUsageSampler sampler = sigarFactory.createSensorMemSwapUsage(); this.monitoringController.schedulePeriodicSampler(sampler, offset, period, TimeUnit.MILLISECONDS); Thread.sleep(3600); // sleep 3.6 seconds // Expecting sampling trigger events at milliseconds 300, 1800, 3300 final int numEventsBeforeDisabled = this.recordListFilledByListWriter.size(); final String pattern = SignatureFactory.createMemSwapSignature(); this.monitoringController.deactivateProbe(pattern); Thread.sleep(2000); // sleep 2 seconds while being disabled // There should be no new trigger events final int numEventsWhileDisabled = this.recordListFilledByListWriter.size() - numEventsBeforeDisabled; this.monitoringController.activateProbe(pattern); Thread.sleep(2000); // sleep 2 seconds while being re-enabled // There should be at least one new trigger event final int numEventsAfterReEnabled = this.recordListFilledByListWriter.size() - numEventsBeforeDisabled; final boolean isInstanceOf = this.recordListFilledByListWriter.get(0) instanceof MemSwapUsageRecord; Assert.assertTrue("Unexpected instance of IMonitoringRecord", isInstanceOf); Assert.assertEquals("Unexpected number of triggering events before disabling", 3, numEventsBeforeDisabled); Assert.assertEquals("Unexpected number of triggering events while disabled", 0, numEventsWhileDisabled); Assert.assertTrue("Unexpected at least one triggering events after being re-enabled. Found " + numEventsAfterReEnabled, numEventsAfterReEnabled > 0); // NOCS (MagicNumberCheck) this.monitoringController.terminateMonitoring(); }
/** * Test if terminating an disabled controller works. */ @Test public void testMonitoringDisabledToTerminated() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); configuration.setProperty(ConfigurationKeys.MONITORING_ENABLED, "false"); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Change to terminated kieker.terminateMonitoring(); { // Check values when terminated // NOCS Assert.assertEquals("Unexpected monitoringEnabled value", false, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", true, kieker.isMonitoringTerminated()); } kieker.terminateMonitoring(); }
@Override protected void checkControllerStateAfterRecordsPassedToController(final IMonitoringController monitoringController) throws Exception { Assert.assertTrue(monitoringController.isMonitoringEnabled()); monitoringController.terminateMonitoring(); this.analysisThread.awaitTermination(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, this.analysisController.getState()); }
@Override protected void checkControllerStateAfterRecordsPassedToController(final IMonitoringController monitoringController) throws Exception { Assert.assertTrue(monitoringController.isMonitoringEnabled()); monitoringController.terminateMonitoring(); this.analysisThread.awaitTermination(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, this.analysisController.getState()); }
@Override protected void checkControllerStateAfterRecordsPassedToController(final IMonitoringController monitoringController) throws Exception { Assert.assertTrue(monitoringController.isMonitoringEnabled()); monitoringController.terminateMonitoring(); this.analysisThread.awaitTermination(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, this.analysisController.getState()); }
@Test public void testMultipleRecords() throws InterruptedException { final String testId = "testMultipleRecords"; final int recordCount = 15; final int taskRunInterval = 10; final int deferredWriteDelay = 50; final IMonitoringController controller = this.createController(testId, taskRunInterval, deferredWriteDelay); for (int recordIndex = 0; recordIndex < recordCount; recordIndex++) { final OperationExecutionRecord record = new OperationExecutionRecord("operation()", "SESS-ID", 0, recordIndex, recordIndex, "hostname", recordIndex, 1); controller.newMonitoringRecord(record); } // Terminate monitoring controller.terminateMonitoring(); controller.waitForTermination(2000); // Retrieve written data from the data storage final byte[] data = TestRawDataStorage.getInstance().getData(testId); // Check some basic numbers, since full decoding is not yet supported final ByteBuffer dataBuffer = ByteBuffer.wrap(data); // Read the string table offset (last four bytes), plus 8 bytes for the container header dataBuffer.position(data.length - 4); final int stringTableOffset = dataBuffer.getInt() + 8; // Read the number of strings in the string table dataBuffer.position(stringTableOffset); final int numberOfStrings = VariableLengthEncoding.decodeInt(dataBuffer); // Check the size of the string table Assert.assertEquals(9, numberOfStrings); }
/** * Test if the default configuration for adaptive monitoring really has an empty probe pattern. */ @Test public void testInitializationDefaultConfigLocation() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "true"); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); Assert.assertFalse(ctrl.isMonitoringTerminated()); final List<String> list = ctrl.getProbePatternList(); Assert.assertTrue(list.isEmpty()); ctrl.terminateMonitoring(); }
/** * Test the adaptive pattern registry by adding test patterns. * * @throws UnsupportedEncodingException * when UTF-8 encoding is not supported * @throws FileNotFoundException * when file creation fails * @throws InterruptedException * when the sleep call was interrupted */ @Test public void testInitializationWithCustomConfiguration() throws UnsupportedEncodingException, FileNotFoundException, InterruptedException { this.writeToConfigFile(new String[] { "+ *", "- * test.Test()", "test invalid line in config file", "- InvalidPatternException expected", }); final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "true"); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_CONFIG_FILE, this.configFile.getAbsolutePath()); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); Assert.assertTrue(this.configFile.exists()); final List<String> list = ctrl.getProbePatternList(); Assert.assertFalse(list.isEmpty()); Assert.assertArrayEquals(new String[] { "+*", "-* test.Test()", }, list.toArray()); // add manual entries to list ctrl.activateProbe("void test.$1.Test()"); final List<String> list2 = ctrl.getProbePatternList(); Assert.assertArrayEquals(new String[] { "+*", "-* test.Test()", "+void test.$1.Test()", }, list2.toArray()); Assert.assertFalse(ctrl.isMonitoringTerminated()); ctrl.terminateMonitoring(); }
/** * Test if the initialization of the monitoring controller from a given configuration works. */ @Test public void testConstructionFromConfig() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); {// Test with default values // NOCS final IMonitoringController kieker = MonitoringController.createInstance(configuration); Assert.assertEquals("monitoring should not be terminated", false, kieker.isMonitoringTerminated()); Assert.assertEquals("monitoringEnabled values differ", configuration.getBooleanProperty(ConfigurationKeys.MONITORING_ENABLED), kieker.isMonitoringEnabled()); kieker.terminateMonitoring(); } {// NOCS configuration .setProperty(ConfigurationKeys.MONITORING_ENABLED, Boolean.toString(!configuration.getBooleanProperty(ConfigurationKeys.MONITORING_ENABLED))); final IMonitoringController kieker = MonitoringController.createInstance(configuration); Assert.assertEquals("monitoring should not be terminated", false, kieker.isMonitoringTerminated()); Assert.assertEquals("monitoringEnabled values differ", configuration.getBooleanProperty(ConfigurationKeys.MONITORING_ENABLED), kieker.isMonitoringEnabled()); kieker.terminateMonitoring(); } }
/** * Test pattern matching algorithm. */ @Test public void testMatching() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "true"); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_CONFIG_FILE, this.configFile.getAbsolutePath()); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); // generate test signature final String signature = "public void kieker.test.monitoring.junit.core.controller.TestProbeController.testIt()"; // test methods final String pattern = "..* kieker..*.*(..)"; Assert.assertFalse(ctrl.activateProbe("InvalidPatternException expected")); Assert.assertTrue(ctrl.activateProbe(pattern)); Assert.assertTrue(ctrl.isProbeActivated(signature)); Assert.assertTrue(ctrl.deactivateProbe(pattern)); Assert.assertFalse(ctrl.isProbeActivated(signature)); ctrl.terminateMonitoring(); }
/** * Test if disabling enabled monitoring works. */ @Test public void testMonitoringEnabledToDisabled() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); configuration.setProperty(ConfigurationKeys.MONITORING_ENABLED, "true"); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Check values when enabled Assert.assertEquals("Unexpected monitoringEnabled value", true, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", false, kieker.isMonitoringTerminated()); // Change to disabled Assert.assertTrue("disableMonitoring returned false", kieker.disableMonitoring()); // Check values when disabled Assert.assertEquals("Unexpected monitoringEnabled value", false, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", false, kieker.isMonitoringTerminated()); kieker.terminateMonitoring(); }
/** * Test if enabling monitoring when starting disabled works. */ @Test public void testMonitoringDisabledToEnabled() { final Configuration configuration = DummyWriterConfigurationFactory.createDefaultConfigurationWithDummyWriter(); configuration.setProperty(ConfigurationKeys.MONITORING_ENABLED, "false"); final IMonitoringController kieker = MonitoringController.createInstance(configuration); // Check values when disabled Assert.assertEquals("Unexpected monitoringEnabled value", false, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", false, kieker.isMonitoringTerminated()); // Change to enabled Assert.assertTrue("enableMonitoring returned false", kieker.enableMonitoring()); // Check values when enabled Assert.assertEquals("Unexpected monitoringEnabled value", true, kieker.isMonitoringEnabled()); Assert.assertEquals("Unexpected monitoringTerminated value", false, kieker.isMonitoringTerminated()); kieker.terminateMonitoring(); }
/** * Test if probe activation/deactivation works properly and is not affected by enabling and disabling monitoring. * Starting with disabled adaptive monitoring. */ @Test public void testEnabledDisabledMatchingWithoutAdaptiveMonitoring() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "false"); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); ctrl.deactivateProbe("*"); Assert.assertTrue(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.disableMonitoring(); Assert.assertFalse(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.enableMonitoring(); Assert.assertTrue(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.terminateMonitoring(); }
/** * Test if probe activation/deactivation works properly and is not affected by enabling and disabling monitoring. * Starting with enabled adaptive monitoring. */ @Test public void testEnabledDisabledMatchingWithAdaptiveMonitoring() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "true"); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); Assert.assertTrue(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.disableMonitoring(); Assert.assertFalse(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.enableMonitoring(); Assert.assertTrue(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.deactivateProbe("*"); Assert.assertTrue(ctrl.isMonitoringEnabled()); Assert.assertFalse(ctrl.isProbeActivated("void test.Test()")); ctrl.activateProbe("*"); Assert.assertTrue(ctrl.isMonitoringEnabled()); Assert.assertTrue(ctrl.isProbeActivated("void test.Test()")); ctrl.terminateMonitoring(); }
/** * Test if activation and deactivation work for sample probes. */ @Test public void testSpecialProbes() { final Configuration configuration = ConfigurationFactory.createSingletonConfiguration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(ConfigurationKeys.ADAPTIVE_MONITORING_ENABLED, "true"); final IMonitoringController ctrl = MonitoringController.createInstance(configuration); final String memSwapSignature = SignatureFactory.createMemSwapSignature(); // %MEM_SWAP final String cpuSignature = SignatureFactory.createCPUSignature(); // %CPU Assert.assertTrue(ctrl.isProbeActivated(memSwapSignature)); // default is true ctrl.deactivateProbe(memSwapSignature); // this entry deactivates the MemSwapProbe Assert.assertFalse(ctrl.isProbeActivated(memSwapSignature)); Assert.assertTrue(ctrl.isProbeActivated(cpuSignature)); // default is true ctrl.deactivateProbe(cpuSignature); // this entry deactivates the CpuProbe Assert.assertFalse(ctrl.isProbeActivated(cpuSignature)); // Independent of 'cpuSignature' all specific signatures are active by default. Assert.assertTrue(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(0))); // %CPU::0 ctrl.deactivateProbe(SignatureFactory.createCPUSignature(0)); Assert.assertFalse(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(0))); Assert.assertTrue(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(1))); // %CPU::1 ctrl.deactivateProbe("%CPU::.*"); // regular expressions also allowed, this one deactivates all probes Assert.assertFalse(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(0))); Assert.assertFalse(ctrl.isProbeActivated(SignatureFactory.createCPUSignature(1))); Assert.assertFalse(ctrl.isMonitoringTerminated()); ctrl.terminateMonitoring(); }