use of java.util.concurrent.ConcurrentMap in project hibernate-orm by hibernate.
the class CorrectnessTestCase method checkForEmptyPendingPuts.
protected void checkForEmptyPendingPuts() throws Exception {
Field pp = PutFromLoadValidator.class.getDeclaredField("pendingPuts");
pp.setAccessible(true);
Method getInvalidators = null;
List<DelayedInvalidators> delayed = new LinkedList<>();
for (int i = 0; i < sessionFactories.length; i++) {
SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactories[i];
for (Object regionName : sfi.getCache().getSecondLevelCacheRegionNames()) {
PutFromLoadValidator validator = getPutFromLoadValidator(sfi, (String) regionName);
if (validator == null) {
log.warn("No validator for " + regionName);
continue;
}
ConcurrentMap<Object, Object> map = (ConcurrentMap) pp.get(validator);
for (Iterator<Map.Entry<Object, Object>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry entry = iterator.next();
if (getInvalidators == null) {
getInvalidators = entry.getValue().getClass().getMethod("getInvalidators");
getInvalidators.setAccessible(true);
}
java.util.Collection invalidators = (java.util.Collection) getInvalidators.invoke(entry.getValue());
if (invalidators != null && !invalidators.isEmpty()) {
delayed.add(new DelayedInvalidators(map, entry.getKey()));
}
}
}
}
// poll until all invalidations come
long deadline = System.currentTimeMillis() + 30000;
while (System.currentTimeMillis() < deadline) {
iterateInvalidators(delayed, getInvalidators, (k, i) -> {
});
if (delayed.isEmpty()) {
break;
}
Thread.sleep(1000);
}
if (!delayed.isEmpty()) {
iterateInvalidators(delayed, getInvalidators, (k, i) -> log.warnf("Left invalidators on key %s: %s", k, i));
throw new IllegalStateException("Invalidators were not cleared: " + delayed.size());
}
}
use of java.util.concurrent.ConcurrentMap in project mapdb by jankotek.
the class ConcurrentHashMapTest method testValuesToArray.
/**
* Values.toArray contains all values
*/
@Test
public void testValuesToArray() {
ConcurrentMap map = map5();
Collection v = map.values();
Object[] ar = v.toArray();
ArrayList s = new ArrayList(Arrays.asList(ar));
assertEquals(5, ar.length);
assertTrue(s.contains("A"));
assertTrue(s.contains("B"));
assertTrue(s.contains("C"));
assertTrue(s.contains("D"));
assertTrue(s.contains("E"));
}
use of java.util.concurrent.ConcurrentMap in project mapdb by jankotek.
the class ConcurrentHashMapTest method testPutIfAbsent.
/**
* putIfAbsent works when the given key is not present
*/
@Test
public void testPutIfAbsent() {
ConcurrentMap map = map5();
map.putIfAbsent(six, "Z");
assertTrue(map.containsKey(six));
}
use of java.util.concurrent.ConcurrentMap in project mapdb by jankotek.
the class ConcurrentHashMapTest method testRemove.
/**
* remove removes the correct key-value pair from the map
*/
@Test
public void testRemove() {
ConcurrentMap map = map5();
map.remove(five);
assertEquals(4, map.size());
assertFalse(map.containsKey(five));
}
use of java.util.concurrent.ConcurrentMap in project mapdb by jankotek.
the class ConcurrentHashMapTest method testPutIfAbsent2.
/**
* putIfAbsent does not add the pair if the key is already present
*/
@Test
public void testPutIfAbsent2() {
ConcurrentMap map = map5();
assertEquals("A", map.putIfAbsent(one, "Z"));
}
Aggregations