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);
}