Changed some multithreaded tests to fail if exception is thrown.

This commit is contained in:
Harrison Deng 2020-04-29 19:53:02 -05:00
parent c63298bcaa
commit 538b1c3cae

View File

@ -1,11 +1,13 @@
package ca.recrown.islandsurvivalcraft.world.generation;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.LinkedList;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.bukkit.block.Biome;
@ -69,6 +71,7 @@ public class UniBiomeIslandGeneratorTest {
}
@Test
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public void testBiomeGenerationMultithread1608Chunks() {
int chunksToDoEach = 268;
Runnable g1 = new BiomeGenTask(chunksToDoEach, 0);
@ -79,18 +82,21 @@ public class UniBiomeIslandGeneratorTest {
Runnable g6 = new BiomeGenTask(chunksToDoEach, 5);
ExecutorService ex = Executors.newFixedThreadPool(6);
ex.execute(g1);
ex.execute(g2);
ex.execute(g3);
ex.execute(g4);
ex.execute(g5);
ex.execute(g6);
LinkedList<Future<?>> tasks = new LinkedList<>();
tasks.add(ex.submit(g1));
tasks.add(ex.submit(g2));
tasks.add(ex.submit(g3));
tasks.add(ex.submit(g4));
tasks.add(ex.submit(g5));
tasks.add(ex.submit(g6));
while (!tasks.isEmpty()) {
try {
ex.shutdown();
assertTrue(ex.awaitTermination(1, TimeUnit.MINUTES), "timed out.");
} catch (InterruptedException e) {
assertFalse(false);
tasks.pop().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
assertFalse(false, e.getCause().getMessage());
}
}
}
@ -102,6 +108,7 @@ public class UniBiomeIslandGeneratorTest {
}
@Test
@Timeout(value = 1, unit = TimeUnit.MINUTES)
public void testBiomeGenerationMultithread1608ChunksScatteredColumns() {
int chunksToDoEach = 268;
Runnable g1 = new BiomeGenTask(chunksToDoEach, 0);
@ -112,18 +119,21 @@ public class UniBiomeIslandGeneratorTest {
Runnable g6 = new BiomeGenTask(chunksToDoEach, 10);
ExecutorService ex = Executors.newFixedThreadPool(6);
ex.execute(g1);
ex.execute(g2);
ex.execute(g3);
ex.execute(g4);
ex.execute(g5);
ex.execute(g6);
LinkedList<Future<?>> tasks = new LinkedList<>();
tasks.add(ex.submit(g1));
tasks.add(ex.submit(g2));
tasks.add(ex.submit(g3));
tasks.add(ex.submit(g4));
tasks.add(ex.submit(g5));
tasks.add(ex.submit(g6));
while (!tasks.isEmpty()) {
try {
ex.shutdown();
assertTrue(ex.awaitTermination(1, TimeUnit.MINUTES), "timed out.");
} catch (InterruptedException e) {
assertFalse(false);
tasks.pop().get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
assertFalse(false, e.getCause().getMessage());
}
}
}
}