From d21f485b5918b4281c349d8c04893d27a979ae76 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 21 Aug 2015 22:43:34 +0200 Subject: [PATCH] Add method to add wait time for reloading plugins --- .../fcp/quelaton/ReloadPluginCommand.java | 1 + .../fcp/quelaton/ReloadPluginCommandImpl.java | 6 ++++++ .../fcp/quelaton/DefaultFcpClientTest.java | 23 ++++++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommand.java index ef25380..65febba 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommand.java @@ -11,6 +11,7 @@ import net.pterodactylus.fcp.PluginInfo; */ public interface ReloadPluginCommand { + ReloadPluginCommand waitFor(int milliseconds); Executable> plugin(String pluginClassName); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java index c1a33fe..f7c11a9 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ReloadPluginCommandImpl.java @@ -33,6 +33,12 @@ public class ReloadPluginCommandImpl implements ReloadPluginCommand { } @Override + public ReloadPluginCommand waitFor(int milliseconds) { + reloadPlugin.setMaxWaitTime(milliseconds); + return this; + } + + @Override public Executable> plugin(String pluginClassName) { reloadPlugin.setPluginName(pluginClassName); return this::execute; diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index 7ba009c..d4d67c5 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1,6 +1,7 @@ package net.pterodactylus.fcp.quelaton; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasItem; @@ -2145,14 +2146,28 @@ public class DefaultFcpClientTest { @Test public void reloadingPluginWorks() throws InterruptedException, ExecutionException, IOException { Future> pluginInfo = fcpClient.reloadPlugin().plugin(CLASS_NAME).execute(); - connectAndAssert(() -> matchesFcpMessage( + connectAndAssert(() -> matchReloadPluginMessage()); + replyWithPluginInfo(); + verifyPluginInfo(pluginInfo); + } + + @Test + public void reloadingPluginWithMaxWaitTimeWorks() + throws InterruptedException, ExecutionException, IOException { + Future> pluginInfo = + fcpClient.reloadPlugin().waitFor(1234).plugin(CLASS_NAME).execute(); + connectAndAssert(() -> allOf(matchReloadPluginMessage(), hasItem("MaxWaitTime=1234"))); + replyWithPluginInfo(); + verifyPluginInfo(pluginInfo); + } + + private Matcher> matchReloadPluginMessage() { + return matchesFcpMessage( "ReloadPlugin", "Identifier=" + identifier, "PluginName=" + CLASS_NAME, "EndMessage" - )); - replyWithPluginInfo(); - verifyPluginInfo(pluginInfo); + ); } } -- 2.7.4