Search in sources :

Example 91 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project tomee by apache.

the class OneToManyComplexPkTests method testIteratorConcurrentModification.

public void testIteratorConcurrentModification() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(new Integer(1));
        final SongLocal song = findSong(new Integer(11));
        final Set songs = artist.getComposed();
        assertFalse(songs.isEmpty());
        assertEquals(2, songs.size());
        final Iterator iterator = songs.iterator();
        songs.remove(song);
        assertEquals(1, songs.size());
        try {
            iterator.next();
            fail("expected iterator.next() to throw an ConcurrentModificationException");
        } catch (final ConcurrentModificationException expected) {
        }
    } finally {
        completeTransaction();
    }
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) ConcurrentModificationException(java.util.ConcurrentModificationException) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Iterator(java.util.Iterator)

Example 92 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project tomee by apache.

the class ManyToManyTests method testIteratorAndRemove.

public void testIteratorAndRemove() throws Exception {
    resetDB();
    beginTransaction();
    final Set games;
    try {
        final PlatformLocal platform = findPlatform(new Integer(1));
        final GameLocal game = findGame(new Integer(11));
        games = platform.getGames();
        assertFalse(games.isEmpty());
        assertEquals(2, games.size());
        final Iterator iterator = games.iterator();
        assertTrue(games.contains(game));
        platform.remove();
        assertFalse(games.contains(game));
        assertEquals(0, games.size());
        try {
            iterator.next();
            fail("expected iterator.next() to throw an ConcurrentModificationException");
        } catch (final ConcurrentModificationException expected) {
        }
    } finally {
        completeTransaction();
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Iterator(java.util.Iterator) GameLocal(org.apache.openejb.test.entity.cmr.manytomany.GameLocal) PlatformLocal(org.apache.openejb.test.entity.cmr.manytomany.PlatformLocal)

Example 93 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project tomee by apache.

the class ManyToManyTests method testModifyCmrCollectionInNewTx.

public void testModifyCmrCollectionInNewTx() throws Exception {
    resetDB();
    beginTransaction();
    Set games;
    GameLocal newGame;
    try {
        final PlatformLocal platform = findPlatform(new Integer(1));
        newGame = createGame(new Integer(33));
        games = platform.getGames();
    } finally {
        completeTransaction();
    }
    beginTransaction();
    try {
        // CMR collections should still be readable
        assertFalse(games.isEmpty());
        assertEquals(2, games.size());
        for (final Iterator iter = games.iterator(); iter.hasNext(); ) {
            final GameLocal game = (GameLocal) iter.next();
            if (game.getId().equals(new Integer(11))) {
                assertEquals("value11", game.getName());
            } else if (game.getId().equals(new Integer(22))) {
                assertEquals("value22", game.getName());
            } else {
                fail();
            }
        }
        // But CMR collections should not be modifiable
        try {
            games.add(newGame);
            fail("expected games.add(game) to throw an IllegalStateException");
        } catch (final IllegalStateException expected) {
        }
        try {
            games.addAll(Arrays.asList(newGame));
            fail("expected games.addAll(Arrays.asList(game)) to throw an IllegalStateException");
        } catch (final IllegalStateException expected) {
        }
        try {
            games.remove(newGame);
            fail("expected games.remove(game) to throw an IllegalStateException");
        } catch (final IllegalStateException expected) {
        }
        try {
            games.removeAll(Arrays.asList(newGame));
            fail("expected games.removeAll(game) to throw an IllegalStateException");
        } catch (final IllegalStateException expected) {
        }
        final Iterator iterator = games.iterator();
        try {
            iterator.remove();
            fail("expected iterator.remove() to throw an ConcurrentModificationException");
        } catch (final ConcurrentModificationException expected) {
        }
    } finally {
        completeTransaction();
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Iterator(java.util.Iterator) GameLocal(org.apache.openejb.test.entity.cmr.manytomany.GameLocal) PlatformLocal(org.apache.openejb.test.entity.cmr.manytomany.PlatformLocal)

Example 94 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project hive by apache.

the class MapJoinTableContainerSerDe method persist.

public void persist(ObjectOutputStream out, MapJoinPersistableTableContainer tableContainer) throws HiveException {
    int numKeys = tableContainer.size();
    try {
        out.writeUTF(tableContainer.getClass().getName());
        out.writeObject(tableContainer.getMetaData());
        out.writeInt(numKeys);
        for (Map.Entry<MapJoinKey, MapJoinRowContainer> entry : tableContainer.entrySet()) {
            entry.getKey().write(keyContext, out);
            entry.getValue().write(valueContext, out);
        }
    } catch (SerDeException e) {
        String msg = "SerDe error while attempting to persist table container";
        throw new HiveException(msg, e);
    } catch (IOException e) {
        String msg = "IO error while attempting to persist table container";
        throw new HiveException(msg, e);
    }
    if (numKeys != tableContainer.size()) {
        throw new ConcurrentModificationException("TableContainer was modified while persisting: " + tableContainer);
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) IOException(java.io.IOException) Map(java.util.Map) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Example 95 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project hive by apache.

the class MapJoinEagerRowContainer method write.

@Override
public void write(MapJoinObjectSerDeContext context, ObjectOutputStream out) throws IOException, SerDeException {
    AbstractSerDe serde = context.getSerDe();
    ObjectInspector valueObjectInspector = context.getStandardOI();
    long numRows = rowCount();
    long numRowsWritten = 0L;
    out.writeLong(numRows);
    for (List<Object> row = first(); row != null; row = next()) {
        serde.serialize(row.toArray(), valueObjectInspector).write(out);
        ++numRowsWritten;
    }
    if (numRows != rowCount()) {
        throw new ConcurrentModificationException("Values was modified while persisting");
    }
    if (numRowsWritten != numRows) {
        throw new IllegalStateException("Expected to write " + numRows + " but wrote " + numRowsWritten);
    }
}
Also used : ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) ConcurrentModificationException(java.util.ConcurrentModificationException) AbstractSerDe(org.apache.hadoop.hive.serde2.AbstractSerDe)

Aggregations

ConcurrentModificationException (java.util.ConcurrentModificationException)206 Iterator (java.util.Iterator)34 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)24 HashSet (java.util.HashSet)23 Map (java.util.Map)19 Set (java.util.Set)19 Test (org.junit.Test)19 ResultSet (java.sql.ResultSet)16 HashMap (java.util.HashMap)13 NoSuchElementException (java.util.NoSuchElementException)13 List (java.util.List)10 Collection (java.util.Collection)9 GameLocal (org.apache.openejb.test.entity.cmr.manytomany.GameLocal)8 PlatformLocal (org.apache.openejb.test.entity.cmr.manytomany.PlatformLocal)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 AbstractList (java.util.AbstractList)6 LinkedList (java.util.LinkedList)6 ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)6 SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)6