use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class ConsumerCompletionTest method testDeleteOnComplete.
@Test
public void testDeleteOnComplete() throws Exception {
if (!canTest()) {
return;
}
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);
when(client.statsJob(anyInt())).thenReturn(null);
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());
verify(client).delete(jobId);
}
use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class DeleteProducerIntegrationTest method testDelete.
@Test
public void testDelete() 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.peek(jobId);
assertNull("Job has been deleted", job);
}
use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class PutProducerIntegrationTest method testOut.
@Test
public void testOut() throws InterruptedException, IOException {
final Endpoint endpoint = context.getEndpoint("beanstalk:" + tubeName);
final Exchange exchange = template.send(endpoint, ExchangePattern.InOut, new Processor() {
public void process(Exchange exchange) {
exchange.getIn().setBody(testMessage);
}
});
final Message out = exchange.getOut();
assertNotNull("Out message", out);
final Long jobId = out.getHeader(Headers.JOB_ID, Long.class);
assertNotNull("Job ID in 'Out' 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 PutProducerIntegrationTest method testDelay.
@Test
public void testDelay() throws InterruptedException, IOException {
final byte[] testBytes = new byte[0];
resultEndpoint.expectedMessageCount(1);
resultEndpoint.allMessages().header(Headers.JOB_ID).isNotNull();
resultEndpoint.expectedBodiesReceived(testBytes);
direct.sendBodyAndHeader(testBytes, Headers.DELAY, 10);
resultEndpoint.assertIsSatisfied();
final Long jobId = resultEndpoint.getReceivedExchanges().get(0).getIn().getHeader(Headers.JOB_ID, Long.class);
assertNotNull("Job ID in message", jobId);
final Job job = reader.reserve(0);
assertNull("Beanstalk client has no message", job);
reader.delete(jobId);
}
use of com.surftools.BeanstalkClient.Job in project camel by apache.
the class TouchProducerIntegrationTest method testBury.
@Ignore("requires reserve - touch 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());
}
Aggregations