Package com.surftools.BeanstalkClient

Examples of com.surftools.BeanstalkClient.Client


      }
    }
  }

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

    try {
      client.ignore(null);
      fail("didn't throw");
    } catch (BeanstalkException be) {
      assertEquals("null tubeName", be.getMessage());
    } catch (Exception e) {
      fail("caught unexpected exception: " + e.getClass().getCanonicalName() + ", " + e.getMessage());
    }

    try {
      client.useTube(null);
      fail("didn't throw");
    } catch (BeanstalkException be) {
      assertEquals("null tubeName", be.getMessage());
    } catch (Exception e) {
      fail("caught unexpected exception: " + e.getClass().getCanonicalName() + ", " + e.getMessage());
    }

    try {
      client.watch(null);
      fail("didn't throw");
    } catch (BeanstalkException be) {
      assertEquals("null tubeName", be.getMessage());
    } catch (Exception e) {
      fail("caught unexpected exception: " + e.getClass().getCanonicalName() + ", " + e.getMessage());
View Full Code Here


      fail("caught unexpected exception: " + e.getClass().getCanonicalName() + ", " + e.getMessage());
    }
  }

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

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

    byte[] bytes = "testPutPerformance".getBytes();
    int nIterations = 10;
    long sumMillis = 0;

    for (int i = 0; i < nIterations; ++i) {
      long startMillis = System.currentTimeMillis();
      client.put(0, 0, 120, bytes);
      long deltaMillis = System.currentTimeMillis() - startMillis;
      sumMillis += deltaMillis;
    }

    long averageMillis = sumMillis / nIterations;
View Full Code Here

    long averageMillis = sumMillis / nIterations;
    assertTrue(averageMillis <= 2);
  }

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

    final String DEFAULT_TUBE = "default";
    List<String> tubeNames = client.listTubesWatched();
    assertEquals(1, tubeNames.size());
    assertEquals(DEFAULT_TUBE, tubeNames.get(0));

    int watchCount = client.ignore(DEFAULT_TUBE);
    assertEquals(-1, watchCount);
  }
View Full Code Here

    assertEquals(-1, watchCount);
  }

  public void testPauseTube() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

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

    String srcString = "testPauseTube";
    int delaySeconds = 0;
    int tubeDelay = 3;

    // producer
    client.useTube((String) tubeNames[1]);
    // now pause the tube
    client.pauseTube((String) tubeNames[1], tubeDelay);

    // note we adjust delay
    long jobId = client.put(65536, delaySeconds, 120, srcString.getBytes());
    assertTrue(jobId > 0);

    // peekReady (but we still can't reserve because of tube delay)
    Job job = client.peekReady();
    assertNotNull(job);
    assertEquals(jobId, job.getJobId());

    // reserve with timeout a little less than tube pause time
    job = client.reserve(tubeDelay - 1);
    assertNull(job);

    // now wait for tube to become un-paused
    job = client.reserve(2);
    assertNotNull(job);
    assertEquals(jobId, job.getJobId());

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

    popWatchedTubes(client, tubeNames);
  }

  public void testBuryKickJob() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    Object[] tubeNames = pushWatchedTubes(client);

    String srcString = "testBuryKickJob";

    // nothing to bury
    boolean ok = false;
    ok = client.bury(0, 65536);
    assertFalse(ok);

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

    // we haven't reserved, so we can't bury
    ok = client.bury(jobId, 65536);
    assertFalse(ok);

    // we can bury
    Job job = client.reserve(0);
    assertNotNull(job);
    ok = client.bury(jobId, 65536);
    assertTrue(ok);

    // nothing to reserve
    job = client.reserve(0);
    assertNull(job);

    // kick non-existent job
    ok = client.kickJob(Integer.MAX_VALUE);
    assertFalse(ok);

    // kick something
    ok = client.kickJob(jobId);
    assertTrue(ok);

    client.delete(jobId);

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

    popWatchedTubes(client, tubeNames);
  }

  public void testTouch() {

    Client client = new ClientImpl(TEST_HOST, TEST_PORT);

    Object[] tubeNames = pushWatchedTubes(client);

    String srcString = "testTouch";
    int timeoutSeconds = 2;

    // nothing to touch
    boolean ok = false;
    ok = client.touch(0);
    assertFalse(ok);

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

    // we haven't reserved, so we can't touch
    ok = client.touch(jobId);
    assertFalse(ok);

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

    // try to reserve another job
    try {
      job = client.reserve(2 * timeoutSeconds);
      fail("expected DEADLINE_SOON");
    } catch (BeanstalkException be) {
      String message = be.getMessage();
      assertEquals("DEADLINE_SOON", message);
      ok = client.touch(jobId);
      assertTrue(ok);
    } catch (Exception e) {
      fail("caught exception: " + e.getMessage());
    }

    client.delete(jobId);

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

  // ****************************************************************
  // Consumer methods
  // stats-related
  // ****************************************************************
  public void testListTubeUsed() {
    Client client = new ClientImpl(TEST_HOST, TEST_PORT);
    String s = client.listTubeUsed();
    assertNotNull(s);

    boolean dump = false;
    if (dump) {
      System.out.println("using tube: " + s);
View Full Code Here

      System.out.println("using tube: " + s);
    }
  }

  public void testListTubes() {
    Client client = new ClientImpl(TEST_HOST, TEST_PORT);
    List<String> list = client.listTubes();
    assertNotNull(list);

    boolean dump = false;
    if (dump) {
      for (String tube : list) {
View Full Code Here

      }
    }
  }

  public void testListTubesWatched() {
    Client client = new ClientImpl(TEST_HOST, TEST_PORT);
    List<String> list = client.listTubesWatched();
    assertNotNull(list);
    int initialWatchCount = list.size();
    assertTrue(initialWatchCount >= 1);

    String tubeName = "tube-" + UUID.randomUUID().toString();
    int watchCount = client.watch(tubeName);
    assertEquals(initialWatchCount + 1, watchCount);

    list = client.listTubesWatched();
    assertNotNull(list);
    assertEquals(watchCount, list.size());
    assertTrue(list.contains(tubeName));

    boolean dump = false;
    if (dump) {
      for (String tube : list) {
        System.out.println("watching tube: " + tube);
      }
    }

    watchCount = client.ignore(tubeName);
    assertEquals(initialWatchCount, watchCount);
    list = client.listTubesWatched();
    assertNotNull(list);
    assertEquals(initialWatchCount, list.size());
    assertFalse(list.contains(tubeName));

  }
View Full Code Here

    assertFalse(list.contains(tubeName));

  }

  public void testStats() {
    Client client = new ClientImpl(TEST_HOST, TEST_PORT);
    Map<String, String> map = client.stats();
    assertNotNull(map);

    boolean dump = false;
    if (dump) {
      for (String key : map.keySet()) {
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.