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