Exemplo n.º 1
0
  @Test
  public void testTransactionalQueueGetsOfferedItems_whenBlockedOnPoll()
      throws InterruptedException {
    final String item = "offered1";
    final String queueName = randomString();
    final IQueue queue1 = client.getQueue(queueName);

    final CountDownLatch justBeforeBlocked = new CountDownLatch(1);

    new Thread() {
      public void run() {
        try {
          justBeforeBlocked.await();
          sleepSeconds(1);
          queue1.offer(item);
        } catch (InterruptedException e) {
          fail("failed" + e);
        }
      }
    }.start();

    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    TransactionalQueue txnQueue1 = context.getQueue(queueName);

    justBeforeBlocked.countDown();
    Object result = txnQueue1.poll(5, TimeUnit.SECONDS);

    assertEquals(
        "TransactionalQueue while blocked in pol should get item offered from client queue",
        item,
        result);

    context.commitTransaction();
  }
Exemplo n.º 2
0
 @Test
 public void testTransactionalOfferAndPollWithTimeout() throws InterruptedException {
   final String item = "offered";
   final String name = randomString();
   final TransactionContext context = client.newTransactionContext();
   context.beginTransaction();
   TransactionalQueue<String> txnQueue = context.getQueue(name);
   assertTrue(txnQueue.offer(item));
   assertEquals(1, txnQueue.size());
   assertEquals(item, txnQueue.poll(5, TimeUnit.SECONDS));
   context.commitTransaction();
 }
Exemplo n.º 3
0
  @Test
  public void testTransactionalOfferPoll() {
    final String item = "offered";
    final String queueName = randomString();
    final IQueue queue = client.getQueue(queueName);

    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    TransactionalQueue txnQueue = context.getQueue(queueName);
    txnQueue.offer(item);
    assertEquals(item, txnQueue.poll());
    context.commitTransaction();
  }