Use custom async thread execution pool

The new pool has a limited thread size (cpu core count - 1) and  should
avoid bot attacks to crash the machine.
This commit is contained in:
Gabriele C
2016-11-07 00:47:07 +01:00
parent 72853a382f
commit a574245bb9
4 changed files with 53 additions and 7 deletions
@@ -3,6 +3,7 @@ package fr.xephi.authme.initialization;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.service.BukkitService;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginLogger;
@@ -49,6 +50,8 @@ public class TaskCloserTest {
private BukkitScheduler bukkitScheduler;
@Mock
private DataSource dataSource;
@Mock
private BukkitService bukkitService;
@Before
public void initAuthMe() {
@@ -56,7 +59,7 @@ public class TaskCloserTest {
given(server.getScheduler()).willReturn(bukkitScheduler);
ReflectionTestUtils.setField(JavaPlugin.class, authMe, "server", server);
ReflectionTestUtils.setField(JavaPlugin.class, authMe, "logger", logger);
taskCloser = spy(new TaskCloser(authMe, dataSource));
taskCloser = spy(new TaskCloser(authMe, dataSource, bukkitService));
}
@Test
@@ -120,7 +123,7 @@ public class TaskCloserTest {
/** Test implementation for {@link #shouldStopForInterruptedThread()}. */
private void shouldStopForInterruptedThread0() throws InterruptedException {
// given
taskCloser = spy(new TaskCloser(authMe, null));
taskCloser = spy(new TaskCloser(authMe, null, bukkitService));
// First two times do nothing, third time throw exception when we sleep
doNothing().doNothing().doThrow(InterruptedException.class).when(taskCloser).sleep();
mockActiveWorkers();