Loading src/test/java/org/torproject/onionoo/writer/BandwidthDocumentWriterTest.java +33 −29 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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()); Loading Loading
src/test/java/org/torproject/onionoo/writer/BandwidthDocumentWriterTest.java +33 −29 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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()); Loading