Search in sources :

Example 86 with ConcurrentModificationException

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

the class ManyToManyTests method testIteratorConcurrentModification.

public void testIteratorConcurrentModification() 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();
        games.remove(game);
        assertEquals(1, 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 87 with ConcurrentModificationException

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

the class ManyToManyTests method testModifyCmrCollectionOusideTx.

public void testModifyCmrCollectionOusideTx() 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();
    }
    // 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) {
    }
}
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 88 with ConcurrentModificationException

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

the class ManyToManyComplexPkTests method testIteratorConcurrentModification.

public void testIteratorConcurrentModification() 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();
        games.remove(game);
        assertEquals(1, 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 89 with ConcurrentModificationException

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

the class ManyToManyComplexPkTests method testModifyCmrCollectionOusideTx.

public void testModifyCmrCollectionOusideTx() 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();
    }
    // 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) {
    }
}
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 90 with ConcurrentModificationException

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

the class OneToManyComplexPkTests method testModifyCmrCollectionOusideTx.

public void testModifyCmrCollectionOusideTx() throws Exception {
    resetDB();
    beginTransaction();
    Set songs;
    SongLocal newSong;
    try {
        final ArtistLocal artist = findArtist(new Integer(1));
        newSong = createSong(new Integer(33));
        songs = artist.getComposed();
    } finally {
        completeTransaction();
    }
    // CMR collections should still be readable
    assertFalse(songs.isEmpty());
    assertEquals(2, songs.size());
    for (final Iterator iter = songs.iterator(); iter.hasNext(); ) {
        final SongLocal song = (SongLocal) iter.next();
        if (song.getId().equals(new Integer(11))) {
            assertEquals("value11", song.getName());
        } else if (song.getId().equals(new Integer(22))) {
            assertEquals("value22", song.getName());
        } else {
            fail();
        }
    }
    // But CMR collections should not be modifiable
    try {
        songs.add(newSong);
        fail("expected songs.add(newSong) to throw an IllegalStateException");
    } catch (final IllegalStateException expected) {
    }
    try {
        songs.addAll(Arrays.asList(newSong));
        fail("expected songs.addAll(Arrays.asList(newSong)) to throw an IllegalStateException");
    } catch (final IllegalStateException expected) {
    }
    try {
        songs.remove(newSong);
        fail("expected songs.remove(newSong) to throw an IllegalStateException");
    } catch (final IllegalStateException expected) {
    }
    try {
        songs.removeAll(Arrays.asList(newSong));
        fail("expected songs.removeAll(Arrays.asList(newSong)) to throw an IllegalStateException");
    } catch (final IllegalStateException expected) {
    }
    final Iterator iterator = songs.iterator();
    try {
        iterator.remove();
        fail("expected iterator.remove() to throw an ConcurrentModificationException");
    } catch (final ConcurrentModificationException expected) {
    }
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) ConcurrentModificationException(java.util.ConcurrentModificationException) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal) Iterator(java.util.Iterator)

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