Search in sources :

Example 1 with Job

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

Example 2 with Job

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

Example 3 with Job

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

Example 4 with Job

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

Example 5 with Job

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