[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/master] Update unit tests for #27981 and #28871.
commit 5225a3b449889e942aeb46392ea3d444244de4ad
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Feb 17 17:45:28 2020 +0100
Update unit tests for #27981 and #28871.
---
.../writer/BandwidthDocumentWriterTest.java | 52 ++++++++--------------
.../onionoo/writer/GraphHistoryCompilerTest.java | 2 +-
.../onionoo/writer/UptimeDocumentWriterTest.java | 48 +++++++++-----------
3 files changed, 41 insertions(+), 61 deletions(-)
diff --git a/src/test/java/org/torproject/metrics/onionoo/writer/BandwidthDocumentWriterTest.java b/src/test/java/org/torproject/metrics/onionoo/writer/BandwidthDocumentWriterTest.java
index 7c22e62..cd39b42 100644
--- a/src/test/java/org/torproject/metrics/onionoo/writer/BandwidthDocumentWriterTest.java
+++ b/src/test/java/org/torproject/metrics/onionoo/writer/BandwidthDocumentWriterTest.java
@@ -16,8 +16,7 @@ import org.torproject.metrics.onionoo.docs.GraphHistory;
import org.junit.Before;
import org.junit.Test;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.time.Instant;
public class BandwidthDocumentWriterTest {
@@ -32,51 +31,38 @@ public class BandwidthDocumentWriterTest {
@Test
public void testIgnoreFuture() {
String ibibUnc0Fingerprint = "7C0AA4E3B73E407E9F5FEB1912F8BE26D8AA124D";
- 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 " + 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";
+ "r 2020-02-12 12:29:33 2020-02-13 12:29:33 144272636928\n"
+ + "r 2020-02-13 12:29:33 2020-02-14 12:29:33 144407647232\n"
+ + "r 2020-02-14 12:29:33 2020-02-15 12:29:33 154355623936\n"
+ + "r 2020-02-15 12:29:33 2020-02-16 12:29:33 149633244160\n"
+ + "r 2021-08-06 13:31:45 2021-08-07 13:31:45 0\n"
+ + "r 2021-08-07 13:31:45 2021-08-08 13:31:45 0\n"
+ + "r 2021-08-08 13:31:45 2021-08-09 13:31:45 0\n"
+ + "r 2021-08-09 13:31:45 2021-08-10 13:31:45 0\n"
+ + "r 2021-08-10 13:31:45 2021-08-11 13:31:45 0\n"
+ + "r 2021-08-11 13:31:45 2021-08-12 13:31:45 0\n";
BandwidthStatus status = new BandwidthStatus();
status.setFromDocumentString(documentString);
this.documentStore.addDocument(status, ibibUnc0Fingerprint);
BandwidthDocumentWriter writer = new BandwidthDocumentWriter();
- writer.writeDocuments(DateTimeHelper.parse(yesterday + " 12:00:00"));
+ writer.writeDocuments(Instant.parse("2020-05-15T12:00:00Z").toEpochMilli());
assertEquals(1, this.documentStore.getPerformedListOperations());
assertEquals(2, this.documentStore.getPerformedRetrieveOperations());
assertEquals(1, this.documentStore.getPerformedStoreOperations());
BandwidthDocument document = this.documentStore.getDocument(
BandwidthDocument.class, ibibUnc0Fingerprint);
assertEquals(1, document.getReadHistory().size());
- assertTrue(document.getReadHistory().containsKey("1_month"));
- GraphHistory history = document.getReadHistory().get("1_month");
- assertEquals(DateTimeHelper.parse(dayBeforeYesterday + " 10:00:00"),
+ assertTrue(document.getReadHistory().containsKey("6_months"));
+ GraphHistory history = document.getReadHistory().get("6_months");
+ assertEquals(Instant.parse("2020-02-12T12:00:00Z").toEpochMilli(),
history.getFirst());
- assertEquals(DateTimeHelper.parse(dayBeforeYesterday + " 22:00:00"),
+ assertEquals(Instant.parse("2020-02-16T12:00:00Z").toEpochMilli(),
history.getLast());
- assertEquals(DateTimeHelper.FOUR_HOURS / DateTimeHelper.ONE_SECOND,
+ assertEquals(DateTimeHelper.ONE_DAY / DateTimeHelper.ONE_SECOND,
(int) history.getInterval());
- assertEquals(4, (int) history.getCount());
- assertEquals(4, history.getValues().size());
+ assertEquals(5, (int) history.getCount());
+ assertEquals(5, history.getValues().size());
}
}
diff --git a/src/test/java/org/torproject/metrics/onionoo/writer/GraphHistoryCompilerTest.java b/src/test/java/org/torproject/metrics/onionoo/writer/GraphHistoryCompilerTest.java
index 4dbca75..98d055c 100644
--- a/src/test/java/org/torproject/metrics/onionoo/writer/GraphHistoryCompilerTest.java
+++ b/src/test/java/org/torproject/metrics/onionoo/writer/GraphHistoryCompilerTest.java
@@ -76,7 +76,7 @@ public class GraphHistoryCompilerTest {
{ "Single 1-week divisible entry right before graphs end",
true, new String[][] {
new String[] { "2017-12-25 00:00", "2018-01-01 00:00", "1" }},
- 1, "1_week", "2017-12-25 00:30", "2017-12-31 23:30", 3600, 0.001,
+ 2, "1_week", "2017-12-25 00:30", "2017-12-31 23:30", 3600, 0.001,
168, null },
{ "Single 1-week-and-1-hour divisible entry right before graphs end",
true, new String[][] {
diff --git a/src/test/java/org/torproject/metrics/onionoo/writer/UptimeDocumentWriterTest.java b/src/test/java/org/torproject/metrics/onionoo/writer/UptimeDocumentWriterTest.java
index 6c18906..15c1491 100644
--- a/src/test/java/org/torproject/metrics/onionoo/writer/UptimeDocumentWriterTest.java
+++ b/src/test/java/org/torproject/metrics/onionoo/writer/UptimeDocumentWriterTest.java
@@ -61,12 +61,6 @@ public class UptimeDocumentWriterTest {
private static final long ONE_HOUR = 60L * 60L * ONE_SECOND;
private static final long FOUR_HOURS = 4L * ONE_HOUR;
- private void assertOneWeekGraph(UptimeDocument document, int graphs,
- String first, String last, int count, List<Integer> values) {
- this.assertGraph(document, graphs, "1_week", first, last,
- (int) (ONE_HOUR / ONE_SECOND), count, values);
- }
-
private void assertOneMonthGraph(UptimeDocument document, int graphs,
String first, String last, int count, List<Integer> values) {
this.assertGraph(document, graphs, "1_month", first, last,
@@ -125,9 +119,9 @@ public class UptimeDocumentWriterTest {
}
@Test
- public void testTwoHoursUptime() {
- this.addStatusOneWeekSample("r 2014-03-23-10 2\n",
- "r 2014-03-23-10 2\n");
+ public void testEightHoursUptime() {
+ this.addStatusOneWeekSample("r 2014-03-23-04 8\n",
+ "r 2014-03-23-04 8\n");
UptimeDocumentWriter writer = new UptimeDocumentWriter();
DescriptorSourceFactory.getDescriptorSource().readDescriptors();
writer.writeDocuments(TEST_TIME);
@@ -135,8 +129,8 @@ public class UptimeDocumentWriterTest {
this.documentStore.getPerformedStoreOperations());
UptimeDocument document = this.documentStore.getDocument(
UptimeDocument.class, GABELMOO_FINGERPRINT);
- this.assertOneWeekGraph(document, 1, "2014-03-23 10:30:00",
- "2014-03-23 11:30:00", 2, null);
+ this.assertOneMonthGraph(document, 1, "2014-03-23 06:00:00",
+ "2014-03-23 10:00:00", 2, null);
}
@Test
@@ -155,9 +149,9 @@ public class UptimeDocumentWriterTest {
}
@Test
- public void testTwoHoursUptimeSeparatedByZero() {
- this.addStatusOneWeekSample("r 2014-03-23-09 3\n",
- "r 2014-03-23-09 1\nr 2014-03-23-11 1\n");
+ public void testEightHoursUptimeSeparatedByFourHoursDowntime() {
+ this.addStatusOneWeekSample("r 2014-03-23-00 12\n",
+ "r 2014-03-23-00 4\nr 2014-03-23-08 4\n");
UptimeDocumentWriter writer = new UptimeDocumentWriter();
DescriptorSourceFactory.getDescriptorSource().readDescriptors();
writer.writeDocuments(TEST_TIME);
@@ -165,15 +159,15 @@ public class UptimeDocumentWriterTest {
this.documentStore.getPerformedStoreOperations());
UptimeDocument document = this.documentStore.getDocument(
UptimeDocument.class, GABELMOO_FINGERPRINT);
- this.assertOneWeekGraph(document, 1, "2014-03-23 09:30:00",
- "2014-03-23 11:30:00", 3,
+ this.assertOneMonthGraph(document, 1, "2014-03-23 02:00:00",
+ "2014-03-23 10:00:00", 3,
Arrays.asList(999, 0, 999));
}
@Test
- public void testTwoHoursUptimeThenDowntime() {
- this.addStatusOneWeekSample("r 2014-03-23-09 3\n",
- "r 2014-03-23-09 2\n");
+ public void testEightHoursUptimeThenDowntime() {
+ this.addStatusOneWeekSample("r 2014-03-23-00 12\n",
+ "r 2014-03-23-00 8\n");
UptimeDocumentWriter writer = new UptimeDocumentWriter();
DescriptorSourceFactory.getDescriptorSource().readDescriptors();
writer.writeDocuments(TEST_TIME);
@@ -181,8 +175,8 @@ public class UptimeDocumentWriterTest {
this.documentStore.getPerformedStoreOperations());
UptimeDocument document = this.documentStore.getDocument(
UptimeDocument.class, GABELMOO_FINGERPRINT);
- this.assertOneWeekGraph(document, 1, "2014-03-23 09:30:00",
- "2014-03-23 11:30:00", 3,
+ this.assertOneMonthGraph(document, 1, "2014-03-23 02:00:00",
+ "2014-03-23 10:00:00", 3,
Arrays.asList(999, 999, 0));
}
@@ -197,8 +191,8 @@ public class UptimeDocumentWriterTest {
this.documentStore.getPerformedStoreOperations());
UptimeDocument document = this.documentStore.getDocument(
UptimeDocument.class, GABELMOO_FINGERPRINT);
- this.assertOneWeekGraph(document, 1, "2014-03-16 13:30:00",
- "2014-03-23 12:30:00", 168, null);
+ this.assertOneMonthGraph(document, 1, "2014-03-16 14:00:00",
+ "2014-03-23 10:00:00", 42, null);
}
@Test
@@ -212,8 +206,8 @@ public class UptimeDocumentWriterTest {
this.documentStore.getPerformedStoreOperations());
UptimeDocument document = this.documentStore.getDocument(
UptimeDocument.class, GABELMOO_FINGERPRINT);
- this.assertOneWeekGraph(document, 1, "2014-03-16 13:30:00",
- "2014-03-23 12:30:00", 168, null);
+ this.assertOneMonthGraph(document, 1, "2014-03-16 14:00:00",
+ "2014-03-23 10:00:00", 42, null);
}
@Test
@@ -227,7 +221,7 @@ public class UptimeDocumentWriterTest {
this.documentStore.getPerformedStoreOperations());
UptimeDocument document = this.documentStore.getDocument(
UptimeDocument.class, GABELMOO_FINGERPRINT);
- this.assertOneMonthGraph(document, 2, "2014-03-16 10:00:00",
+ this.assertOneMonthGraph(document, 1, "2014-03-16 10:00:00",
"2014-03-16 14:00:00", 2, null);
}
@@ -242,7 +236,7 @@ public class UptimeDocumentWriterTest {
this.documentStore.getPerformedStoreOperations());
UptimeDocument document = this.documentStore.getDocument(
UptimeDocument.class, GABELMOO_FINGERPRINT);
- this.assertOneMonthGraph(document, 2, "2014-03-16 10:00:00",
+ this.assertOneMonthGraph(document, 1, "2014-03-16 10:00:00",
"2014-03-16 14:00:00", 2,
Arrays.asList(999, 499));
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits