Search in sources :

Example 16 with CopyOnWriteArraySet

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

the class CopyOnWriteArraySetTest method testConstructor.

/**
     * Default-constructed set is empty
     */
public void testConstructor() {
    CopyOnWriteArraySet a = new CopyOnWriteArraySet();
    assertTrue(a.isEmpty());
}
Also used : CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Example 17 with CopyOnWriteArraySet

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

the class CopyOnWriteArraySetTest method testEquals.

/**
     * Sets with equal elements are equal
     */
public void testEquals() {
    CopyOnWriteArraySet a = populatedSet(3);
    CopyOnWriteArraySet b = populatedSet(3);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());
    assertEquals(a.size(), b.size());
    a.add(m1);
    assertFalse(a.equals(b));
    assertFalse(b.equals(a));
    assertTrue(a.containsAll(b));
    assertFalse(b.containsAll(a));
    b.add(m1);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());
    Object x = a.iterator().next();
    a.remove(x);
    assertFalse(a.equals(b));
    assertFalse(b.equals(a));
    assertFalse(a.containsAll(b));
    assertTrue(b.containsAll(a));
    a.add(x);
    assertTrue(a.equals(b));
    assertTrue(b.equals(a));
    assertTrue(a.containsAll(b));
    assertTrue(b.containsAll(a));
    assertEquals(a.hashCode(), b.hashCode());
    assertEquals(a.size(), b.size());
    CopyOnWriteArraySet empty1 = new CopyOnWriteArraySet(Arrays.asList());
    CopyOnWriteArraySet empty2 = new CopyOnWriteArraySet(Arrays.asList());
    assertTrue(empty1.equals(empty1));
    assertTrue(empty1.equals(empty2));
    assertFalse(empty1.equals(a));
    assertFalse(a.equals(empty1));
    assertFalse(a.equals(null));
}
Also used : CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Example 18 with CopyOnWriteArraySet

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

the class CopyOnWriteArraySetTest method testToArray.

/**
     * toArray() returns an Object array containing all elements from
     * the set in insertion order
     */
public void testToArray() {
    Object[] a = new CopyOnWriteArraySet().toArray();
    assertTrue(Arrays.equals(new Object[0], a));
    assertSame(Object[].class, a.getClass());
    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);
    assertTrue(Arrays.equals(elements, full.toArray()));
    assertSame(Object[].class, full.toArray().getClass());
}
Also used : CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Example 19 with CopyOnWriteArraySet

use of java.util.concurrent.CopyOnWriteArraySet in project hazelcast by hazelcast.

the class MultiMapTestsFrom2X method testMultiMapEntryListener.

@Test
public void testMultiMapEntryListener() {
    final HazelcastInstance instance = createHazelcastInstance();
    MultiMap<String, String> map = instance.getMultiMap("testMultiMapEntryListener");
    final CountDownLatch latchAdded = new CountDownLatch(3);
    final CountDownLatch latchRemoved = new CountDownLatch(1);
    final CountDownLatch latchCleared = new CountDownLatch(1);
    final Set<String> expectedValues = new CopyOnWriteArraySet<String>();
    expectedValues.add("hello");
    expectedValues.add("world");
    expectedValues.add("again");
    map.addEntryListener(new EntryAdapter<String, String>() {

        public void entryAdded(EntryEvent<String, String> event) {
            String key = event.getKey();
            String value = event.getValue();
            if ("2".equals(key)) {
                assertEquals("again", value);
            } else {
                assertEquals("1", key);
            }
            assertContains(expectedValues, value);
            expectedValues.remove(value);
            latchAdded.countDown();
        }

        public void entryRemoved(EntryEvent<String, String> event) {
            assertEquals("2", event.getKey());
            assertEquals("again", event.getOldValue());
            latchRemoved.countDown();
        }

        public void entryUpdated(EntryEvent<String, String> event) {
            throw new AssertionError("MultiMap cannot get update event!");
        }

        public void entryEvicted(EntryEvent<String, String> event) {
            entryRemoved(event);
        }

        @Override
        public void mapEvicted(MapEvent event) {
        }

        @Override
        public void mapCleared(MapEvent event) {
            latchCleared.countDown();
        }
    }, true);
    map.put("1", "hello");
    map.put("1", "world");
    map.put("2", "again");
    Collection<String> values = map.get("1");
    assertEquals(2, values.size());
    assertContains(values, "hello");
    assertContains(values, "world");
    assertEquals(1, map.get("2").size());
    assertEquals(3, map.size());
    map.remove("2");
    assertEquals(2, map.size());
    map.clear();
    try {
        assertTrue(latchAdded.await(5, TimeUnit.SECONDS));
        assertTrue(latchRemoved.await(5, TimeUnit.SECONDS));
        assertTrue(latchCleared.await(5, TimeUnit.SECONDS));
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MapEvent(com.hazelcast.core.MapEvent) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with CopyOnWriteArraySet

use of java.util.concurrent.CopyOnWriteArraySet in project druid by alibaba.

the class SpringStatManager method getSpringStatSetFromSysProperty.

@SuppressWarnings("unchecked")
static Set<Object> getSpringStatSetFromSysProperty() {
    Properties properties = System.getProperties();
    Set<Object> webAppStats = (Set<Object>) properties.get(SYS_PROP_INSTANCES);
    if (webAppStats == null) {
        synchronized (properties) {
            webAppStats = (Set<Object>) properties.get(SYS_PROP_INSTANCES);
            if (webAppStats == null) {
                webAppStats = new CopyOnWriteArraySet<Object>();
                properties.put(SYS_PROP_INSTANCES, webAppStats);
            }
        }
    }
    return webAppStats;
}
Also used : Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Properties(java.util.Properties)

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