[tor-commits] [onionoo/master] Rather tweak test data than using DummyTime class in order to avoid

karsten at torproject.org karsten at torproject.org
Mon Jan 9 20:11:24 UTC 2017


commit 8b1ff256b76a1e247285c0d8f1fb40549117f1bf
Author: iwakeh <iwakeh at torproject.org>
Date:   Mon Jan 9 18:26:52 2017 +0100

    Rather tweak test data than using DummyTime class in order to avoid
    Time and TimeFactory dependencies.
---
 .../writer/BandwidthDocumentWriterTest.java        | 62 ++++++++++++----------
 1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/src/test/java/org/torproject/onionoo/writer/BandwidthDocumentWriterTest.java b/src/test/java/org/torproject/onionoo/writer/BandwidthDocumentWriterTest.java
index 925f943..436ee43 100644
--- a/src/test/java/org/torproject/onionoo/writer/BandwidthDocumentWriterTest.java
+++ b/src/test/java/org/torproject/onionoo/writer/BandwidthDocumentWriterTest.java
@@ -14,24 +14,14 @@ import org.torproject.onionoo.docs.DummyDocumentStore;
 import org.torproject.onionoo.docs.GraphHistory;
 import org.torproject.onionoo.updater.DescriptorSourceFactory;
 import org.torproject.onionoo.updater.DummyDescriptorSource;
-import org.torproject.onionoo.util.DummyTime;
-import org.torproject.onionoo.util.TimeFactory;
 
 import org.junit.Before;
 import org.junit.Test;
 
-public class BandwidthDocumentWriterTest {
-
-  private static final long TEST_TIME = DateTimeHelper.parse(
-      "2017-01-09 12:00:00");
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
-  private DummyTime dummyTime;
-
-  @Before
-  public void createDummyTime() {
-    this.dummyTime = new DummyTime(TEST_TIME);
-    TimeFactory.setTime(this.dummyTime);
-  }
+public class BandwidthDocumentWriterTest {
 
   private DummyDescriptorSource descriptorSource;
 
@@ -50,34 +40,48 @@ public class BandwidthDocumentWriterTest {
   }
 
   @Test
-  public void testIgnore2019() {
+  public void testIgnoreFuture() {
     BandwidthStatus status = new BandwidthStatus();
+    String future = new SimpleDateFormat("yyyy")
+        .format(new Date(System.currentTimeMillis()
+            + DateTimeHelper.ROUGHLY_ONE_YEAR));
+    String dayBeforeYesterday = new SimpleDateFormat("yyyy-MM-dd")
+        .format(new Date(System.currentTimeMillis()
+            - 2 * DateTimeHelper.ONE_DAY));
+    String yesterday = new SimpleDateFormat("yyyy-MM-dd")
+        .format(new Date(System.currentTimeMillis()
+            - DateTimeHelper.ONE_DAY));
     String documentString =
-        "r 2017-01-08 08:29:33 2017-01-08 12:29:33 144272636928\n"
-        + "r 2017-01-08 12:29:33 2017-01-08 16:29:33 144407647232\n"
-        + "r 2017-01-08 16:29:33 2017-01-08 20:29:33 154355623936\n"
-        + "r 2017-01-08 20:29:33 2017-01-09 00:29:33 149633244160\n"
-        + "r 2019-08-06 05:31:45 2019-08-06 09:31:45 0\n"
-        + "r 2019-08-06 09:31:45 2019-08-06 13:31:45 0\n"
-        + "r 2019-08-06 13:31:45 2019-08-06 17:31:45 0\n"
-        + "r 2019-08-06 17:31:45 2019-08-06 21:31:45 0\n"
-        + "r 2019-08-06 21:31:45 2019-08-07 01:31:45 0\n"
-        + "r 2019-08-07 01:31:45 2019-08-07 05:31:45 0\n";
+        "r " + dayBeforeYesterday + " 08:29:33 " + dayBeforeYesterday
+        + " 12:29:33 144272636928\n"
+        + "r " + dayBeforeYesterday + " 12:29:33 " + dayBeforeYesterday
+        + " 16:29:33 144407647232\n"
+        + "r " + dayBeforeYesterday + " 16:29:33 " + dayBeforeYesterday
+        + " 20:29:33 154355623936\n"
+        + "r " + dayBeforeYesterday + " 20:29:33 " + yesterday
+        + " 00:29:33 149633244160\n"
+        + "r " + future + "-08-06 05:31:45 " + future + "-08-06 09:31:45 0\n"
+        + "r " + future + "-08-06 09:31:45 " + future + "-08-06 13:31:45 0\n"
+        + "r " + future + "-08-06 13:31:45 " + future + "-08-06 17:31:45 0\n"
+        + "r " + future + "-08-06 17:31:45 " + future + "-08-06 21:31:45 0\n"
+        + "r " + future + "-08-06 21:31:45 " + future + "-08-07 01:31:45 0\n"
+        + "r " + future + "-08-07 01:31:45 " + future + "-08-07 05:31:45 0\n";
+
     status.setFromDocumentString(documentString);
-    String ibibUNC0Fingerprint = "7C0AA4E3B73E407E9F5FEB1912F8BE26D8AA124D";
-    this.documentStore.addDocument(status, ibibUNC0Fingerprint);
+    String ibibUnc0Fingerprint = "7C0AA4E3B73E407E9F5FEB1912F8BE26D8AA124D";
+    this.documentStore.addDocument(status, ibibUnc0Fingerprint);
     BandwidthDocumentWriter writer = new BandwidthDocumentWriter();
     DescriptorSourceFactory.getDescriptorSource().readDescriptors();
     writer.writeDocuments();
     assertEquals(1, this.documentStore.getPerformedStoreOperations());
     BandwidthDocument document = this.documentStore.getDocument(
-        BandwidthDocument.class, ibibUNC0Fingerprint);
+        BandwidthDocument.class, ibibUnc0Fingerprint);
     assertEquals(1, document.getReadHistory().size());
     assertTrue(document.getReadHistory().containsKey("1_month"));
     GraphHistory history = document.getReadHistory().get("1_month");
-    assertEquals(DateTimeHelper.parse("2017-01-08 14:00:00"),
+    assertEquals(DateTimeHelper.parse(dayBeforeYesterday + " 14:00:00"),
         history.getFirst());
-    assertEquals(DateTimeHelper.parse("2017-01-09 02:00:00"),
+    assertEquals(DateTimeHelper.parse(yesterday + " 02:00:00"),
         history.getLast());
     assertEquals(DateTimeHelper.FOUR_HOURS / DateTimeHelper.ONE_SECOND,
         (int) history.getInterval());





More information about the tor-commits mailing list