use of com.surftools.BeanstalkClient.BeanstalkException in project camel by apache.
the class ProducerTest method test1BeanstalkException.
@Test
public void test1BeanstalkException() throws Exception {
final long priority = 1020;
final int delay = 50;
final int timeToRun = 75;
final byte[] payload = Helper.stringToBytes(testMessage);
final long jobId = 113;
when(client.put(priority, delay, timeToRun, payload)).thenThrow(new BeanstalkException("test")).thenReturn(jobId);
resultEndpoint.expectedMessageCount(1);
resultEndpoint.allMessages().body().isEqualTo(testMessage);
resultEndpoint.allMessages().header(Headers.JOB_ID).isEqualTo(jobId);
direct.sendBodyAndHeader(testMessage, Headers.TIME_TO_RUN, timeToRun);
resultEndpoint.assertIsSatisfied();
final Long jobIdIn = resultEndpoint.getReceivedExchanges().get(0).getIn().getHeader(Headers.JOB_ID, Long.class);
assertNotNull("Job ID in 'In' message", jobIdIn);
verify(client, times(1)).close();
verify(client, times(2)).put(priority, delay, timeToRun, payload);
}
use of com.surftools.BeanstalkClient.BeanstalkException in project camel by apache.
the class AwaitingConsumerTest method testBeanstalkException.
@Test
public void testBeanstalkException() throws Exception {
if (!canTest()) {
return;
}
final Job jobMock = mock(Job.class);
final long jobId = 111;
final byte[] payload = Helper.stringToBytes(testMessage);
when(jobMock.getJobId()).thenReturn(jobId);
when(jobMock.getData()).thenReturn(payload);
when(client.reserve(anyInt())).thenThrow(new BeanstalkException("test")).thenReturn(jobMock);
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(1);
result.expectedBodiesReceived(testMessage);
result.expectedHeaderReceived(Headers.JOB_ID, jobId);
result.message(0).header(Headers.JOB_ID).isEqualTo(jobId);
result.assertIsSatisfied(100);
verify(client, atLeast(1)).reserve(anyInt());
verify(client, times(1)).close();
}
use of com.surftools.BeanstalkClient.BeanstalkException in project camel by apache.
the class ConsumerCompletionTest method testBeanstalkException.
@Test
public void testBeanstalkException() throws Exception {
if (!canTest()) {
return;
}
shouldIdie = false;
final Job jobMock = mock(Job.class);
final long jobId = 111;
final byte[] payload = Helper.stringToBytes(testMessage);
when(jobMock.getJobId()).thenReturn(jobId);
when(jobMock.getData()).thenReturn(payload);
when(client.reserve(anyInt())).thenThrow(new BeanstalkException("test")).thenReturn(jobMock);
when(client.statsJob(anyInt())).thenReturn(null);
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(1);
result.expectedBodiesReceived(testMessage);
result.expectedHeaderReceived(Headers.JOB_ID, jobId);
result.message(0).header(Headers.JOB_ID).isEqualTo(jobId);
context.startRoute("foo");
result.assertIsSatisfied();
verify(client, atLeast(1)).reserve(anyInt());
verify(client, times(1)).close();
}
use of com.surftools.BeanstalkClient.BeanstalkException in project camel by apache.
the class ProducerTest method test2BeanstalkException.
@Test
public void test2BeanstalkException() throws Exception {
final long jobId = 111;
when(client.touch(jobId)).thenThrow(new BeanstalkException("test"));
endpoint.setCommand(BeanstalkCommand.touch);
final Exchange exchange = template.send(endpoint, ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) {
exchange.getIn().setHeader(Headers.JOB_ID, jobId);
}
});
assertTrue("Exchange failed", exchange.isFailed());
verify(client, times(2)).touch(jobId);
verify(client, times(1)).close();
}
Aggregations