}
};
int queueCapacity = 10000;
final MemoryQueue4Sink queue = new MemoryQueue4Sink(queueCapacity);
final int initialCount = queueCapacity / 2 + 10;
for (int i = 0; i < initialCount; ++i) {
queue.offer(new Message("routingKey", ("testMessage" + i).getBytes()));
}
sink.initialize(null, queue, 100, 1000, true);
assertEquals(sink.checkPause(), queue.size());
queue.drain(Integer.MAX_VALUE, new LinkedList<Message>());
///////////////////////////
sink = new QueuedSink() {
@Override
protected void beforePolling() throws IOException {
}
@Override
protected void write(List<Message> msgList) throws IOException {
}
@Override
protected void innerClose() throws IOException {
}
};
QueuedSink.MAX_PENDING_MESSAGES_TO_PAUSE = 100;
for (int i = 0; i < QueuedSink.MAX_PENDING_MESSAGES_TO_PAUSE + 1; ++i) {
queue.offer(new Message("routingKey", ("testMessage" + i).getBytes()));
}
sink.initialize(null, queue, 100, 1000, true);
assertEquals(sink.checkPause(), queue.size());
QueuedSink.MAX_PENDING_MESSAGES_TO_PAUSE = 1000000;
queue.drain(Integer.MAX_VALUE, new LinkedList<Message>());
////////////////////////////
sink = new QueuedSink() {
@Override
protected void beforePolling() throws IOException {
}
@Override
protected void write(List<Message> msgList) throws IOException {
}
@Override
protected void innerClose() throws IOException {
}
};
sink.initialize(null, queue, 100, 1000, true);
sink.throughput.increment(initialCount);
for (int i = 0; i < initialCount; ++i) {
queue.offer(new Message("routingKey", ("testMessage" + i).getBytes()));
}
assertTrue(sink.checkPause() < queue.size() && sink.checkPause() > 0);
}