use of cz.o2.proxima.storage.commitlog.KeyPartitioner in project proxima-platform by O2-Czech-Republic.
the class KafkaLogReaderIT method writePoisonedPills.
/**
* Write poisoned pills (element with timestamp = {@link Watermarks#MAX_WATERMARK}) to all
* partitions.
*
* @param numPartitions Number of partitions in topic.
* @return Completion latch.
*/
private CountDownLatch writePoisonedPills(int numPartitions) {
final OnlineAttributeWriter writer = Optionals.get(operator.getWriter(fooDescriptor));
// We assume test uses default partitioner.
final KeyPartitioner keyPartitioner = new KeyPartitioner();
final Set<Integer> poisonedPartitions = new HashSet<>();
final CountDownLatch done = new CountDownLatch(numPartitions);
for (int i = 0; poisonedPartitions.size() < numPartitions; i++) {
final StreamElement poisonedPill = StreamElement.upsert(entity, fooDescriptor, UUID.randomUUID().toString(), String.format("poisoned-pill-%d", i), fooDescriptor.getName(), Watermarks.MAX_WATERMARK, "value".getBytes(StandardCharsets.UTF_8));
final int partition = (keyPartitioner.getPartitionId(poisonedPill) & Integer.MAX_VALUE) % numPartitions;
if (poisonedPartitions.add(partition)) {
writer.write(poisonedPill, ((success, error) -> {
if (success) {
done.countDown();
}
}));
}
}
return done;
}
Aggregations