@Override public void invoke(Integer value) throws Exception { valuesPerPartition[value]++; boolean missing = false; for (int i : valuesPerPartition) { if (i < 100) { missing = true; break; } } if (!missing) { throw new SuccessException(); } } }
@Override public void invoke(Tuple2<Long, byte[]> value) throws Exception { elCnt++; if (value.f0 == -1) { // we should have seen 11 elements now. if (elCnt == 11) { throw new SuccessException(); } else { throw new RuntimeException("There have been " + elCnt + " elements"); } } if (elCnt > 10) { throw new RuntimeException("More than 10 elements seen: " + elCnt); } } });
@Override public void flatMap(Tuple2<byte[], PojoValue> value, Collector<Object> out) throws Exception { // ensure that deleted messages are passed as nulls assertNull(value.f1); counter++; if (counter == elementCount) { // we got the right number of elements throw new SuccessException(); } } });
@Override public void close() { if (resultChecker.checkResult(windowCounts)) { if (usingProcessingTime) { throw new SuccessException(); } } else { throw new AssertionError("Test failed check."); } }
@Override public void invoke(Integer value) throws Exception { numElements++; if (duplicateChecker.get(value)) { throw new Exception("Received a duplicate: " + value); } duplicateChecker.set(value); if (numElements == numElementsTotal) { // validate if (duplicateChecker.cardinality() != numElementsTotal) { throw new Exception("Duplicate checker has wrong cardinality"); } else if (duplicateChecker.nextClearBit(0) != numElementsTotal) { throw new Exception("Received sparse sequence"); } else { throw new SuccessException(); } } }
@Override public void flatMap(Tuple3<Integer, Integer, String> value, Collector<Integer> out) throws Exception { Integer count = countPerTopic.get(value.f2); if (count == null) { count = 1; } else { count++; } countPerTopic.put(value.f2, count); // check map: for (Map.Entry<String, Integer> el: countPerTopic.entrySet()) { if (el.getValue() < numElements) { break; // not enough yet } if (el.getValue() > numElements) { throw new RuntimeException("There is a failure in the test. I've read " + el.getValue() + " from topic " + el.getKey()); } } // we've seen messages from all topics throw new SuccessException(); } }).setParallelism(1);
@Override public void flatMap(Tuple2<Integer, Integer> value, Collector<Integer> out) throws Exception { int partition = value.f0; int val = value.f1; BitSet bitSet = partitionsToValueCheck.get(partition); if (bitSet == null) { throw new RuntimeException("Got a record from an unknown partition"); } else { bitSet.set(val - partitionsToValuesCountAndStartOffset.get(partition).f1); } count++; LOG.info("Received message {}, total {} messages", value, count); // verify if we've seen everything if (count == finalCount) { for (Map.Entry<Integer, BitSet> partitionsToValueCheck : this.partitionsToValueCheck.entrySet()) { BitSet check = partitionsToValueCheck.getValue(); int expectedValueCount = partitionsToValuesCountAndStartOffset.get(partitionsToValueCheck.getKey()).f0; if (check.cardinality() != expectedValueCount) { throw new RuntimeException("Expected cardinality to be " + expectedValueCount + ", but was " + check.cardinality()); } else if (check.nextClearBit(0) != expectedValueCount) { throw new RuntimeException("Expected next clear bit to be " + expectedValueCount + ", but was " + check.cardinality()); } } // test has passed throw new SuccessException(); } }
@Override public void invoke(T value, Context context) throws Exception { countUpdater.updateCount(value, windowCounts); if (usingProcessingTime && resultChecker.checkResult(windowCounts)) { throw new SuccessException(); } }
@Override public void invoke(Tuple2<Long, String> value) throws Exception { String[] sp = value.f1.split("-"); int v = Integer.parseInt(sp[1]); assertEquals(value.f0 - 1000, (long) v); assertFalse("Received tuple twice", validator.get(v)); validator.set(v); elCnt++; if (elCnt == totalElements) { // check if everything in the bitset is set to true int nc; if ((nc = validator.nextClearBit(0)) != totalElements) { fail("The bitset was not set to 1 on all elements. Next clear:" + nc + " Set: " + validator); } throw new SuccessException(); } }
@Override public void invoke(String value) throws Exception { int fileIdx = getFileIdx(value); Set<String> content = actualContent.get(fileIdx); if (content == null) { content = new HashSet<>(); actualContent.put(fileIdx, content); } // detect duplicate lines. if (!content.add(value + "\n")) { fail("Duplicate line: " + value); System.exit(0); } elementCounter++; // this is termination if (elementCounter >= NO_OF_FILES * LINES_PER_FILE) { actualCollectedContent = actualContent; throw new SuccessException(); } // add some latency so that we have at least two checkpoint in if (!hasRestoredAfterFailure && successfulCheckpoints < 2) { Thread.sleep(5); } // simulate a node failure if (!hasRestoredAfterFailure && successfulCheckpoints >= 2 && elementCounter >= elementsToFailure) { throw new Exception("Task Failure @ elem: " + elementCounter + " / " + elementsToFailure); } }
@Override public void flatMap(Tuple2<Long, PojoValue> value, Collector<Object> out) throws Exception { // the elements should be in order. Assert.assertTrue("Wrong value " + value.f1.lat, value.f1.lat == counter); if (value.f1.lat % 2 == 0) { assertNull("key was not null", value.f0); } else { Assert.assertTrue("Wrong value " + value.f0, value.f0 == counter); } counter++; if (counter == elementCount) { // we got the right number of elements throw new SuccessException(); } } });
@Override public void open(Configuration parameters) throws Exception { // this sink can only work with DOP 1 assertEquals(1, getRuntimeContext().getNumberOfParallelSubtasks()); if (usingProcessingTime && resultChecker.checkResult(windowCounts)) { throw new SuccessException(); } }
if (Arrays.equals(solvedCase, workCase)) { drawSudoku(testOutput); throw new SuccessException(); }