/** * Starts a complete test flow through all currently available filters. In this case, the NamedDoubleRecords can * be from different applications and will still be treated correctly. * * @throws InterruptedException * If interrupted */ @Test public void testOpadFlow() throws InterruptedException { final AnalysisControllerThread thread = new AnalysisControllerThread(this.controller); thread.start(); Thread.sleep(2000); thread.terminate(); Assert.assertEquals(7, this.sinkPluginIfAnomaly.getList().size()); Assert.assertEquals(6, this.sinkPluginElse.getList().size()); }
/** * Test of the AnomalyDetectionFilter. * * @throws InterruptedException * If interrupted * @throws IllegalStateException * If illegal state * @throws AnalysisConfigurationException * If wrong configuration */ @Test public void testDetectionOnly() throws InterruptedException, IllegalStateException, AnalysisConfigurationException { final AnalysisControllerThread thread = new AnalysisControllerThread(this.controller); thread.start(); Thread.sleep(1000); thread.terminate(); Assert.assertEquals(2, this.sinkPluginIfAnomaly.getList().size()); Assert.assertEquals(1, this.sinkPluginElse.getList().size()); Assert.assertEquals(3, this.sinkPluginAll.getList().size()); }
@Override protected MonitoringController createController(final int numRecordsWritten) throws IllegalStateException, AnalysisConfigurationException, InterruptedException { final AnalysisController analysisController = new AnalysisController(); final Configuration config = ConfigurationFactory.createDefaultConfiguration(); config.setProperty(ConfigurationKeys.WRITER_CLASSNAME, JmsWriter.class.getName()); config.setProperty(JmsWriter.CONFIG_CONTEXTFACTORYTYPE, FakeInitialContextFactory.class.getName()); config.setProperty(JmsWriter.CONFIG_FACTORYLOOKUPNAME, "ConnectionFactory"); final MonitoringController ctrl = MonitoringController.createInstance(config); Thread.sleep(1000); final Configuration jmsReaderConfig = new Configuration(); jmsReaderConfig.setProperty(JmsReader.CONFIG_PROPERTY_NAME_FACTORYLOOKUP, FakeInitialContextFactory.class.getName()); final JmsReader jmsReader = new JmsReader(jmsReaderConfig, analysisController); this.sinkFilter = new ListCollectionFilter<IMonitoringRecord>(new Configuration(), analysisController); analysisController.connect(jmsReader, JmsReader.OUTPUT_PORT_NAME_RECORDS, this.sinkFilter, ListCollectionFilter.INPUT_PORT_NAME); final AnalysisControllerThread analysisThread = new AnalysisControllerThread(analysisController); analysisThread.start(); Thread.sleep(1000); return ctrl; }
public void testForecastingOnly() throws InterruptedException, IllegalStateException, AnalysisConfigurationException { final AnalysisControllerThread thread = new AnalysisControllerThread(this.controller); thread.start();
/** * Tests the "blocking" mode of the reader. * * @throws InterruptedException * If the thread is interrupted. This should not happen. */ @SuppressWarnings("unused") @Test public void testBlockingMode() throws InterruptedException { final AnalysisController ac = new AnalysisController(); final AnalysisControllerThread thread = new AnalysisControllerThread(ac); final Configuration configuration = new Configuration(); configuration.setProperty(TimeReader.CONFIG_PROPERTY_NAME_NUMBER_IMPULSES, Long.toString(TimeReader.INFINITE_EMITS)); new TimeReader(configuration, ac); // We expect that the reader doesn't return immediately - in this case we expect the AC to run at least five seconds thread.start(); Thread.sleep(5000); Assert.assertEquals(STATE.RUNNING, ac.getState()); ac.terminate(); }
/** * Test of the AnomalyScoreCalculationFilter. * * @throws InterruptedException * If interrupted * @throws IllegalStateException * If illegal state * @throws AnalysisConfigurationException * If wrong configuration */ @Test public void testAnomalyScoreCalculationOnly() throws InterruptedException, IllegalStateException, AnalysisConfigurationException { final AnalysisControllerThread thread = new AnalysisControllerThread(this.controller); thread.start(); Thread.sleep(1000); thread.terminate(); Assert.assertEquals(3, this.sinkAnomalyScore.getList().size()); Assert.assertEquals(this.sinkAnomalyScore.getList().get(0).getScore(), 0.19999999999999996, 0); Assert.assertEquals(this.sinkAnomalyScore.getList().get(1).getScore(), 0.1428571428571429, 0); Assert.assertEquals(this.sinkAnomalyScore.getList().get(2).getScore(), 0.0, 0); }
/** * Test the extraction of the data from ResponseTimeDoubleRecords. * * @throws InterruptedException * If interrupted */ @Test public void testResponsetimeOnly() throws InterruptedException { final AnalysisControllerThread thread = new AnalysisControllerThread(this.controller); thread.start(); Thread.sleep(2000); thread.terminate(); Assert.assertEquals(3, this.sinkPlugin.getList().size()); // Test on the timestamp conversion (here as configured to milliseconds Assert.assertEquals(1369127, this.sinkPlugin.getList().get(0).getTime(), 0); Assert.assertEquals(1369128, this.sinkPlugin.getList().get(1).getTime(), 0); Assert.assertEquals(1369129, this.sinkPlugin.getList().get(2).getTime(), 0); // Test on the extracted values Assert.assertEquals(10341.94, this.sinkPlugin.getList().get(0).getDoubleValue(), 0); Assert.assertEquals(8341.00, this.sinkPlugin.getList().get(1).getDoubleValue(), 0); Assert.assertEquals(78.26, this.sinkPlugin.getList().get(2).getDoubleValue(), 0); } }
@Override protected MonitoringController createController(final int numRecordsWritten) throws IllegalStateException, AnalysisConfigurationException, InterruptedException { this.analysisController = new AnalysisController(); final Configuration readerConfig = new Configuration(); readerConfig.setProperty(SingleSocketTcpReader.CONFIG_PROPERTY_NAME_PORT, SingleSocketTcpWriterReaderTest.PORT1); // readerConfig.setProperty(SingleSocketTcpReader.CONFIG_PROPERTY_NAME_PORT1, SingleSocketTcpWriterReaderTest.PORT1); // readerConfig.setProperty(SingleSocketTcpReader.CONFIG_PROPERTY_NAME_PORT2, SingleSocketTcpWriterReaderTest.PORT2); final SingleSocketTcpReader tcpReader = new SingleSocketTcpReader(readerConfig, this.analysisController); this.sinkFilter = new ListCollectionFilter<IMonitoringRecord>(new Configuration(), this.analysisController); this.analysisController.connect(tcpReader, SingleSocketTcpReader.OUTPUT_PORT_NAME_RECORDS, this.sinkFilter, ListCollectionFilter.INPUT_PORT_NAME); this.analysisThread = new AnalysisControllerThread(this.analysisController); this.analysisThread.start(); Thread.sleep(1000); final Configuration monitoringConfig = ConfigurationFactory.createDefaultConfiguration(); monitoringConfig.setProperty(ConfigurationKeys.WRITER_CLASSNAME, SingleSocketTcpWriter.class.getName()); monitoringConfig.setProperty(SingleSocketTcpWriter.CONFIG_PORT, SingleSocketTcpWriterReaderTest.PORT1); return MonitoringController.createInstance(monitoringConfig); }
@Override protected MonitoringController createController(final int numRecordsWritten) throws IllegalStateException, AnalysisConfigurationException, InterruptedException { this.analysisController = new AnalysisController(); final Configuration readerConfig = new Configuration(); readerConfig.setProperty(SingleSocketTcpReader.CONFIG_PROPERTY_NAME_PORT, NewSingleSocketTcpWriterReaderTest.PORT1); // readerConfig.setProperty(SingleSocketTcpReader.CONFIG_PROPERTY_NAME_PORT1, SingleSocketTcpWriterReaderTest.PORT1); // readerConfig.setProperty(SingleSocketTcpReader.CONFIG_PROPERTY_NAME_PORT2, SingleSocketTcpWriterReaderTest.PORT2); final SingleSocketTcpReader tcpReader = new SingleSocketTcpReader(readerConfig, this.analysisController); this.sinkFilter = new ListCollectionFilter<IMonitoringRecord>(new Configuration(), this.analysisController); this.analysisController.connect(tcpReader, SingleSocketTcpReader.OUTPUT_PORT_NAME_RECORDS, this.sinkFilter, ListCollectionFilter.INPUT_PORT_NAME); this.analysisThread = new AnalysisControllerThread(this.analysisController); this.analysisThread.start(); Thread.sleep(1000); final Configuration monitoringConfig = ConfigurationFactory.createDefaultConfiguration(); monitoringConfig.setProperty(ConfigurationKeys.WRITER_CLASSNAME, SingleSocketTcpWriter.class.getName()); monitoringConfig.setProperty(SingleSocketTcpWriter.CONFIG_PORT, NewSingleSocketTcpWriterReaderTest.PORT1); return MonitoringController.createInstance(monitoringConfig); }
@Before public void setUp() throws Exception { final AnalysisController analysisController = new AnalysisController(); final Configuration pipeReaderConfig = new Configuration(); pipeReaderConfig.setProperty(PipeReader.CONFIG_PROPERTY_NAME_PIPENAME, BasicNamedRecordPipeWriterReaderTest.PIPE_NAME); final PipeReader pipeReader = new PipeReader(pipeReaderConfig, analysisController); this.sinkFilter = new ListCollectionFilter<IMonitoringRecord>(new Configuration(), analysisController); analysisController.connect(pipeReader, PipeReader.OUTPUT_PORT_NAME_RECORDS, this.sinkFilter, ListCollectionFilter.INPUT_PORT_NAME); final AnalysisControllerThread analysisThread = new AnalysisControllerThread(analysisController); analysisThread.start(); }
/** * Tests the "non blocking" mode of the reader. * * @throws InterruptedException * If the thread is interrupted. This should not happen. */ @SuppressWarnings("unused") @Test public void testNonBlockingMode() throws InterruptedException { final AnalysisController ac = new AnalysisController(); final AnalysisControllerThread thread = new AnalysisControllerThread(ac); final Configuration configuration = new Configuration(); configuration.setProperty(TimeReader.CONFIG_PROPERTY_NAME_NUMBER_IMPULSES, "1"); configuration.setProperty(TimeReader.CONFIG_PROPERTY_NAME_DELAY_NS, "0"); configuration.setProperty(TimeReader.CONFIG_PROPERTY_NAME_UPDATE_INTERVAL_NS, "1000000000"); new TimeReader(configuration, ac); // We expect the reader to return very fast - in this case we expect the AC to return within five seconds thread.start(); Thread.sleep(6000); Assert.assertEquals(STATE.TERMINATED, ac.getState()); }
@Override protected MonitoringController createController(final int numRecordsWritten) throws IllegalStateException, AnalysisConfigurationException, InterruptedException { this.analysisController = new AnalysisController(); final Configuration readerConfig = new Configuration(); readerConfig.setProperty(DualSocketTcpReader.CONFIG_PROPERTY_NAME_PORT1, DualSocketTcpWriterReaderTest.PORT1); readerConfig.setProperty(DualSocketTcpReader.CONFIG_PROPERTY_NAME_PORT2, DualSocketTcpWriterReaderTest.PORT2); final DualSocketTcpReader tcpReader = new DualSocketTcpReader(readerConfig, this.analysisController); this.sinkFilter = new ListCollectionFilter<IMonitoringRecord>(new Configuration(), this.analysisController); this.analysisController.connect(tcpReader, DualSocketTcpReader.OUTPUT_PORT_NAME_RECORDS, this.sinkFilter, ListCollectionFilter.INPUT_PORT_NAME); this.analysisThread = new AnalysisControllerThread(this.analysisController); this.analysisThread.start(); Thread.sleep(1000); final Configuration monitoringConfig = ConfigurationFactory.createDefaultConfiguration(); monitoringConfig.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DualSocketTcpWriter.class.getName()); monitoringConfig.setProperty(DualSocketTcpWriter.CONFIG_PORT1, DualSocketTcpWriterReaderTest.PORT1); monitoringConfig.setProperty(DualSocketTcpWriter.CONFIG_PORT2, DualSocketTcpWriterReaderTest.PORT2); return MonitoringController.createInstance(monitoringConfig); }
thread.start(); Thread.sleep(12000); ac.terminate();
/** * This test should make sure that the timer delivers a correct amount of records within a given limit. * * @throws InterruptedException * If the test thread is interrupted. * @throws IllegalStateException * If the analysis is in the wrong state. * @throws AnalysisConfigurationException * If the analysis is somehow invalid configured. */ @Test public void testIntervalTimer() throws InterruptedException, IllegalStateException, AnalysisConfigurationException { // Running 5 seconds, firing one event per 100 ms, we expect to receive approx. 50 events. final AnalysisController ac = new AnalysisController(); final AnalysisControllerThread thread = new AnalysisControllerThread(ac); final Configuration configuration = new Configuration(); configuration.setProperty(TimeReader.CONFIG_PROPERTY_NAME_UPDATE_INTERVAL_NS, "100000000"); final TimeReader tr = new TimeReader(configuration, ac); final CountingFilter cf = new CountingFilter(new Configuration(), ac); ac.connect(tr, TimeReader.OUTPUT_PORT_NAME_TIMESTAMP_RECORDS, cf, CountingFilter.INPUT_PORT_NAME_EVENTS); thread.start(); Thread.sleep(5000); ac.terminate(); Assert.assertTrue(cf.getMessageCount() > 40); Assert.assertTrue(cf.getMessageCount() < 60); }
analysisThread.start(); // start asynchronously