popWatchedTubes(client, tubeNames);
}
public void testReserveWithTimeout() {
Client client = new ClientImpl(TEST_HOST, TEST_PORT);
Object[] tubeNames = pushWatchedTubes(client);
String srcString = "testReserveWithTimeout";
int timeoutSeconds = 2;
// producer
client.useTube((String) tubeNames[1]);
long putMillis = System.currentTimeMillis();
long jobId = client.put(65536, timeoutSeconds, 120, srcString.getBytes());
assertTrue(jobId > 0);
// consumer
Job job = client.reserve(timeoutSeconds);
long getMillis = System.currentTimeMillis();
assertNotNull(job);
long newJobId = job.getJobId();
assertEquals(jobId, newJobId);
String dstString = new String(job.getData());
assertEquals(srcString, dstString);
long deltaSeconds = (getMillis - putMillis) / 1000;
assertTrue(deltaSeconds >= timeoutSeconds);
client.delete(job.getJobId());
// now try to achieve a TIMED_OUT
jobId = client.put(65536, 2 * timeoutSeconds, 120, srcString.getBytes());
assertTrue(jobId > 0);
job = client.reserve(timeoutSeconds);
assertNull(job);
popWatchedTubes(client, tubeNames);
}