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