Upgrade jndn to version 0.9 and jndn-mock to 1.0.1-SNAPSHOT
Change-Id: I814f5508df8b7b0e18f35d4d1ebd5120c624c9b1
diff --git a/src/test/java/com/intel/jndn/utils/TestHelper.java b/src/test/java/com/intel/jndn/utils/TestHelper.java
index fbf931e..7b79bf4 100644
--- a/src/test/java/com/intel/jndn/utils/TestHelper.java
+++ b/src/test/java/com/intel/jndn/utils/TestHelper.java
@@ -13,7 +13,6 @@
*/
package com.intel.jndn.utils;
-import com.intel.jndn.mock.MockKeyChain;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -24,8 +23,12 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
+
+import com.intel.jndn.mock.MockFace;
+import com.intel.jndn.mock.MockKeyChain;
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.encoding.EncodingException;
import net.named_data.jndn.security.KeyChain;
@@ -40,6 +43,42 @@
*/
public class TestHelper {
+ public interface Tester {
+ boolean test();
+ }
+
+ public static void run(Face face, int limit, Tester t) throws IOException, EncodingException, InterruptedException {
+ while (t.test() && limit > 0) {
+ face.processEvents();
+ Thread.sleep(500);
+ limit--;
+ }
+ }
+
+ public static void run(Face face, int limit) throws IOException, EncodingException, InterruptedException {
+ run(face, limit, new Tester() {
+ @Override
+ public boolean test() {
+ return true;
+ }
+ });
+ }
+
+ public static void addDataPublisher(final MockFace face, final int finalBlockId) {
+ face.onSendInterest.add(new MockFace.SignalOnSendInterest() {
+ @Override
+ public void emit(Interest interest) throws EncodingException, SecurityException {
+ if (finalBlockId < 0) {
+ face.receive(TestHelper.buildData(interest.getName(), "..."));
+ }
+ else {
+ face.receive(TestHelper.buildData(interest.getName(), "...", finalBlockId));
+ }
+ }
+ });
+ }
+
+
public static Data retrieve(CompletableFuture<Data> future) {
try {
return future.get(4000, TimeUnit.MILLISECONDS);
@@ -126,8 +165,4 @@
}
}
}
-
- public static class TestCounter{
- public int count = 0;
- }
}