X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FDefaultFcpClientTest.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FDefaultFcpClientTest.java;h=a4dc5a99d51e698a2e48b7c3bfbdbdac5e675992;hb=0e2b31d9770e0548962a863f7e96d8a55da63e7d;hp=771cd25ddfc5ebfb6addb21cf0443da992bb6c5f;hpb=872b858bdb4fd4bfadf50491567d0dd5207851b4;p=jFCPlib.git diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index 771cd25..a4dc5a9 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1,5 +1,6 @@ package net.pterodactylus.fcp.quelaton; +import static net.pterodactylus.fcp.RequestProgressMatcher.isRequestProgress; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.contains; @@ -16,6 +17,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -43,6 +45,7 @@ import net.pterodactylus.fcp.Peer; import net.pterodactylus.fcp.PeerNote; import net.pterodactylus.fcp.PluginInfo; import net.pterodactylus.fcp.Priority; +import net.pterodactylus.fcp.RequestProgress; import net.pterodactylus.fcp.fake.FakeTcpServer; import net.pterodactylus.fcp.quelaton.ClientGetCommand.Data; @@ -1542,10 +1545,12 @@ public class DefaultFcpClientTest { ); } - private Matcher> matchesDirectClientPut() { + private Matcher> matchesDirectClientPut(String... additionalLines) { + List lines = new ArrayList<>(Arrays.asList("UploadFrom=direct", "DataLength=6", "URI=KSK@foo.txt")); + Arrays.asList(additionalLines).forEach(lines::add); return allOf( hasHead("ClientPut"), - hasParameters(1, 2, "UploadFrom=direct", "DataLength=6", "URI=KSK@foo.txt"), + hasParameters(1, 2, lines.toArray(new String[lines.size()])), hasTail("EndMessage", "Hello") ); } @@ -1619,6 +1624,45 @@ public class DefaultFcpClientTest { assertThat(generatedKeys, contains("KSK@foo.txt")); } + @Test + public void clientPutSendsNotificationOnProgress() throws InterruptedException, ExecutionException, IOException { + List requestProgress = new ArrayList<>(); + Future> key = fcpClient.clientPut() + .onProgress(requestProgress::add) + .from(new ByteArrayInputStream("Hello\n".getBytes())) + .length(6) + .uri("KSK@foo.txt") + .execute(); + connectNode(); + readMessage("Hello", () -> matchesDirectClientPut("Verbosity=1")); + replyWithSimpleProgress(1, 2, 3, 4, 5, 6, true, 8); + replyWithSimpleProgress(11, 12, 13, 14, 15, 16, false, 18); + replyWithPutSuccessful(identifier); + assertThat(key.get().get().getKey(), is("KSK@foo.txt")); + assertThat(requestProgress, contains( + isRequestProgress(1, 2, 3, 4, 5, 6, true, 8), + isRequestProgress(11, 12, 13, 14, 15, 16, false, 18) + )); + } + + private void replyWithSimpleProgress( + int total, int required, int failed, int fatallyFailed, int succeeded, int lastProgress, + boolean finalizedTotal, int minSuccessFetchBlocks) throws IOException { + fcpServer.writeLine( + "SimpleProgress", + "Identifier=" + identifier, + "Total=" + total, + "Required=" + required, + "Failed=" + failed, + "FatallyFailed=" + fatallyFailed, + "Succeeded=" + succeeded, + "LastProgress=" + lastProgress, + "FinalizedTotal=" + finalizedTotal, + "MinSuccessFetchBlocks=" + minSuccessFetchBlocks, + "EndMessage" + ); + } + } public class ClientPutDiskDir {