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();
}
}
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) {
}
}
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();
}
}
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) {
}
}
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) {
}
}
Aggregations