use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class AwaitingConsumerTest method testReceive.
@Test
public void testReceive() 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())).thenReturn(jobMock).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);
result.assertIsSatisfied(100);
verify(client, atLeast(1)).reserve(0);
verify(client, atLeast(1)).delete(jobId);
}
use of com.surftools.BeanstalkClient.Job 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.Job in project camel by apache.
the class ConsumerCompletionTest method testReleaseOnFailure.
@Test
public void testReleaseOnFailure() throws Exception {
shouldIdie = true;
final long jobId = 111;
final long priority = BeanstalkComponent.DEFAULT_PRIORITY;
final int delay = BeanstalkComponent.DEFAULT_DELAY;
final byte[] payload = Helper.stringToBytes(testMessage);
final Job jobMock = mock(Job.class);
when(jobMock.getJobId()).thenReturn(jobId);
when(jobMock.getData()).thenReturn(payload);
when(client.reserve(anyInt())).thenReturn(jobMock).thenReturn(null);
when(client.statsJob(anyInt())).thenReturn(null);
when(client.release(anyInt(), anyLong(), anyInt())).thenReturn(true);
NotifyBuilder notify = new NotifyBuilder(context).whenFailed(1).create();
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(0);
context.startRoute("foo");
assertTrue(notify.matches(5, TimeUnit.SECONDS));
verify(client, atLeastOnce()).reserve(anyInt());
verify(client, atLeastOnce()).statsJob(anyInt());
verify(client).release(jobId, priority, delay);
}
use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class ConsumerToProducerHeadersTest method testBeanstalkConsumerToProducer.
@Test
public void testBeanstalkConsumerToProducer() throws Exception {
final long jobId = 111;
final byte[] payload = Helper.stringToBytes(testMessage);
final Job jobMock = mock(Job.class);
// stats that may be set in the consumer:
// mock stats : "tube", "state", "age", "time-left", "timeouts", "releases", "buries", "kicks"
Map<String, String> stats = new HashMap<String, String>();
stats.put("tube", "A");
stats.put("state", "Test");
stats.put("age", "0");
stats.put("time-left", "0");
stats.put("timeouts", "0");
stats.put("releases", "0");
stats.put("buries", "0");
stats.put("kicks", "0");
when(jobMock.getJobId()).thenReturn(jobId);
when(jobMock.getData()).thenReturn(payload);
when(client.reserve(anyInt())).thenReturn(jobMock).thenReturn(null);
when(client.statsJob(anyInt())).thenReturn(stats);
when(client.put(BeanstalkComponent.DEFAULT_PRIORITY, BeanstalkComponent.DEFAULT_DELAY, BeanstalkComponent.DEFAULT_TIME_TO_RUN, payload)).thenReturn(jobId);
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMinimumMessageCount(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, atLeastOnce()).reserve(anyInt());
verify(client, atLeastOnce()).statsJob(anyInt());
assertEquals(((TestExchangeCopyProcessor) a).getExchangeCopy().getIn().getHeaders(), ((TestExchangeCopyProcessor) b).getExchangeCopy().getIn().getHeaders());
}
use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class ImmediateConsumerTest method testDeleteOnSuccess.
@Test
public void testDeleteOnSuccess() 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())).thenReturn(jobMock).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);
result.assertIsSatisfied(100);
verify(client, atLeast(1)).reserve(0);
verify(client, atLeast(1)).delete(jobId);
}
Aggregations