Search in sources :

Example 1 with CopyOnWriteArraySet

use of java.util.concurrent.CopyOnWriteArraySet in project elastic-job by dangdangdotcom.

the class ExecutorServiceHandlerRegistryTest method assertGetExecutorServiceHandlerForConcurrent.

@Test
public void assertGetExecutorServiceHandlerForConcurrent() throws InterruptedException {
    int threadCount = 100;
    CyclicBarrier barrier = new CyclicBarrier(threadCount);
    ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
    CountDownLatch latch = new CountDownLatch(threadCount);
    Set<ExecutorService> set = new CopyOnWriteArraySet<>();
    for (int i = 0; i < threadCount; i++) {
        executorService.submit(new GetExecutorServiceHandlerTask(barrier, latch, set));
    }
    latch.await();
    assertThat(set.size(), is(1));
    assertThat(ExecutorServiceHandlerRegistry.getExecutorServiceHandler("test_job", new DefaultExecutorServiceHandler()), is(set.iterator().next()));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) DefaultExecutorServiceHandler(com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) CountDownLatch(java.util.concurrent.CountDownLatch) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 2 with CopyOnWriteArraySet

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

the class WebAppStatManager method getWebAppStatSet0.

@SuppressWarnings("unchecked")
static Set<Object> getWebAppStatSet0() {
    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)

Example 3 with CopyOnWriteArraySet

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

the class CopyOnWriteArraySetTest method testSize.

/**
     * size returns the number of elements
     */
public void testSize() {
    Collection empty = new CopyOnWriteArraySet();
    Collection full = populatedSet(3);
    assertEquals(3, full.size());
    assertEquals(0, empty.size());
}
Also used : Collection(java.util.Collection) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Example 4 with CopyOnWriteArraySet

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

the class CopyOnWriteArraySetTest method testContainsAll.

/**
     * containsAll returns true for collections with subset of elements
     */
public void testContainsAll() {
    Collection full = populatedSet(3);
    assertTrue(full.containsAll(full));
    assertTrue(full.containsAll(Arrays.asList()));
    assertTrue(full.containsAll(Arrays.asList(one)));
    assertTrue(full.containsAll(Arrays.asList(one, two)));
    assertFalse(full.containsAll(Arrays.asList(one, two, six)));
    assertFalse(full.containsAll(Arrays.asList(six)));
    CopyOnWriteArraySet empty1 = new CopyOnWriteArraySet(Arrays.asList());
    CopyOnWriteArraySet empty2 = new CopyOnWriteArraySet(Arrays.asList());
    assertTrue(empty1.containsAll(empty2));
    assertTrue(empty1.containsAll(empty1));
    assertFalse(empty1.containsAll(full));
    assertTrue(full.containsAll(empty1));
    try {
        full.containsAll(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : Collection(java.util.Collection) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet)

Example 5 with CopyOnWriteArraySet

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

the class CopyOnWriteArraySetTest method testToArray_ArrayStoreException.

/**
     * toArray throws an ArrayStoreException when the given array can
     * not store the objects inside the set
     */
public void testToArray_ArrayStoreException() {
    CopyOnWriteArraySet c = new CopyOnWriteArraySet();
    c.add("zfasdfsdf");
    c.add("asdadasd");
    try {
        c.toArray(new Long[5]);
        shouldThrow();
    } catch (ArrayStoreException success) {
    }
}
Also used : 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