Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.cyclops.integratedterminals.gametest.GameTestAdvancementsIntegratedTerminals;
import org.cyclops.integratedterminals.gametest.GameTestCraftingJobIndication;
import org.cyclops.integratedterminals.gametest.GameTestCraftingJobNotify;
import org.cyclops.integratedterminals.gametest.GameTestCraftingPlanWorkerPool;
import org.cyclops.integratedterminals.gametest.GameTestIngredientQueryMatchers;
import org.cyclops.integratedterminals.gametest.GameTestPendingCraftingJobOutputs;
import org.cyclops.integratedterminals.gametest.GameTestTerminalCraftingJobFinishedEvent;
Expand Down Expand Up @@ -158,6 +159,7 @@ public Class<?>[] getGameTestClasses() {
GameTestAdvancementsIntegratedTerminals.class,
GameTestCraftingJobIndication.class,
GameTestCraftingJobNotify.class,
GameTestCraftingPlanWorkerPool.class,
GameTestIngredientQueryMatchers.class,
GameTestPendingCraftingJobOutputs.class,
GameTestTerminalCraftingJobFinishedEvent.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cyclops.integratedterminals.gametest;

import net.minecraft.gametest.framework.GameTestHelper;
import org.cyclops.cyclopscore.gametest.GameTest;
import org.cyclops.integratedterminals.inventory.container.ContainerTerminalStorageCraftingPlanBase;

import java.util.concurrent.ExecutionException;

/**
* Game tests for the crafting planner worker pool.
* @author rubensworks
*/
public class GameTestCraftingPlanWorkerPool {

@GameTest(template = "cyclopscore:empty")
public void testWorkerThreadsAreDaemon(GameTestHelper helper) throws ExecutionException, InterruptedException {
// Non-daemon worker threads would keep the client JVM alive after quitting the game.
boolean daemon = ContainerTerminalStorageCraftingPlanBase.getWorkerPool().submit(() -> Thread.currentThread().isDaemon()).get();
helper.assertTrue(daemon, "Crafting planner worker threads must be daemon threads");
helper.succeed();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.cyclops.integratedterminals.inventory.container;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.SimpleContainer;
Expand Down Expand Up @@ -29,7 +31,19 @@
public abstract class ContainerTerminalStorageCraftingPlanBase<L> extends InventoryContainer {

public static final String BUTTON_START = "start";
private static final ExecutorService WORKER_POOL = Executors.newFixedThreadPool(GeneralConfig.craftingPlannerThreads);
// Daemon threads, so they don't prevent the client JVM from exiting.
private static final ExecutorService WORKER_POOL = Executors.newFixedThreadPool(
GeneralConfig.craftingPlannerThreads,
new ThreadFactoryBuilder()
.setNameFormat("IntegratedTerminals Crafting Planner #%d")
.setDaemon(true)
.build()
);

@VisibleForTesting
public static ExecutorService getWorkerPool() {
return WORKER_POOL;
}

private final CraftingOptionGuiData craftingOptionGuiData;
private final int craftingPlanNotifierId;
Expand Down
Loading