threadPool.shutdown();
}
- @Test(expected = ExecutionException.class)
- public void defaultFcpClientThrowsExceptionIfItCanNotConnect()
- throws IOException, ExecutionException, InterruptedException {
- Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
- fcpServer.connect().get();
- fcpServer.collectUntil(is("EndMessage"));
- fcpServer.writeLine(
- "CloseConnectionDuplicateClientName",
- "EndMessage"
- );
- keyPairFuture.get();
- }
-
- @Test(expected = ExecutionException.class)
- public void defaultFcpClientThrowsExceptionIfConnectionIsClosed()
- throws IOException, ExecutionException, InterruptedException {
- Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
- fcpServer.connect().get();
- fcpServer.collectUntil(is("EndMessage"));
- fcpServer.close();
- keyPairFuture.get();
- }
-
private void connectNode() throws InterruptedException, ExecutionException, IOException {
fcpServer.connect().get();
fcpServer.collectUntil(is("EndMessage"));
);
}
- @Test
- public void clientGetCanDownloadData() throws InterruptedException, ExecutionException, IOException {
- Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
- connectNode();
- List<String> lines = fcpServer.collectUntil(is("EndMessage"));
- assertThat(lines, matchesFcpMessage("ClientGet", "ReturnType=direct", "URI=KSK@foo.txt"));
- String identifier = extractIdentifier(lines);
- fcpServer.writeLine(
- "AllData",
- "Identifier=" + identifier,
- "DataLength=6",
- "StartupTime=1435610539000",
- "CompletionTime=1435610540000",
- "Metadata.ContentType=text/plain;charset=utf-8",
- "Data",
- "Hello"
- );
- Optional<Data> data = dataFuture.get();
- assertThat(data.get().getMimeType(), is("text/plain;charset=utf-8"));
- assertThat(data.get().size(), is(6L));
- assertThat(ByteStreams.toByteArray(data.get().getInputStream()),
- is("Hello\n".getBytes(StandardCharsets.UTF_8)));
- }
-
private String extractIdentifier(List<String> lines) {
return lines.stream()
.filter(s -> s.startsWith("Identifier="))
assertThat(lines, requestMatcher.get());
}
+ public class Connections {
+
+ @Test(expected = ExecutionException.class)
+ public void throwsExceptionOnFailure() throws IOException, ExecutionException, InterruptedException {
+ Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
+ connectAndAssert(() -> matchesFcpMessage("GenerateSSK"));
+ fcpServer.writeLine(
+ "CloseConnectionDuplicateClientName",
+ "EndMessage"
+ );
+ keyPairFuture.get();
+ }
+
+ @Test(expected = ExecutionException.class)
+ public void throwsExceptionIfConnectionIsClosed() throws IOException, ExecutionException, InterruptedException {
+ Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
+ connectAndAssert(() -> matchesFcpMessage("GenerateSSK"));
+ fcpServer.close();
+ keyPairFuture.get();
+ }
+
+ }
+
public class GenerateKeyPair {
@Test
@Test
public void works() throws InterruptedException, ExecutionException, IOException {
Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
- connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
+ connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "ReturnType=direct"));
replyWithAllData("not-test", "Hello World", "text/plain;charset=latin-9");
replyWithAllData(identifier, "Hello", "text/plain;charset=utf-8");
Optional<Data> data = dataFuture.get();
public void getFailedIsRecognized() throws InterruptedException, ExecutionException, IOException {
Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
connectAndAssert(() -> matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
+ replyWithGetFailed("not-test");
replyWithGetFailed(identifier);
Optional<Data> data = dataFuture.get();
assertThat(data.isPresent(), is(false));