Search in sources :

Example 16 with ConcurrentModificationException

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;
        }
    };
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Closeable(java.io.Closeable) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) IOException(java.io.IOException) ConcurrentModificationException(java.util.ConcurrentModificationException)

Example 17 with ConcurrentModificationException

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) {
        }
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Set(java.util.Set) HashSet(java.util.HashSet) Hashtable(java.util.Hashtable) Iterator(java.util.Iterator) NoSuchElementException(java.util.NoSuchElementException)

Example 18 with ConcurrentModificationException

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);
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 19 with ConcurrentModificationException

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
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Vector(java.util.Vector)

Example 20 with ConcurrentModificationException

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);
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) NotificationListener(javax.management.NotificationListener)

Aggregations

ConcurrentModificationException (java.util.ConcurrentModificationException)89 Iterator (java.util.Iterator)24 HashSet (java.util.HashSet)19 Set (java.util.Set)18 ResultSet (java.sql.ResultSet)16 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)11 HashMap (java.util.HashMap)9 GameLocal (org.apache.openejb.test.entity.cmr.manytomany.GameLocal)8 PlatformLocal (org.apache.openejb.test.entity.cmr.manytomany.PlatformLocal)8 ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)8 SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)8 List (java.util.List)7 Test (org.junit.Test)7 Map (java.util.Map)6 AbstractList (java.util.AbstractList)5 NoSuchElementException (java.util.NoSuchElementException)5 Collection (java.util.Collection)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 MultiMapRecord (com.hazelcast.multimap.impl.MultiMapRecord)3