Add packet names to logging messages
diff --git a/src/main/java/com/intel/jndn/utils/SegmentedClient.java b/src/main/java/com/intel/jndn/utils/SegmentedClient.java
index aa9cb1a..671d6a2 100644
--- a/src/main/java/com/intel/jndn/utils/SegmentedClient.java
+++ b/src/main/java/com/intel/jndn/utils/SegmentedClient.java
@@ -124,11 +124,11 @@
try {
lastSegment = segments.get(0).get().getMetaInfo().getFinalBlockId().toSegment();
} catch (ExecutionException | InterruptedException e) {
- logger.log(Level.FINE, "Failed to retrieve first segment: ", e);
+ logger.log(Level.FINE, "Failed to retrieve first segment: " + interest.toUri(), e);
((FutureData) segments.get(0)).reject(e); // TODO implies knowledge of underlying data structure
return segments;
} catch (EncodingException e) {
- logger.log(Level.FINER, "No FinalBlockId, returning first packet.");
+ logger.log(Level.FINER, "No FinalBlockId, returning first packet: " + interest.toUri());
return segments;
}
@@ -179,8 +179,9 @@
try {
return getAsync(face, interest).get();
} catch (ExecutionException | InterruptedException e) {
- logger.log(Level.FINE, "Failed to retrieve data.", e);
- throw new IOException("Failed to retrieve data.", e);
+ String message = "Failed to retrieve data: " + interest.toUri();
+ logger.log(Level.FINE, message, e);
+ throw new IOException(message, e);
}
}
diff --git a/src/main/java/com/intel/jndn/utils/client/FutureData.java b/src/main/java/com/intel/jndn/utils/client/FutureData.java
index dc6b393..55c001e 100644
--- a/src/main/java/com/intel/jndn/utils/client/FutureData.java
+++ b/src/main/java/com/intel/jndn/utils/client/FutureData.java
@@ -132,18 +132,18 @@
face.processEvents();
}
} catch (EncodingException | IOException e) {
- throw new ExecutionException("Failed to retrieve packet.", e);
+ throw new ExecutionException("Failed to retrieve packet while processing events: " + name.toUri(), e);
}
}
// case: cancelled
if (cancelled) {
- throw new InterruptedException("Interrupted by user.");
+ throw new InterruptedException("Interrupted by user while retrieving packet: " + name.toUri());
}
// case: error
if (error != null) {
- throw new ExecutionException("Future rejected with error.", error);
+ throw new ExecutionException("Error while retrieving packet: " + name.toUri(), error);
}
return data;
@@ -171,7 +171,7 @@
face.processEvents();
}
} catch (EncodingException | IOException e) {
- throw new ExecutionException("Failed to retrieve packet.", e);
+ throw new ExecutionException("Failed to retrieve packet while processing events: " + name.toUri(), e);
}
currentTime = System.currentTimeMillis();
@@ -179,17 +179,17 @@
// case: cancelled
if (cancelled) {
- throw new InterruptedException("Interrupted by user.");
+ throw new InterruptedException("Interrupted by user while retrieving packet: " + name.toUri());
}
// case: error
if (error != null) {
- throw new ExecutionException("Future rejected with error.", error);
+ throw new ExecutionException("Error while retrieving packet: " + name.toUri(), error);
}
// case: timed out
if (currentTime > endTime) {
- throw new TimeoutException("Timed out.");
+ throw new TimeoutException("Timed out while retrieving packet: " + name.toUri());
}
return data;
diff --git a/src/main/java/com/intel/jndn/utils/client/SegmentedFutureData.java b/src/main/java/com/intel/jndn/utils/client/SegmentedFutureData.java
index dec33df..403e2da 100644
--- a/src/main/java/com/intel/jndn/utils/client/SegmentedFutureData.java
+++ b/src/main/java/com/intel/jndn/utils/client/SegmentedFutureData.java
@@ -122,7 +122,7 @@
try {
content.write(futureData.get().getContent().getImmutableArray());
} catch (ExecutionException | IOException | InterruptedException e) {
- throw new ExecutionException("Failed while aggregating retrieved packets.", e);
+ throw new ExecutionException("Failed while aggregating retrieved packets: " + name.toUri(), e);
}
}
@@ -154,12 +154,12 @@
try {
content.write(futureData.get().getContent().getImmutableArray());
} catch (ExecutionException | IOException | InterruptedException e) {
- throw new ExecutionException("Failed while aggregating retrieved packets.", e);
+ throw new ExecutionException("Failed while aggregating retrieved packets: " + name.toUri(), e);
}
// check for timeout
if (System.currentTimeMillis() > endTime) {
- throw new TimeoutException("Timed out.");
+ throw new TimeoutException("Timed out while retrieving packets: " + name.toUri());
}
}
diff --git a/src/main/java/com/intel/jndn/utils/repository/Repository.java b/src/main/java/com/intel/jndn/utils/repository/Repository.java
index 4647b9f..f64c145 100644
--- a/src/main/java/com/intel/jndn/utils/repository/Repository.java
+++ b/src/main/java/com/intel/jndn/utils/repository/Repository.java
@@ -13,7 +13,6 @@
*/
package com.intel.jndn.utils.repository;
-import com.intel.jndn.utils.repository.DataNotFoundException;
import net.named_data.jndn.Data;
import net.named_data.jndn.Interest;
diff --git a/src/test/java/com/intel/jndn/utils/SegmentedClientTest.java b/src/test/java/com/intel/jndn/utils/SegmentedClientTest.java
index 11f17a9..319ee6a 100644
--- a/src/test/java/com/intel/jndn/utils/SegmentedClientTest.java
+++ b/src/test/java/com/intel/jndn/utils/SegmentedClientTest.java
@@ -14,7 +14,6 @@
package com.intel.jndn.utils;
import com.intel.jndn.mock.MockFace;
-import com.intel.jndn.mock.MockTransport;
import com.intel.jndn.utils.client.SegmentedFutureData;
import java.io.IOException;
import java.util.List;
@@ -22,7 +21,6 @@
import java.util.concurrent.Future;
import java.util.logging.Logger;
import net.named_data.jndn.Data;
-import net.named_data.jndn.Face;
import net.named_data.jndn.Interest;
import net.named_data.jndn.Name;
import net.named_data.jndn.Name.Component;
@@ -42,9 +40,9 @@
private static final Logger logger = Logger.getLogger(SimpleClient.class.getName());
private MockFace face;
-
+
@Before
- public void beforeTest(){
+ public void beforeTest() {
face = new MockFace();
}
@@ -143,6 +141,28 @@
}
/**
+ * Verify that segmented content is the correct length when retrieved by the
+ * client.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testContentLength() throws Exception {
+ Data data1 = new Data(new Name("/test/content-length").appendSegment(0));
+ data1.setContent(new Blob("0123456789"));
+ data1.getMetaInfo().setFinalBlockId(Name.Component.fromNumberWithMarker(1, 0x00));
+ face.addResponse(data1.getName(), data1);
+
+ Data data2 = new Data(new Name("/test/content-length").appendSegment(1));
+ data2.setContent(new Blob("0123456789"));
+ data1.getMetaInfo().setFinalBlockId(Name.Component.fromNumberWithMarker(1, 0x00));
+ face.addResponse(data2.getName(), data2);
+
+ Future<Data> result = SegmentedClient.getDefault().getAsync(face, new Name("/test/content-length").appendSegment(0));
+ assertEquals(20, result.get().getContent().size());
+ }
+
+ /**
* If a Data packet does not have a FinalBlockId, the SegmentedClient should
* just return the packet.
*