From 8f79765077fe9e8568e4209dce137ed5a4f9172e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 13 Jul 2015 21:03:37 +0200 Subject: [PATCH] Add method to remove a peer by host name and port number --- .../fcp/quelaton/RemovePeerCommand.java | 1 + .../fcp/quelaton/RemovePeerCommandImpl.java | 6 ++++++ .../fcp/quelaton/DefaultFcpClientTest.java | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java index cd43adb..e9f6e1e 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java @@ -9,5 +9,6 @@ public interface RemovePeerCommand { Executable byName(String name); Executable byIdentity(String nodeIdentity); + Executable byHostAndPort(String host, int port); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java index 6b791e8..b12e225 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java @@ -42,6 +42,12 @@ public class RemovePeerCommandImpl implements RemovePeerCommand { return this::execute; } + @Override + public Executable byHostAndPort(String host, int port) { + nodeIdentifier.set(String.format("%s:%d", host, port)); + return this::execute; + } + private ListenableFuture execute() { return threadPool.submit(this::executeDialog); } diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index eb0e193..d2918a8 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1614,4 +1614,26 @@ public class DefaultFcpClientTest { assertThat(peer.get(), is(true)); } + @Test + public void defaultFcpClientCanRemovePeerByHostAndPort() + throws InterruptedException, ExecutionException, IOException { + Future peer = fcpClient.removePeer().byHostAndPort("1.2.3.4", 5678).execute(); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + String identifier = extractIdentifier(lines); + assertThat(lines, matchesFcpMessage( + "RemovePeer", + "Identifier=" + identifier, + "NodeIdentifier=1.2.3.4:5678", + "EndMessage" + )); + fcpServer.writeLine( + "PeerRemoved", + "Identifier=" + identifier, + "NodeIdentifier=Friend1", + "EndMessage" + ); + assertThat(peer.get(), is(true)); + } + } -- 2.7.4