Search in sources :

Example 1 with BeanstalkException

use of com.surftools.BeanstalkClient.BeanstalkException in project camel by apache.

the class ProducerTest method test1BeanstalkException.

@Test
public void test1BeanstalkException() throws Exception {
    final long priority = 1020;
    final int delay = 50;
    final int timeToRun = 75;
    final byte[] payload = Helper.stringToBytes(testMessage);
    final long jobId = 113;
    when(client.put(priority, delay, timeToRun, payload)).thenThrow(new BeanstalkException("test")).thenReturn(jobId);
    resultEndpoint.expectedMessageCount(1);
    resultEndpoint.allMessages().body().isEqualTo(testMessage);
    resultEndpoint.allMessages().header(Headers.JOB_ID).isEqualTo(jobId);
    direct.sendBodyAndHeader(testMessage, Headers.TIME_TO_RUN, timeToRun);
    resultEndpoint.assertIsSatisfied();
    final Long jobIdIn = resultEndpoint.getReceivedExchanges().get(0).getIn().getHeader(Headers.JOB_ID, Long.class);
    assertNotNull("Job ID in 'In' message", jobIdIn);
    verify(client, times(1)).close();
    verify(client, times(2)).put(priority, delay, timeToRun, payload);
}
Also used : Mockito.anyLong(org.mockito.Mockito.anyLong) BeanstalkException(com.surftools.BeanstalkClient.BeanstalkException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 2 with BeanstalkException

use of com.surftools.BeanstalkClient.BeanstalkException 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)

Example 3 with BeanstalkException

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

Example 4 with BeanstalkException

use of com.surftools.BeanstalkClient.BeanstalkException in project camel by apache.

the class ProducerTest method test2BeanstalkException.

@Test
public void test2BeanstalkException() throws Exception {
    final long jobId = 111;
    when(client.touch(jobId)).thenThrow(new BeanstalkException("test"));
    endpoint.setCommand(BeanstalkCommand.touch);
    final Exchange exchange = template.send(endpoint, ExchangePattern.InOnly, new Processor() {

        public void process(Exchange exchange) {
            exchange.getIn().setHeader(Headers.JOB_ID, jobId);
        }
    });
    assertTrue("Exchange failed", exchange.isFailed());
    verify(client, times(2)).touch(jobId);
    verify(client, times(1)).close();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) BeanstalkException(com.surftools.BeanstalkClient.BeanstalkException) Test(org.junit.Test)

Aggregations

BeanstalkException (com.surftools.BeanstalkClient.BeanstalkException)4 Test (org.junit.Test)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 Job (com.surftools.BeanstalkClient.Job)2 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 Mockito.anyLong (org.mockito.Mockito.anyLong)1