Package com.surftools.BeanstalkClient

Examples of com.surftools.BeanstalkClient.Client


    }
  }

  public void testStatsTube() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    Map<String, String> map = client.statsTube(null);
    assertNull(map);

    map = client.statsTube("tube-" + UUID.randomUUID().toString());
    assertNull(map);

    Object[] tubeNames = pushWatchedTubes(client);

    String srcString = "testStatsTube";

    // producer
    client.useTube((String) tubeNames[1]);
    long jobId = client.put(65536, 0, 120, srcString.getBytes());
    assertTrue(jobId > 0);

    Job job = client.reserve(null);
    assertNotNull(job);
    client.delete(jobId);

    map = client.statsTube((String) tubeNames[1]);
    assertNotNull(map);

    boolean dump = false;
    if (dump) {
      for (String key : map.keySet()) {
View Full Code Here


    popWatchedTubes(client, tubeNames);
  }

  public void testStatsJob() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    Map<String, String> map = client.statsJob(0);
    assertNull(map);

    Object[] tubeNames = pushWatchedTubes(client);

    String srcString = "testStatsJob";

    // producer
    client.useTube((String) tubeNames[1]);
    long jobId = client.put(65536, 0, 120, srcString.getBytes());
    assertTrue(jobId > 0);

    Job job = client.reserve(null);
    assertNotNull(job);

    map = client.statsJob(jobId);
    assertNotNull(map);

    boolean dump = false;
    if (dump) {
      for (String key : map.keySet()) {
        System.out.println("key = " + key + ", ==> " + map.get(key));
      }
    }

    client.delete(jobId);

    popWatchedTubes(client, tubeNames);
  }
View Full Code Here

  // Consumer methods
  // peek-related
  // ****************************************************************
  public void testPeek() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    Object[] tubeNames = pushWatchedTubes(client);
    client.useTube((String) tubeNames[1]);

    Job job = client.peek(-1);
    assertNull(job);
    job = client.peek(0);
    assertNull(job);

    String srcString = "testPeek-";

    int nJobs = 3;
    long[] jobIds = new long[nJobs];

    // producer
    for (int i = 0; i < nJobs; ++i) {
      client.useTube((String) tubeNames[1]);
      long jobId = client.put(65536, 0, 120, (srcString + i).getBytes());
      assertTrue(jobId > 0);
      jobIds[i] = jobId;
    }

    // peek 'em once
    for (int i = 0; i < nJobs; ++i) {
      job = client.peek(jobIds[i]);
      assertNotNull(job);
      assertEquals(jobIds[i], job.getJobId());
    }

    // peek 'em again
    for (int i = 0; i < nJobs; ++i) {
      job = client.peek(jobIds[i]);
      assertNotNull(job);
      assertEquals(jobIds[i], job.getJobId());
    }

    // reserve and delete
    for (int i = 0; i < nJobs; ++i) {
      job = client.reserve(null);
      assertNotNull(job);
      assertEquals(jobIds[i], job.getJobId());
      client.delete(job.getJobId());
    }

    // peek one last time
    for (int i = 0; i < nJobs; ++i) {
      job = client.peek(jobIds[i]);
      assertNull(job);
    }

    popWatchedTubes(client, tubeNames);
  }
View Full Code Here

    popWatchedTubes(client, tubeNames);
  }

  public void testReady() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    Object[] tubeNames = pushWatchedTubes(client);
    client.useTube((String) tubeNames[1]);

    String srcString = "testPeekReady-";

    int nJobs = 3;
    long[] jobIds = new long[nJobs];

    // producer
    for (int i = 0; i < nJobs; ++i) {
      client.useTube((String) tubeNames[1]);
      long jobId = client.put(65536, 0, 120, (srcString + i).getBytes());
      assertTrue(jobId > 0);
      jobIds[i] = jobId;
    }

    // peek 'em once
    Job job = null;
    for (int i = 0; i < nJobs; ++i) {
      job = client.peekReady();
      assertNotNull(job);
      assertEquals(jobIds[0], job.getJobId());
    }

    // reserve and delete
    for (int i = 0; i < nJobs; ++i) {
      job = client.reserve(null);
      assertNotNull(job);
      assertEquals(jobIds[i], job.getJobId());
      client.delete(job.getJobId());
    }

    // peek one last time
    for (int i = 0; i < nJobs; ++i) {
      job = client.peekReady();
      assertNull(job);
    }

    popWatchedTubes(client, tubeNames);
  }
