Package com.surftools.BeanstalkClient

Examples of com.surftools.BeanstalkClient.BeanstalkException


        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);
View Full Code Here


    @Test
    public void test2BeanstalkException() throws Exception {
        final long jobId = 111;

        when(client.touch(jobId))
                .thenThrow(new BeanstalkException("test"));

        endpoint.setCommand(BeanstalkComponent.COMMAND_TOUCH);
        final Exchange exchange = template.send(endpoint, ExchangePattern.InOnly, new Processor() {
            public void process(Exchange exchange) {
                exchange.getIn().setHeader(Headers.JOB_ID, jobId);
View Full Code Here

        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);
View Full Code Here

        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);
View Full Code Here

  // ****************************************************************

  @Override
  public long put(long priority, int delaySeconds, int timeToRun, byte[] data) {
    if (data == null) {
      throw new BeanstalkException("null data");
    }
    if (priority > MAX_PRIORITY) {
      throw new BeanstalkException("invalid priority");
    }
    long jobId = -1;
    Request request = new Request("put " + priority + " " + delaySeconds + " " + timeToRun + " " + data.length,
        new String[] { "INSERTED", "BURIED" }, new String[] { "JOB_TOO_BIG" }, data, ExpectedResponse.None);
    Response response = getProtocolHandler().processRequest(request);
    if (response != null && response.getStatus().equals("JOB_TOO_BIG")) {
      BeanstalkException be = new BeanstalkException(response.getStatus());
      throw be;
    }
    if (response != null && response.isMatchOk()) {
      jobId = Long.parseLong(response.getReponse());
    }
View Full Code Here

  }

  @Override
  public void useTube(String tubeName) {
    if (tubeName == null) {
      throw new BeanstalkException("null tubeName");
    }
    Request request = new Request("use " + tubeName, "USING", null, null, ExpectedResponse.None);
    getProtocolHandler().processRequest(request);
  }
View Full Code Here

    String command = (timeoutSeconds == null) ? "reserve" : "reserve-with-timeout " + timeoutSeconds.toString();
    Request request = new Request(command, new String[] { "RESERVED" }, new String[] { "DEADLINE_SOON",
        "TIMED_OUT", }, null, ExpectedResponse.ByteArray, 2);
    Response response = getProtocolHandler().processRequest(request);
    if (response != null && response.getStatus().equals("DEADLINE_SOON")) {
      BeanstalkException be = new BeanstalkException(response.getStatus());
      throw be;
    }
    if (response != null && response.isMatchOk()) {
      long jobId = Long.parseLong(response.getReponse());
      job = new JobImpl(jobId);
View Full Code Here

  // tube-related
  // ****************************************************************
  @Override
  public int watch(String tubeName) {
    if (tubeName == null) {
      throw new BeanstalkException("null tubeName");
    }
    Request request = new Request("watch " + tubeName, "WATCHING", null, null, ExpectedResponse.None);
    Response response = getProtocolHandler().processRequest(request);
    return Integer.parseInt(response.getReponse());
  }
View Full Code Here

  }

  @Override
  public int ignore(String tubeName) {
    if (tubeName == null) {
      throw new BeanstalkException("null tubeName");
    }
    Request request = new Request("ignore " + tubeName, new String[] { "WATCHING", "NOT_IGNORED" }, null, null,
        ExpectedResponse.None);
    Response response = getProtocolHandler().processRequest(request);
    return (response.getReponse() == null) ? -1 : Integer.parseInt(response.getReponse());
View Full Code Here

  @Override
  public String getServerVersion() {
    Map<String, String> stats = stats();
    if (stats == null) {
      throw new BeanstalkException("could not get stats");
    }
    return stats.get("version").trim();
  }
View Full Code Here

TOP

Related Classes of com.surftools.BeanstalkClient.BeanstalkException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.