if (streamType.equals(TeeFilterStreamType.STDLOG)) { this.printStream = null; // NOPMD (null) this.active = true; } else if (streamType.equals(TeeFilterStreamType.STDOUT)) { this.printStream = System.out; this.active = true; } else if (streamType.equals(TeeFilterStreamType.STDERR)) { this.printStream = System.err; this.active = true;
@Override protected void onStarting() { super.onStarting(); this.resetTimestamp(System.nanoTime()); }
/** * This method represents the input port of this filter. * * @param event * The next event. */ @Override protected void execute(final Object event) { final Long count = this.counter.incrementAndGet(); this.updateDisplays(); this.relayedEventsOutputPort.send(event); this.countOutputPort.send(count); }
@Ignore // NOCS @Test public void testRecordsWithoutStringSame() { final StringBufferFilter stringBufferFilter = new StringBufferFilter(); final List<IMonitoringRecord> inputElements = new ArrayList<>(); final List<Object> outputElements = new ArrayList<>(); final IMonitoringRecord recordIn1 = new EmptyRecord(); inputElements.add(recordIn1); StageTester.test(stringBufferFilter) .and().send(inputElements).to(stringBufferFilter.getInputPort()) .and().receive(outputElements).from(stringBufferFilter.getOutputPort()) .start(); Assert.assertEquals("Unexpected number of records", 1, outputElements.size()); final IMonitoringRecord recordOut1 = (IMonitoringRecord) outputElements.get(0); Assert.assertSame("First output record not same as first input record", recordIn1, recordOut1); // includes no String, hence "as-is" }
public RealtimeRecordDelayFilterConfig(final InitialElementProducer<IMonitoringRecord> recordProducer, final Counter<IMonitoringRecord> preDelayCounter, final RealtimeRecordDelayFilter delayFilter, final Clock clock, final AnalysisThroughputFilter throughputStage, final Counter<IMonitoringRecord> postDelayCounter, final CollectorSink<IMonitoringRecord> recordCollectorSink, final CollectorSink<Long> throughputCollectorSink) { this.connectPorts(recordProducer.getOutputPort(), preDelayCounter.getInputPort()); this.connectPorts(preDelayCounter.getOutputPort(), delayFilter.getInputPort()); this.connectPorts(delayFilter.getOutputPort(), postDelayCounter.getInputPort()); this.connectPorts(postDelayCounter.getOutputPort(), throughputStage.getRecordsInputPort()); this.connectPorts(throughputStage.getRecordsOutputPort(), recordCollectorSink.getInputPort()); this.connectPorts(clock.getOutputPort(), throughputStage.getTimestampsInputPort()); this.connectPorts(throughputStage.getRecordsCountOutputPort(), throughputCollectorSink.getInputPort()); } }
/** * A simple test for the counting filter. */ @Test public void testNormal() { this.testElements.add(new Object()); this.testElements.add(new Object()); this.testElements.add(new Object()); Assert.assertEquals(0, this.countingFilter.getMessageCount()); StageTester.test(this.countingFilter).and().send(this.testElements).to(this.countingFilter.getInputPort()).start(); Assert.assertEquals(3, this.countingFilter.getMessageCount()); }
private void executeAnalysis(final File tempFile, final boolean append, final List<Integer> objectsToWrite) { final TeeFilter teeFilter = new TeeFilter(tempFile.getAbsolutePath(), null, append); StageTester.test(teeFilter).and().send(objectsToWrite).to(teeFilter.getInputPort()).start(); }
this.clock.setInitialDelayInMs(5000); this.clock.setIntervalDelayInMs(5000); this.throughputStage = new AnalysisThroughputFilter(); this.throughputStage.declareActive(); this.postDelayCounter = new Counter<>(); this.recordCollectorSink = new CollectorSink<>();
@Override public boolean isMet() { return AbstractTestRealtimeRecordDelayFilter.this.throughputStage.getRecordsInputPort().isClosed(); // NOPMD } };
/** * This method receives incoming objects from the filter's input port. Every object will be printed into a stream * (based on the configuration) before the filter sends it to the output port. * * @param object * The new object. */ @Override protected void execute(final Object object) { if (this.active) { final StringBuilder sb = new StringBuilder(128).append(this.getId()).append('(') .append(object.getClass().getSimpleName()).append(") ").append(object.toString()); final String record = sb.toString(); if (this.printStream != null) { this.printStream.println(record); } else { this.logger.info(record); } } this.outputPort.send(object); }
/** * Initializes a new filter and array of test elements before each test. */ @Before public void initializeNewFilter() { this.countingFilter = new CountingFilter(); this.testElements = new ArrayList<>(); }
@Ignore // NOCS @Test public void testRecordsWithStringEqualButNeverSame() { final StringBufferFilter stringBufferFilter = new StringBufferFilter(); final List<IMonitoringRecord> inputElements = new ArrayList<>(); final List<Object> outputElements = new ArrayList<>(); long timestamp = 3268936L; final IMonitoringRecord recordIn1 = TestStringBufferFilter.createOperationExecutionRecord(timestamp); timestamp++; final IMonitoringRecord recordIn2 = TestStringBufferFilter.createOperationExecutionRecord(timestamp); inputElements.add(recordIn1); inputElements.add(recordIn2); StageTester.test(stringBufferFilter) .and().send(inputElements).to(stringBufferFilter.getInputPort()) .and().receive(outputElements).from(stringBufferFilter.getOutputPort()) .start(); Assert.assertEquals("Unexpected number of records", 2, outputElements.size()); final IMonitoringRecord recordOut1 = (IMonitoringRecord) outputElements.get(0); final IMonitoringRecord recordOut2 = (IMonitoringRecord) outputElements.get(1); Assert.assertNotSame("First output record same as first input record", recordIn1, recordOut1); // includes String, hence NOT "as-is" Assert.assertEquals("First output record doesn't equal first input record", recordIn1, recordOut1); // ... but must be equal Assert.assertNotSame("Second output record same as second input record", recordIn2, recordOut2); // includes String, hence NOT "as-is" Assert.assertEquals("Second output record doesn't equal second input record", recordIn2, recordOut2); // ... but must be equal }
/** * A simple test for the counting filter using objects of different classes. */ @Test public void testDifferentClasses() { this.testElements.add(Long.valueOf(10)); this.testElements.add(new Object()); this.testElements.add(""); Assert.assertEquals(0, this.countingFilter.getMessageCount()); StageTester.test(this.countingFilter).and().send(this.testElements).to(this.countingFilter.getInputPort()).start(); Assert.assertEquals(3, this.countingFilter.getMessageCount()); } }
@Override protected void execute() { final IMonitoringRecord record = this.recordsInputPort.receive(); if (record != null) { this.numPassedElements++; this.recordsOutputPort.send(record); } final Long timestampInNs = this.timestampsInputPort.receive(); if (timestampInNs != null) { final long duration = timestampInNs - this.lastTimestampInNs; final StringBuilder sb = new StringBuilder(256).append(this.numPassedElements).append(" objects within ") .append(duration).append(' ').append(TimeUnit.NANOSECONDS.toString()); this.plainTextDisplayObject.setText(sb.toString()); this.recordsCountOutputPort.send(this.numPassedElements); this.resetTimestamp(timestampInNs); } }
@Ignore // NOCS @Test public void testObjects() { final StringBufferFilter stringBufferFilter = new StringBufferFilter(); final List<Object> inputElements = new ArrayList<>(); final List<Object> outputElements = new ArrayList<>(); final Object objectIn = new Object(); final String stringIn1 = "In-String"; final String stringIn2 = new String(stringIn1); // NOPMD (new String) Assert.assertNotSame(stringIn1, stringIn2); Assert.assertEquals(stringIn1, stringIn2); inputElements.add(objectIn); inputElements.add(stringIn1); inputElements.add(stringIn2); StageTester.test(stringBufferFilter) .and().send(inputElements).to(stringBufferFilter.getInputPort()) .and().receive(outputElements).from(stringBufferFilter.getOutputPort()) .start(); Assert.assertEquals("Unexpected number of records", 3, outputElements.size()); final Object objectOut = outputElements.get(0); Assert.assertSame("Input object not same as output object", objectIn, objectOut); final String stringOut1 = (String) outputElements.get(1); final String stringOut2 = (String) outputElements.get(2); Assert.assertSame("Input string 1 not same as output string 1", stringIn1, stringOut1); // first occurrence of a string should remain same Assert.assertEquals("Input string not equal to output string", stringIn1, stringOut1); Assert.assertNotSame("Input string 2 same as output string 2", stringIn2, stringOut2); // next occurrence should be cached Assert.assertSame("Input string 1 not same as output string 2", stringIn1, stringOut2); Assert.assertEquals("Input string not equal to output string", stringIn2, stringOut2); }
final StringBufferFilter stringBufferFilter = new StringBufferFilter(); final List<OperationExecutionRecord> inputElements = new ArrayList<>(); final List<Object> outputElements = new ArrayList<>(); .and().send(inputElements).to(stringBufferFilter.getInputPort()) .and().receive(outputElements).from(stringBufferFilter.getOutputPort()) .start();