use of org.apache.camel.spi.PollingConsumerPollStrategy in project camel by apache.
the class ScheduledPollConsumerBackoffTest method testBackoffError.
public void testBackoffError() throws Exception {
final Endpoint endpoint = getMockEndpoint("mock:foo");
final Exception expectedException = new Exception("Hello, I should be thrown on shutdown only!");
MockScheduledPollConsumer consumer = new MockScheduledPollConsumer(endpoint, expectedException);
consumer.setBackoffMultiplier(4);
consumer.setBackoffErrorThreshold(3);
consumer.setPollStrategy(new PollingConsumerPollStrategy() {
public boolean begin(Consumer consumer, Endpoint endpoint) {
return true;
}
public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {
commits++;
}
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
errors++;
return false;
}
});
consumer.start();
consumer.run();
consumer.run();
consumer.run();
assertEquals(3, errors);
// now it should backoff 4 times
consumer.run();
consumer.run();
consumer.run();
consumer.run();
assertEquals(3, errors);
// and now we poll again
consumer.run();
consumer.run();
consumer.run();
assertEquals(6, errors);
// now it should backoff 4 times
consumer.run();
consumer.run();
consumer.run();
consumer.run();
assertEquals(6, errors);
consumer.stop();
}
use of org.apache.camel.spi.PollingConsumerPollStrategy in project camel by apache.
the class ScheduledPollConsumerBackoffTest method testBackoffIdle.
public void testBackoffIdle() throws Exception {
final Endpoint endpoint = getMockEndpoint("mock:foo");
MockScheduledPollConsumer consumer = new MockScheduledPollConsumer(endpoint, null);
consumer.setBackoffMultiplier(4);
consumer.setBackoffIdleThreshold(2);
consumer.setPollStrategy(new PollingConsumerPollStrategy() {
public boolean begin(Consumer consumer, Endpoint endpoint) {
return true;
}
public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {
commits++;
}
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
return false;
}
});
consumer.start();
consumer.run();
consumer.run();
assertEquals(2, commits);
// now it should backoff 4 times
consumer.run();
consumer.run();
consumer.run();
consumer.run();
assertEquals(2, commits);
// and now we poll again
consumer.run();
consumer.run();
assertEquals(4, commits);
// now it should backoff 4 times
consumer.run();
consumer.run();
consumer.run();
consumer.run();
assertEquals(4, commits);
consumer.run();
assertEquals(5, commits);
consumer.stop();
}
use of org.apache.camel.spi.PollingConsumerPollStrategy in project camel by apache.
the class ScheduledPollConsumerGreedyTest method test321NotGreedy.
public void test321NotGreedy() throws Exception {
polled.set(0);
MockScheduledPollConsumer consumer = new Mock321ScheduledPollConsumer(getMockEndpoint("mock:foo"), null);
consumer.setGreedy(false);
consumer.setPollStrategy(new PollingConsumerPollStrategy() {
public boolean begin(Consumer consumer, Endpoint endpoint) {
return true;
}
public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {
polled.addAndGet(polledMessages);
}
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
return false;
}
});
consumer.start();
consumer.run();
assertEquals(3, polled.get());
consumer.run();
assertEquals(5, polled.get());
consumer.run();
assertEquals(6, polled.get());
consumer.run();
assertEquals(6, polled.get());
consumer.stop();
}
use of org.apache.camel.spi.PollingConsumerPollStrategy in project camel by apache.
the class ScheduledPollConsumerGreedyTest method test321Greedy.
public void test321Greedy() throws Exception {
polled.set(0);
MockScheduledPollConsumer consumer = new Mock321ScheduledPollConsumer(getMockEndpoint("mock:foo"), null);
consumer.setGreedy(true);
consumer.setPollStrategy(new PollingConsumerPollStrategy() {
public boolean begin(Consumer consumer, Endpoint endpoint) {
return true;
}
public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {
polled.addAndGet(polledMessages);
}
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
return false;
}
});
consumer.start();
consumer.run();
assertEquals(6, polled.get());
consumer.stop();
}
use of org.apache.camel.spi.PollingConsumerPollStrategy in project camel by apache.
the class ScheduledPollConsumerTest method testRetryAtMostThreeTimes.
public void testRetryAtMostThreeTimes() throws Exception {
counter = 0;
event = "";
final Exception expectedException = new Exception("Hello, I should be thrown on shutdown only!");
final Endpoint endpoint = getMockEndpoint("mock:foo");
MockScheduledPollConsumer consumer = new MockScheduledPollConsumer(endpoint, expectedException);
consumer.setPollStrategy(new PollingConsumerPollStrategy() {
public boolean begin(Consumer consumer, Endpoint endpoint) {
return true;
}
public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {
event += "commit";
}
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
event += "rollback";
counter++;
if (retryCounter < 3) {
return true;
}
return false;
}
});
consumer.setUseFixedDelay(true);
consumer.setDelay(60000);
consumer.start();
// poll that throws an exception
consumer.run();
consumer.stop();
// 3 retries + 1 last failed attempt when we give up
assertEquals(4, counter);
assertEquals("rollbackrollbackrollbackrollback", event);
}
Aggregations