コード例 #1
0
  /**
   * JUnit.
   *
   * @throws Exception If failed.
   */
  public void testAddPollUnbounded() throws Exception {
    // Random queue name.
    String queueName = UUID.randomUUID().toString();

    IgniteQueue<String> queue = grid(0).queue(queueName, 0, config(false));

    assert queue.add("1");

    assert queue.add("2");

    assert queue.add("3");

    assertEquals("1", queue.poll());
    assertEquals("2", queue.poll());
    assertEquals("3", queue.poll());
  }
コード例 #2
0
  /**
   * JUnit.
   *
   * @throws Exception If failed.
   */
  public void testAddPeekUnbounded() throws Exception {
    // Random queue name.
    String queueName = UUID.randomUUID().toString();

    IgniteQueue<String> queue = grid(0).queue(queueName, 0, config(false));

    String item1 = "1";
    assert queue.add(item1);

    String item2 = "2";
    assert queue.add(item2);

    String item3 = "3";
    assert queue.add(item3);

    assert item1.equals(queue.peek());
    assert item1.equals(queue.peek());
    assert !item2.equals(queue.peek());
  }
コード例 #3
0
  /**
   * JUnit.
   *
   * @throws Exception If failed.
   */
  public void testAddUnbounded() throws Exception {
    // Random queue name.
    String queueName = UUID.randomUUID().toString();

    String val = UUID.randomUUID().toString();

    IgniteQueue<String> queue = grid(0).queue(queueName, 0, config(false));

    assert queue.add(val);

    assert val.equals(queue.poll());
  }
コード例 #4
0
  /**
   * JUnit.
   *
   * @throws Exception If failed.
   */
  public void testAddDeleteUnbounded() throws Exception {
    // Random queue name.
    String queueName = UUID.randomUUID().toString();

    String val = UUID.randomUUID().toString();

    IgniteQueue<String> queue = grid(0).queue(queueName, 0, config(false));

    assert queue.add(val);

    assert queue.remove(val);

    assert queue.isEmpty();
  }
コード例 #5
0
  /**
   * JUnit.
   *
   * @throws Exception If failed.
   */
  public void testIterator() throws Exception {
    // Random queue name.
    String queueName = UUID.randomUUID().toString();

    IgniteQueue<String> queue = grid(0).queue(queueName, 0, config(false));

    for (int i = 0; i < 100; i++) assert queue.add(Integer.toString(i));

    Iterator<String> iter1 = queue.iterator();

    int cnt = 0;
    for (int i = 0; i < 100; i++) {
      assertNotNull(iter1.next());
      cnt++;
    }

    assertEquals(100, queue.size());
    assertEquals(100, cnt);

    assertNotNull(queue.take());
    assertNotNull(queue.take());
    assertTrue(queue.remove("33"));
    assertTrue(queue.remove("77"));

    assertEquals(96, queue.size());

    Iterator<String> iter2 = queue.iterator();

    try {
      iter2.remove();
    } catch (IllegalStateException e) {
      info("Caught expected exception: " + e);
    }

    iter2.next();
    iter2.remove();

    cnt = 0;
    while (iter2.hasNext()) {
      assertNotNull(iter2.next());
      cnt++;
    }

    assertEquals(95, cnt);
    assertEquals(95, queue.size());

    iter2.remove();
  }