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