@Test
  public void testQueueSplitBrain() throws InterruptedException {
    Config config = newConfig();
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance h3 = Hazelcast.newHazelcastInstance(config);
    final String name = generateKeyOwnedBy(h1);
    IQueue<Object> queue = h1.getQueue(name);

    TestMemberShipListener memberShipListener = new TestMemberShipListener(2);
    h3.getCluster().addMembershipListener(memberShipListener);
    TestLifeCycleListener lifeCycleListener = new TestLifeCycleListener(1);
    h3.getLifecycleService().addLifecycleListener(lifeCycleListener);

    for (int i = 0; i < 100; i++) {
      queue.add("item" + i);
    }

    waitAllForSafeState();

    closeConnectionBetween(h1, h3);
    closeConnectionBetween(h2, h3);

    assertOpenEventually(memberShipListener.latch);
    assertClusterSizeEventually(2, h1);
    assertClusterSizeEventually(2, h2);
    assertClusterSizeEventually(1, h3);

    for (int i = 100; i < 200; i++) {
      queue.add("item" + i);
    }

    IQueue<Object> queue3 = h3.getQueue(name);
    for (int i = 0; i < 50; i++) {
      queue3.add("lostQueueItem" + i);
    }

    assertOpenEventually(lifeCycleListener.latch);
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);

    IQueue<Object> testQueue = h1.getQueue(name);
    assertFalse(testQueue.contains("lostQueueItem0"));
    assertFalse(testQueue.contains("lostQueueItem49"));
    assertTrue(testQueue.contains("item0"));
    assertTrue(testQueue.contains("item199"));
    assertTrue(testQueue.contains("item121"));
    assertTrue(testQueue.contains("item45"));
  }
Esempio n. 2
0
  @Test
  public void testSize() {
    final int maxItems = 143;
    final IQueue q = client.getQueue(randomString());

    for (int i = 0; i < maxItems; i++) {
      q.add(i);
    }
    assertEquals(maxItems, q.size());
  }
Esempio n. 3
0
  @Test
  public void testRetainEmptyList() throws IOException {
    final int maxItems = 131;
    final IQueue q = client.getQueue(randomString());

    for (int i = 0; i < maxItems; i++) {
      q.add(i);
    }

    List retain = new LinkedList();
    assertTrue(q.retainAll(retain));
    assertEquals(0, q.size());
  }
  @Test
  public void test() {
    List<Object> expectedItems = new LinkedList<Object>();
    for (int k = 0; k < 100; k++) {
      queue.add(k);
      expectedItems.add(k);
    }

    remote1.shutdown();
    remote2.shutdown();

    assertEquals(expectedItems.size(), queue.size());
    List actualItems = Arrays.asList(queue.toArray());
    assertEquals(expectedItems, actualItems);
  }
Esempio n. 5
0
  @Test
  public void testRemoveList_whereNotFound() throws IOException {
    final int maxItems = 131;
    final IQueue q = client.getQueue(randomString());

    List removeList = new LinkedList();
    for (int i = 0; i < maxItems; i++) {
      q.add(i);
    }
    removeList.add(maxItems + 1);
    removeList.add(maxItems + 2);

    assertFalse(q.removeAll(removeList));
    assertEquals(maxItems, q.size());
  }
Esempio n. 6
0
 @Test
 public void testadd() {
   final IQueue q = client.getQueue(randomString());
   assertTrue(q.add(1));
   assertEquals(1, q.size());
 }