Search in sources :

Example 11 with CopyOnWriteArraySet

use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.

the class CopyOnWriteArraySetTest method testConstructor3.

/**
     * Collection-constructed set holds all of its elements
     */
public void testConstructor3() {
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i);
    CopyOnWriteArraySet a = new CopyOnWriteArraySet(Arrays.asList(ints));
    for (int i = 0; i < SIZE; ++i) assertTrue(a.contains(ints[i]));
}
Also used : CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Example 12 with CopyOnWriteArraySet

use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.

the class CopyOnWriteArraySetTest method testToString.

/**
     * toString holds toString of elements
     */
public void testToString() {
    assertEquals("[]", new CopyOnWriteArraySet().toString());
    Collection full = populatedSet(3);
    String s = full.toString();
    for (int i = 0; i < 3; ++i) assertTrue(s.contains(String.valueOf(i)));
    assertEquals(new ArrayList(full).toString(), full.toString());
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Example 13 with CopyOnWriteArraySet

use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.

the class CopyOnWriteArraySetTest method testToArray2.

/**
     * toArray(Integer array) returns an Integer array containing all
     * elements from the set in insertion order
     */
public void testToArray2() {
    Collection empty = new CopyOnWriteArraySet();
    Integer[] a;
    a = new Integer[0];
    assertSame(a, empty.toArray(a));
    a = new Integer[SIZE / 2];
    Arrays.fill(a, 42);
    assertSame(a, empty.toArray(a));
    assertNull(a[0]);
    for (int i = 1; i < a.length; i++) assertEquals(42, (int) a[i]);
    Integer[] elements = new Integer[SIZE];
    for (int i = 0; i < SIZE; i++) elements[i] = i;
    Collections.shuffle(Arrays.asList(elements));
    Collection<Integer> full = populatedSet(elements);
    Arrays.fill(a, 42);
    assertTrue(Arrays.equals(elements, full.toArray(a)));
    for (int i = 0; i < a.length; i++) assertEquals(42, (int) a[i]);
    assertSame(Integer[].class, full.toArray(a).getClass());
    a = new Integer[SIZE];
    Arrays.fill(a, 42);
    assertSame(a, full.toArray(a));
    assertTrue(Arrays.equals(elements, a));
    a = new Integer[2 * SIZE];
    Arrays.fill(a, 42);
    assertSame(a, full.toArray(a));
    assertTrue(Arrays.equals(elements, Arrays.copyOf(a, SIZE)));
    assertNull(a[SIZE]);
    for (int i = SIZE + 1; i < a.length; i++) assertEquals(42, (int) a[i]);
}
Also used : Collection(java.util.Collection) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Example 14 with CopyOnWriteArraySet

use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.

the class CopyOnWriteArraySetTest method testIterator.

/**
     * iterator() returns an iterator containing the elements of the
     * set in insertion order
     */
public void testIterator() {
    Collection empty = new CopyOnWriteArraySet();
    assertFalse(empty.iterator().hasNext());
    try {
        empty.iterator().next();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
    Integer[] elements = new Integer[SIZE];
    for (int i = 0; i < SIZE; i++) elements[i] = i;
    Collections.shuffle(Arrays.asList(elements));
    Collection<Integer> full = populatedSet(elements);
    Iterator it = full.iterator();
    for (int j = 0; j < SIZE; j++) {
        assertTrue(it.hasNext());
        assertEquals(elements[j], it.next());
    }
    assertIteratorExhausted(it);
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) NoSuchElementException(java.util.NoSuchElementException)

Example 15 with CopyOnWriteArraySet

use of java.util.concurrent.CopyOnWriteArraySet in project mapdb by jankotek.

the class CopyOnWriteArraySetTest method testAddAll_idempotent.

/**
     * addAll is idempotent
     */
public void testAddAll_idempotent() throws Exception {
    Set x = populatedSet(SIZE);
    Set y = new CopyOnWriteArraySet(x);
    y.addAll(x);
    assertEquals(x, y);
    assertEquals(y, x);
}
Also used : Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Aggregations

CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)24 Set (java.util.Set)6 Collection (java.util.Collection)5 Test (org.junit.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MapEvent (com.hazelcast.core.MapEvent)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 ObjectName (javax.management.ObjectName)2 RegistryDonePlugin (aQute.bnd.service.RegistryDonePlugin)1 DefaultExecutorServiceHandler (com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1