use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class BuryProducerIntegrationTest method testBury.
@Ignore("requires reserve - bury sequence")
@Test
public void testBury() throws InterruptedException, IOException {
long jobId = writer.put(0, 0, 5, new byte[0]);
assertTrue("Valid Job Id", jobId > 0);
resultEndpoint.expectedMessageCount(1);
resultEndpoint.allMessages().header(Headers.JOB_ID).isNotNull();
resultEndpoint.allMessages().header(Headers.RESULT).isEqualTo(true);
direct.sendBodyAndHeader(null, Headers.JOB_ID, jobId);
assertMockEndpointsSatisfied();
final Long messageJobId = resultEndpoint.getReceivedExchanges().get(0).getIn().getHeader(Headers.JOB_ID, Long.class);
assertNotNull("Job ID in message", messageJobId);
assertEquals("Message Job ID equals", jobId, messageJobId.longValue());
final Job job = reader.reserve(0);
assertNull("Beanstalk client has no message", job);
final Job buried = reader.peekBuried();
assertNotNull("Job in buried", buried);
assertEquals("Buried job id", jobId, buried.getJobId());
}
use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class PutProducerIntegrationTest method testPut.
@Test
public void testPut() throws InterruptedException, IOException {
resultEndpoint.expectedMessageCount(1);
resultEndpoint.allMessages().header(Headers.JOB_ID).isNotNull();
direct.sendBody(testMessage);
resultEndpoint.assertIsSatisfied();
final Long jobId = resultEndpoint.getReceivedExchanges().get(0).getIn().getHeader(Headers.JOB_ID, Long.class);
assertNotNull("Job ID in 'In' message", jobId);
final Job job = reader.reserve(5);
assertNotNull("Beanstalk client got message", job);
assertEquals("Job body from the server", testMessage, new String(job.getData()));
assertEquals("Job ID from the server", jobId.longValue(), job.getJobId());
reader.delete(jobId);
}
use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class ReleaseProducerIntegrationTest method testBury.
@Ignore("requires reserve - release sequence")
@Test
public void testBury() throws InterruptedException, IOException {
long jobId = writer.put(0, 0, 5, new byte[0]);
assertTrue("Valid Job Id", jobId > 0);
resultEndpoint.expectedMessageCount(1);
resultEndpoint.allMessages().header(Headers.JOB_ID).isNotNull();
resultEndpoint.allMessages().header(Headers.RESULT).isEqualTo(true);
direct.sendBodyAndHeader(null, Headers.JOB_ID, jobId);
assertMockEndpointsSatisfied();
final Long messageJobId = resultEndpoint.getReceivedExchanges().get(0).getIn().getHeader(Headers.JOB_ID, Long.class);
assertNotNull("Job ID in message", messageJobId);
assertEquals("Message Job ID equals", jobId, messageJobId.longValue());
final Job job = reader.reserve(0);
assertNull("Beanstalk client has no message", job);
final Job buried = reader.peekBuried();
assertNotNull("Job in buried", buried);
assertEquals("Buried job id", jobId, buried.getJobId());
}
use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class ImmediateConsumerTest method testDeleteOnFailure.
@Test
public void testDeleteOnFailure() throws Exception {
shouldIdie = true;
final long jobId = 111;
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);
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMinimumMessageCount(1);
result.assertIsNotSatisfied(1000);
verify(client, atLeastOnce()).reserve(anyInt());
verify(client, atLeast(1)).delete(jobId);
}
use of com.surftools.BeanstalkClient.Job 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();
}
Aggregations