use of org.apache.camel.Consumer 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.Consumer 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.Consumer 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);
}
use of org.apache.camel.Consumer in project camel by apache.
the class ScheduledPollConsumerTest method testExceptionOnPollAndCanStartAgain.
public void testExceptionOnPollAndCanStartAgain() throws Exception {
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) {
}
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) throws Exception {
if (e == expectedException) {
rollback = true;
}
return false;
}
});
consumer.start();
// poll that throws an exception
consumer.run();
consumer.stop();
assertEquals("Should have rollback", true, rollback);
// prepare for 2nd run but this time it should not thrown an exception on poll
rollback = false;
consumer.setExceptionToThrowOnPoll(null);
// start it again and we should be able to run
consumer.start();
consumer.run();
// should be able to stop with no problem
consumer.stop();
assertEquals("Should not have rollback", false, rollback);
}
use of org.apache.camel.Consumer in project camel by apache.
the class SWFEndpoint method createConsumer.
public Consumer createConsumer(Processor processor) throws Exception {
Consumer consumer = isWorkflow() ? new SWFWorkflowConsumer(this, processor, configuration) : new SWFActivityConsumer(this, processor, configuration);
configureConsumer(consumer);
return consumer;
}
Aggregations