/** * A simple test for the counting filter. * * @throws IllegalStateException * If the test setup is somehow invalid (should not happen). * @throws AnalysisConfigurationException * If the test setup is somehow invalid (should not happen). */ @Test public void testNormal() throws IllegalStateException, AnalysisConfigurationException { this.simpleListReader.addObject(new Object()); this.simpleListReader.addObject(new Object()); this.simpleListReader.addObject(new Object()); Assert.assertEquals(0, this.countingFilter.getMessageCount()); this.analysisController.run(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, this.analysisController.getState()); Assert.assertEquals(3, this.countingFilter.getMessageCount()); }
/** * This method represents the input port of this filter. * * @param event * The next event. */ @InputPort(name = INPUT_PORT_NAME_EVENTS, eventTypes = { Object.class }, description = "Receives incoming objects to be counted and forwarded") public final void inputEvent(final Object event) { final Long count = CountingFilter.this.counter.incrementAndGet(); this.updateDisplays(); super.deliver(OUTPUT_PORT_NAME_RELAYED_EVENTS, event); super.deliver(OUTPUT_PORT_NAME_COUNT, count); }
/** * 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); }
/** * This method prepares the test setup. * * @throws IllegalStateException * If something went wrong during the test setup (should not happen). * @throws AnalysisConfigurationException * If something went wrong during the test setup (should not happen). */ @Before public void before() throws IllegalStateException, AnalysisConfigurationException { this.analysisController = new AnalysisController(); this.countingFilter = new CountingFilter(new Configuration(), this.analysisController); this.simpleListReader = new ListReader<Object>(new Configuration(), this.analysisController); this.analysisController.connect(this.simpleListReader, ListReader.OUTPUT_PORT_NAME, this.countingFilter, CountingFilter.INPUT_PORT_NAME_EVENTS); }
@Ignore // NOCS @Test public void testRecords() throws IOException, IllegalStateException, AnalysisConfigurationException { final IAnalysisController analysisController = new AnalysisController(); final Configuration configurationFSReader = new Configuration(); configurationFSReader.setProperty(FSReader.CONFIG_PROPERTY_NAME_INPUTDIRS, this.tmpFolder.getRoot().getCanonicalPath()); final FSReader reader = new FSReader(configurationFSReader, analysisController); final CountingFilter sink = new CountingFilter(new Configuration(), analysisController); analysisController.connect(reader, FSReader.OUTPUT_PORT_NAME_RECORDS, sink, CountingFilter.INPUT_PORT_NAME_EVENTS); analysisController.run(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, analysisController.getState()); Assert.assertEquals(5L, sink.getMessageCount()); // 5 records are expected } }
uncountedRecordsCountingFilter = new CountingFilter(configuration, this.analysisController); this.analysisController.connect(monitoringThroughputFilter, MonitoringThroughputFilter.OUTPUT_PORT_NAME_UNCOUNTED_RECORDS, uncountedRecordsCountingFilter, CountingFilter.INPUT_PORT_NAME_EVENTS); relayedRecordsCountingFilter = new CountingFilter(configuration, this.analysisController); this.analysisController.connect(monitoringThroughputFilter, MonitoringThroughputFilter.OUTPUT_PORT_NAME_RELAYED_RECORDS, relayedRecordsCountingFilter, CountingFilter.INPUT_PORT_NAME_EVENTS);
configuration.setProperty(TimeReader.CONFIG_PROPERTY_NAME_NUMBER_IMPULSES, "10"); final TimeReader tr = new TimeReader(configuration, ac); final CountingFilter cf = new CountingFilter(new Configuration(), ac); ac.terminate(); Assert.assertEquals(10, cf.getMessageCount());
this.countingFilterReader = new CountingFilter(new Configuration(), this.analysisController); this.analysisController.connect(this.simpleListReader, ListReader.OUTPUT_PORT_NAME, this.countingFilterReader, CountingFilter.INPUT_PORT_NAME_EVENTS); this.countingFilterDelayed = new CountingFilter(new Configuration(), this.analysisController); this.analysisController.connect(throughputFilter, AnalysisThroughputFilter.OUTPUT_PORT_NAME_RELAYED_OBJECTS, this.countingFilterDelayed, CountingFilter.INPUT_PORT_NAME_EVENTS);
@Test public void testNormal() throws IllegalStateException, AnalysisConfigurationException, InterruptedException { final List<Entry<Long, Integer>> eventList = this.passEventListToReader(this.simpleListReader); Assert.assertEquals(0, this.sinkPlugin.size()); this.analysisController.run(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, this.analysisController.getState()); // Make sure that all events have been provided to the delay filter (otherwise the test make no sense) Assert.assertEquals("Test invalid: Unexpected number of events provided TO the delay filter", eventList.size(), this.countingFilterReader.getMessageCount()); // Make sure that all events have been passed through the delay filter Assert.assertEquals("Unexpected number of events relayed by the delay filter", eventList.size(), this.countingFilterDelayed.getMessageCount()); this.checkTiming(); // Make sure that exactly the right objects have been passed this.checkRelayedRecords(); } }
/** * This method represents the input port of this filter. * * @param event * The next event. */ @InputPort(name = INPUT_PORT_NAME_EVENTS, eventTypes = { Object.class }, description = "Receives incoming objects to be counted and forwarded") public final void inputEvent(final Object event) { final Long count = CountingFilter.this.counter.incrementAndGet(); this.updateDisplays(); super.deliver(OUTPUT_PORT_NAME_RELAYED_EVENTS, event); super.deliver(OUTPUT_PORT_NAME_COUNT, count); }
final CountingFilter countingFilter = new CountingFilter(countinConfiguration, analysis); Assert.assertEquals("Unexpected number of records received", numRecordsToSend, countingFilter.getMessageCount());
final CountingFilter countingFilter1 = new CountingFilter(confCountingFilter1, analysisController); final CountingFilter countingFilter2 = new CountingFilter(confCountingFilter2, analysisController);
/** * A simple test for the counting filter using objects of different classes. * * @throws IllegalStateException * If the test setup is somehow invalid (should not happen). * @throws AnalysisConfigurationException * If the test setup is somehow invalid (should not happen). */ @Test public void testDifferentClasses() throws IllegalStateException, AnalysisConfigurationException { this.simpleListReader.addObject(Long.valueOf(10)); this.simpleListReader.addObject(null); this.simpleListReader.addObject(""); Assert.assertEquals(0, this.countingFilter.getMessageCount()); this.analysisController.run(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, this.analysisController.getState()); Assert.assertEquals(2, this.countingFilter.getMessageCount()); } }
/** * A test for the counting filter with multiple readers. * * @throws IllegalStateException * If the test setup is somehow invalid (should not happen). * @throws AnalysisConfigurationException * If the test setup is somehow invalid (should not happen). */ @Test public void testConcurrently() throws IllegalStateException, AnalysisConfigurationException { this.simpleListReader.addObject(new Object()); // register multiple readers (they fire concurrently) final ListReader<Object> reader2 = new ListReader<Object>(new Configuration(), this.analysisController); this.analysisController.connect(reader2, ListReader.OUTPUT_PORT_NAME, this.countingFilter, CountingFilter.INPUT_PORT_NAME_EVENTS); reader2.addObject(new Object()); final ListReader<Object> reader3 = new ListReader<Object>(new Configuration(), this.analysisController); this.analysisController.connect(reader3, ListReader.OUTPUT_PORT_NAME, this.countingFilter, CountingFilter.INPUT_PORT_NAME_EVENTS); reader3.addObject(new Object()); Assert.assertEquals(0, this.countingFilter.getMessageCount()); this.analysisController.run(); Assert.assertEquals(AnalysisController.STATE.TERMINATED, this.analysisController.getState()); Assert.assertEquals(3, this.countingFilter.getMessageCount()); }