use of java.util.ConcurrentModificationException in project fresco by facebook.
the class StatefulProducerRunnableTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mException = new ConcurrentModificationException();
mSuccessMap = new HashMap<>();
mSuccessMap.put("state", "success");
mFailureMap = new HashMap<>();
mFailureMap.put("state", "failure");
mCancellationMap = new HashMap<>();
mCancellationMap.put("state", "cancelled");
mStatefulProducerRunnable = new StatefulProducerRunnable<Closeable>(mConsumer, mProducerListener, PRODUCER_NAME, REQUEST_ID) {
@Override
protected void disposeResult(Closeable result) {
try {
result.close();
} catch (IOException ioe) {
throw new RuntimeException("unexpected IOException", ioe);
}
}
@Override
protected Closeable getResult() throws Exception {
return mResultSupplier.get();
}
@Override
protected Map<String, String> getExtraMapOnCancellation() {
return mCancellationMap;
}
@Override
protected Map<String, String> getExtraMapOnFailure(Exception exception) {
return mFailureMap;
}
@Override
protected Map<String, String> getExtraMapOnSuccess(Closeable result) {
return mSuccessMap;
}
};
}
use of java.util.ConcurrentModificationException in project j2objc by google.
the class HashtableTest method test_keySet_subtest0.
/**
* java.util.Hashtable#keySet()
*/
public void test_keySet_subtest0() {
Set s1 = ht10.keySet();
assertTrue("should contain key", s1.remove("Key 0"));
assertTrue("should not contain key", !s1.remove("Key 0"));
final int iterations = 10000;
final Hashtable ht = new Hashtable();
Thread t1 = new Thread() {
public void run() {
for (int i = 0; i < iterations; i++) {
ht.put(String.valueOf(i), "");
ht.remove(String.valueOf(i));
}
}
};
t1.start();
Set set = ht.keySet();
for (int i = 0; i < iterations; i++) {
Iterator it = set.iterator();
try {
it.next();
it.remove();
int size;
// Hashtable
if ((size = ht.size()) < 0) {
fail("invalid size: " + size);
}
} catch (NoSuchElementException e) {
} catch (ConcurrentModificationException e) {
}
}
}
use of java.util.ConcurrentModificationException in project j2objc by google.
the class AbstractListTest method test_iterator_next.
/*
* Regression test for HY-4398
*/
public void test_iterator_next() {
MockArrayList<String> t = new MockArrayList<String>();
t.list.add("a");
t.list.add("b");
Iterator it = t.iterator();
while (it.hasNext()) {
it.next();
}
try {
it.next();
fail("Should throw NoSuchElementException");
} catch (NoSuchElementException cme) {
// expected
}
t.add("c");
try {
it.remove();
fail("Should throw NoSuchElementException");
} catch (ConcurrentModificationException cme) {
// expected
}
it = t.iterator();
try {
it.remove();
fail("Should throw IllegalStateException");
} catch (IllegalStateException ise) {
// expected
}
Object value = it.next();
assertEquals("a", value);
}
use of java.util.ConcurrentModificationException in project j2objc by google.
the class ArrayListTest method test_trimToSize.
/**
* @tests java.util.ArrayList#trimToSize()
*/
public void test_trimToSize() {
// Test for method void java.util.ArrayList.trimToSize()
for (int i = 99; i > 24; i--) alist.remove(i);
((ArrayList) alist).trimToSize();
assertEquals("Returned incorrect size after trim", 25, alist.size());
for (int i = 0; i < alist.size(); i++) assertTrue("Trimmed list contained incorrect elements", alist.get(i) == objArray[i]);
Vector v = new Vector();
v.add("a");
v.add("b");
ArrayList al = new ArrayList(v);
al.remove("a");
Iterator it = al.iterator();
al.trimToSize();
try {
it.next();
fail("should throw a ConcurrentModificationException");
} catch (ConcurrentModificationException ioobe) {
// expected
}
}
use of java.util.ConcurrentModificationException in project jdk8u_jdk by JetBrains.
the class ConcurrentModificationTest method main.
public static void main(String[] args) throws Exception {
System.out.println(">>> test on Concurrent Modification.");
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
e.printStackTrace();
if (e instanceof ConcurrentModificationException) {
uncaughtException = e;
}
}
});
delegateName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
for (int i = 0; i < number; i++) {
timerNames[i] = new ObjectName("MBean:name=Timer" + i);
listeners[i] = new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {
// nothing
}
};
}
String errors = "";
for (int i = 0; i < protocols.length; i++) {
uncaughtException = null;
System.out.println(">>> Test for protocol " + protocols[i]);
test(protocols[i]);
if (uncaughtException != null) {
if ("".equals(errors)) {
errors = "Failed to " + protocols[i] + ": " + uncaughtException;
} else {
errors = errors + ", failed to " + protocols[i] + ": " + uncaughtException;
}
System.out.println(">>> FAILED for protocol " + protocols[i]);
} else {
System.out.println(">>> PASSED for protocol " + protocols[i]);
}
}
if ("".equals(errors)) {
System.out.println("All Passed!");
} else {
System.out.println("!!!!!! Failed.");
throw new RuntimeException(errors);
}
}
Aggregations