Пример #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();
  }
Пример #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();
 }
Пример #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();
  }
Пример #4
0
  @Test
  public void testTransactionalOfferRoleBack() {
    final String name = randomString();
    final IQueue queue = client.getQueue(name);

    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    TransactionalQueue<String> qTxn = context.getQueue(name);
    qTxn.offer("ITEM");
    context.rollbackTransaction();

    assertEquals(0, queue.size());
  }
Пример #5
0
  @Test
  public void testTransactionalQueueSize() {
    final String item = "offered";
    final String name = randomString();
    final IQueue queue = client.getQueue(name);

    queue.offer(item);

    final TransactionContext context = client.newTransactionContext();
    context.beginTransaction();
    TransactionalQueue<String> txnQueue = context.getQueue(name);

    txnQueue.offer(item);
    assertEquals(2, txnQueue.size());

    context.rollbackTransaction();
  }