View Full Code Here

    popWatchedTubes(client, tubeNames);
  }

  public void testDelayed() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    Object[] tubeNames = pushWatchedTubes(client);
    client.useTube((String) tubeNames[1]);

    String srcString = "testPeekDelay";
    int delaySeconds = 2;

    // producer
    client.useTube((String) tubeNames[1]);
    // note we adjust delay
    long jobId = client.put(65536, delaySeconds, 120, srcString.getBytes());
    assertTrue(jobId > 0);

    // peekDelayed
    Job job = client.peekDelayed();
    assertNotNull(job);
    assertEquals(jobId, job.getJobId());

    try {
      Thread.sleep(delaySeconds * 1000);
    } catch (Exception e) {

    }

    // reserve and delete
    job = client.reserve(null);
    assertNotNull(job);
    assertEquals(jobId, job.getJobId());
    client.delete(job.getJobId());

    // peek one last time
    job = client.peekDelayed();
    assertNull(job);

    popWatchedTubes(client, tubeNames);
  }
View Full Code Here

    popWatchedTubes(client, tubeNames);
  }

  public void testBuried() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    Object[] tubeNames = pushWatchedTubes(client);
    client.useTube((String) tubeNames[1]);

    String srcString = "testPeekBuried";

    // peekBuried
    Job job = client.peekBuried();
    assertNull(job);

    // producer
    long jobId = client.put(65536, 0, 120, srcString.getBytes());
    assertTrue(jobId > 0);

    // peekBuried
    job = client.peekBuried();
    assertNull(job);

    // reserve and bury
    job = client.reserve(null);
    assertNotNull(job);
    assertEquals(jobId, job.getJobId());
    client.bury(job.getJobId(), 65536);

    // peekBuried
    job = client.peekBuried();
    assertNotNull(job);
    assertEquals(jobId, job.getJobId());

    // delete
    client.delete(jobId);

    // peekBuried
    job = client.peekBuried();
    assertNull(job);

    popWatchedTubes(client, tubeNames);
  }
View Full Code Here

    popWatchedTubes(client, tubeNames);
  }

  public void testClose() {
    Client client = new ClientImpl(TEST_HOST, TEST_PORT);
    String s = client.listTubeUsed();
    assertNotNull(s);

    client.close();
    try {
      client.listTubeUsed();
      fail("didn't throw expected exception");
    } catch (BeanstalkException be) {
      String message = be.getMessage();
      assertEquals("Socket is closed", message);
    } catch (Exception e) {
      fail("caught exception: " + e.getMessage());
    }

    // close again
    client.close();
    try {
      client.listTubeUsed();
      fail("didn't throw expected exception");
    } catch (BeanstalkException be) {
      String message = be.getMessage();
      assertEquals("Socket is closed", message);
    } catch (Exception e) {
View Full Code Here

    String remoteHost = TEST_HOST;
    int nIterations = 100;
    for (int i = 0; i < nIterations; ++i) {
      Set<Boolean> blockModes = new HashSet<Boolean>(Arrays.asList(new Boolean[] { false, true }));
      for (boolean useBlockIO : blockModes) {
        Client client = new ClientImpl(remoteHost, TEST_PORT, useBlockIO);

        Object[] tubeNames = pushWatchedTubes(client);

        String srcString = "testUseBlockIO";

        // producer
        client.useTube((String) tubeNames[1]);
        long jobId = client.put(65536, 0, 120, srcString.getBytes());
        assertTrue(jobId > 0);

        // consumer
        Job job = client.reserve(null);
        assertNotNull(job);
        long newJobId = job.getJobId();
        assertEquals(jobId, newJobId);

        String dstString = new String(job.getData());
        assertEquals(srcString, dstString);

        client.delete(job.getJobId());

        popWatchedTubes(client, tubeNames);

        client.close();
      }
    }
  }
View Full Code Here

  // ****************************************************************
  // Producer methods
  // ****************************************************************

  public void testGetServerVersion() {
    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    String serverVersion = client.getServerVersion();
    assertNotNull(serverVersion);

    String[] tokens = serverVersion.split(VERSION_DELIMITERS);
    assertTrue(tokens.length >= 2);

View Full Code Here

  }

  public void testBinaryData() {

    for (boolean useBlockIO : new boolean[] { false, true }) {
      Client client = new ClientImpl(TEST_HOST, TEST_PORT, useBlockIO);

      Object[] tubeNames = pushWatchedTubes(client);

      byte[] srcBytes = new byte[256];
      for (int i = 0; i < srcBytes.length; ++i) {
        srcBytes[i] = (byte) i;
      }

      // producer
      client.useTube((String) tubeNames[1]);
      long jobId = client.put(65536, 0, 120, srcBytes);
      assertTrue(jobId > 0);

      // consumer
      Job job = client.reserve(null);
      assertNotNull(job);
      long newJobId = job.getJobId();
      assertEquals(jobId, newJobId);

      // verify bytes
      byte[] dstBytes = job.getData();
      assertEquals(srcBytes.length, dstBytes.length);
      for (int i = 0; i < srcBytes.length; ++i) {
        assertEquals(srcBytes[i], dstBytes[i]);
      }

      client.delete(job.getJobId());

      popWatchedTubes(client, tubeNames);
    }
  }
View Full Code Here

TOP

Related Classes of com.surftools.BeanstalkClient.Client

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.