private FcpConnection connect() throws IOException {
FcpConnection fcpConnection = this.fcpConnection.get();
- if (fcpConnection != null) {
+ if ((fcpConnection != null) && !fcpConnection.isClosed()) {
return fcpConnection;
}
fcpConnection = createConnection();
- this.fcpConnection.compareAndSet(null, fcpConnection);
+ this.fcpConnection.set(fcpConnection);
return fcpConnection;
}
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Test;
/**
}
@Test
+ public void defaultFcpClientCanReconnectAfterConnectionHasBeenClosed()
+ throws InterruptedException, ExecutionException, IOException {
+ Future<FcpKeyPair> keyPair = fcpClient.generateKeypair().execute();
+ connectNode();
+ fcpServer.collectUntil(is("EndMessage"));
+ fcpServer.close();
+ try {
+ keyPair.get();
+ Assert.fail();
+ } catch (ExecutionException e) {
+ }
+ keyPair = fcpClient.generateKeypair().execute();
+ connectNode();
+ List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+ String identifier = extractIdentifier(lines);
+ fcpServer.writeLine(
+ "SSKKeypair",
+ "InsertURI=" + INSERT_URI + "",
+ "RequestURI=" + REQUEST_URI + "",
+ "Identifier=" + identifier,
+ "EndMessage"
+ );
+ keyPair.get();
+ }
+
+ @Test
public void clientGetWithIgnoreDataStoreSettingSendsCorrectCommands()
throws InterruptedException, ExecutionException, IOException {
fcpClient.clientGet().ignoreDataStore().uri("KSK@foo.txt").execute();