use of org.apache.storm.st.wrapper.DecoratedLogLine in project storm by apache.
the class WindowVerifier method runAndVerifyCount.
/**
* Run the topology and verify that the number and contents of count based windows is as expected
* once the spout and bolt have emitted sufficient tuples.
* The spout and bolt are required to log exactly one log line per emit/window using {@link StringDecorator}
*/
public void runAndVerifyCount(int windowSize, int slideSize, TestableTopology testable, TopoWrap topo) throws IOException, TException, MalformedURLException {
topo.submitSuccessfully();
final int minBoltEmits = 5;
// Sliding windows should produce one window every slideSize tuples
// Wait for the spout to emit at least enough tuples to get minBoltEmit windows and at least one full window
final int minSpoutEmits = Math.max(windowSize, minBoltEmits * slideSize);
String boltName = testable.getBoltName();
String spoutName = testable.getSpoutName();
// Waiting for spout tuples isn't strictly necessary since we also wait for bolt emits, but do it anyway
topo.assertProgress(minSpoutEmits, testable.getSpoutExecutors(), spoutName, 180);
topo.assertProgress(minBoltEmits, testable.getBoltExecutors(), boltName, 180);
final List<DecoratedLogLine> allDecoratedBoltLogs = topo.getDecoratedLogLines(boltName);
final List<DecoratedLogLine> allDecoratedSpoutLogs = topo.getDecoratedLogLines(spoutName);
// We expect the bolt to log exactly one decorated line per emit
Assert.assertTrue(allDecoratedBoltLogs.size() >= minBoltEmits, "Expecting min " + minBoltEmits + " bolt emits, found: " + allDecoratedBoltLogs.size() + " \n\t" + allDecoratedBoltLogs);
final int numberOfWindows = allDecoratedBoltLogs.size();
for (int i = 0; i < numberOfWindows; ++i) {
LOG.info("Comparing window: " + (i + 1) + " of " + numberOfWindows);
final int toIndex = (i + 1) * slideSize;
final int fromIndex = toIndex - windowSize;
final int positiveFromIndex = fromIndex > 0 ? fromIndex : 0;
final List<DecoratedLogLine> expectedWindowContents = allDecoratedSpoutLogs.subList(positiveFromIndex, toIndex);
final String actualString = allDecoratedBoltLogs.get(i).toString();
for (DecoratedLogLine windowData : expectedWindowContents) {
final String logStr = windowData.getData();
Assertions.assertTrue(actualString.contains(logStr), () -> String.format("Missing: '%s' \nActual: '%s' \nCalculated window: '%s'", logStr, actualString, expectedWindowContents));
}
}
}
Aggregations