Search in sources :

Example 6 with Job

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);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Job(com.surftools.BeanstalkClient.Job) Test(org.junit.Test)

Example 7 with Job

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);
}
Also used : Job(com.surftools.BeanstalkClient.Job) Test(org.junit.Test)

Example 8 with 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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Message(org.apache.camel.Message) Job(com.surftools.BeanstalkClient.Job) Test(org.junit.Test)

Example 9 with Job

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);
}
Also used : Job(com.surftools.BeanstalkClient.Job) Test(org.junit.Test)

Example 10 with Job

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());
}
Also used : Job(com.surftools.BeanstalkClient.Job) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Job (com.surftools.BeanstalkClient.Job)15 Test (org.junit.Test)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)9 Ignore (org.junit.Ignore)3 BeanstalkException (com.surftools.BeanstalkClient.BeanstalkException)2 HashMap (java.util.HashMap)1 Endpoint (org.apache.camel.Endpoint)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 Processor (org.apache.camel.Processor)1 NotifyBuilder (org.apache.camel.builder.NotifyBuilder)1