@Test
public void testOffer() throws IOException, InterruptedException {
final IQueue q = getQueue();
final SimpleClient client = getClient();
client.send(new OfferRequest(queueName, ss.toData("item1")));
Object result = client.receive();
assertTrue((Boolean) result);
Object item = q.peek();
assertEquals(item, "item1");
q.offer("item2");
q.offer("item3");
q.offer("item4");
q.offer("item5");
q.offer("item6");
final CountDownLatch latch = new CountDownLatch(1);
new Thread() {
public void run() {
try {
latch.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
q.poll();
}
}.start();
client.send(new OfferRequest(queueName, 500, ss.toData("item7")));
result = client.receive();
assertFalse((Boolean) result);
client.send(new OfferRequest(queueName, 10 * 1000, ss.toData("item7")));
Thread.sleep(1000);
latch.countDown();
result = client.receive();
assertTrue((Boolean) result);
}