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()));
}
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;
}
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());
}
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) {
}
}
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) {
}
}
Aggregations