Add flag to GetNode command to include volatile data
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 10 Jul 2015 20:09:15 +0000 (22:09 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 10 Jul 2015 20:09:24 +0000 (22:09 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index ff94622..e55c890 100644 (file)
@@ -11,5 +11,6 @@ public interface GetNodeCommand extends Executable<NodeData> {
 
        GetNodeCommand opennetRef();
        GetNodeCommand includePrivate();
+       GetNodeCommand includeVolatile();
 
 }
index 23c5ad0..51ebd73 100644 (file)
@@ -23,6 +23,7 @@ public class GetNodeCommandImpl implements GetNodeCommand {
        private final ConnectionSupplier connectionSupplier;
        private final AtomicBoolean giveOpennetRef = new AtomicBoolean(false);
        private final AtomicBoolean includePrivate = new AtomicBoolean(false);
+       private final AtomicBoolean includeVolatile = new AtomicBoolean(false);
 
        public GetNodeCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
                this.threadPool = MoreExecutors.listeningDecorator(threadPool);
@@ -42,9 +43,15 @@ public class GetNodeCommandImpl implements GetNodeCommand {
        }
 
        @Override
+       public GetNodeCommand includeVolatile() {
+               includeVolatile.set(true);
+               return this;
+       }
+
+       @Override
        public ListenableFuture<NodeData> execute() {
                GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), giveOpennetRef.get(),
-                       includePrivate.get(), false);
+                       includePrivate.get(), includeVolatile.get());
                return threadPool.submit(() -> new GetNodeReplySequence().send(getNode).get());
        }
 
index 1e484dc..47b787d 100644 (file)
@@ -835,4 +835,34 @@ public class DefaultFcpClientTest {
                assertThat(nodeData.get().getARK().getPrivateURI(), is("SSK@XdHMiRl"));
        }
 
+       @Test
+       public void defaultFcpClientCanGetNodeInformationWithVolatileData()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<NodeData> nodeData = fcpClient.getNode().includeVolatile().execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "GetNode",
+                       "Identifier=" + identifier,
+                       "GiveOpennetRef=false",
+                       "WithPrivate=false",
+                       "WithVolatile=true",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "NodeData",
+                       "Identifier=" + identifier,
+                       "opennet=false",
+                       "ark.pubURI=SSK@3YEf.../ark",
+                       "ark.number=78",
+                       "auth.negTypes=2",
+                       "version=Fred,0.7,1.0,1466",
+                       "lastGoodVersion=Fred,0.7,1.0,1466",
+                       "volatile.freeJavaMemory=205706528",
+                       "EndMessage"
+               );
+               assertThat(nodeData.get().getVolatile("freeJavaMemory").toString(), is("205706528"));
+       }
+
 }