commit ee54f8e957ea24c66465e216eb9bec9e024d14e9 Author: Karsten Loesing karsten.loesing@gmx.net Date: Fri Aug 15 18:37:35 2014 +0200
Simplify UptimeStatusTest.
There's no reason (anymore) to test the status class together with DocumentStore. --- .../org/torproject/onionoo/UptimeStatusTest.java | 94 ++++---------------- 1 file changed, 18 insertions(+), 76 deletions(-)
diff --git a/src/test/java/org/torproject/onionoo/UptimeStatusTest.java b/src/test/java/org/torproject/onionoo/UptimeStatusTest.java index 984a281..f83e5a4 100644 --- a/src/test/java/org/torproject/onionoo/UptimeStatusTest.java +++ b/src/test/java/org/torproject/onionoo/UptimeStatusTest.java @@ -4,40 +4,21 @@ package org.torproject.onionoo;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue;
import java.util.Arrays; import java.util.TreeSet;
-import org.junit.Before; import org.junit.Test; import org.torproject.onionoo.docs.DateTimeHelper; -import org.torproject.onionoo.docs.DocumentStoreFactory; import org.torproject.onionoo.docs.UptimeHistory; import org.torproject.onionoo.docs.UptimeStatus;
public class UptimeStatusTest {
- private DummyDocumentStore documentStore; - - @Before - public void createDummyDocumentStore() { - this.documentStore = new DummyDocumentStore(); - DocumentStoreFactory.setDocumentStore(this.documentStore); - } - - private static final String MORIA1_FINGERPRINT = - "9695DFC35FFEB861329B9F1AB04C46397020CE31"; - @Test() - public void testEmptyStatusNoWriteToDisk() { - UptimeStatus uptimeStatus = this.documentStore.retrieve( - UptimeStatus.class, true, MORIA1_FINGERPRINT); - assertEquals("Should make one retrieve attempt.", 1, - this.documentStore.getPerformedRetrieveOperations()); - assertNull("Uptime status should not exist.", uptimeStatus); - uptimeStatus = new UptimeStatus(); + public void testEmptyStatusNotDirty() { + UptimeStatus uptimeStatus = new UptimeStatus(); assertFalse("Newly created uptime status should not be dirty.", uptimeStatus.isDirty()); } @@ -50,7 +31,6 @@ public class UptimeStatusTest { uptimeStatus.compressHistory(); assertTrue("Changed uptime status should say it's dirty.", uptimeStatus.isDirty()); - this.documentStore.store(uptimeStatus, MORIA1_FINGERPRINT); assertEquals("History must contain single entry.", 1, uptimeStatus.getRelayHistory().size()); UptimeHistory newUptimeHistory = @@ -62,9 +42,6 @@ public class UptimeStatusTest { newUptimeHistory.getStartMillis()); assertEquals("History uptime hours not 1.", 1, newUptimeHistory.getUptimeHours()); - assertEquals("Newly created uptime status with non-empty history " - + "must be written to disk.", 1, - this.documentStore.getPerformedStoreOperations()); }
@Test() @@ -74,7 +51,6 @@ public class UptimeStatusTest { new Long[] { DateTimeHelper.parse("2013-12-20 00:00:00"), DateTimeHelper.parse("2013-12-20 01:00:00") }))); uptimeStatus.compressHistory(); - this.documentStore.store(uptimeStatus, MORIA1_FINGERPRINT); assertEquals("History must contain single entry.", 1, uptimeStatus.getRelayHistory().size()); UptimeHistory newUptimeHistory = @@ -88,32 +64,21 @@ public class UptimeStatusTest { newUptimeHistory.getUptimeHours()); }
- private static final String GABELMOO_FINGERPRINT = - "F2044413DAC2E02E3D6BCF4735A19BCA1DE97281"; - - private static final String GABELMOO_UPTIME_SAMPLE = + private static final String RELAY_UPTIME_SAMPLE = "r 2013-07-22-17 1161\n" /* ends 2013-09-09 02:00:00 */ + "r 2013-09-09-03 2445\n" /* ends 2013-12-20 00:00:00 */ + "r 2013-12-20-01 2203\n"; /* ends 2014-03-21 20:00:00 */
- private void addGabelmooUptimeSample() { - UptimeStatus uptimeStatus = new UptimeStatus(); - uptimeStatus.fromDocumentString(GABELMOO_UPTIME_SAMPLE); - this.documentStore.addDocument(uptimeStatus, GABELMOO_FINGERPRINT); - } - @Test() public void testGabelmooFillInGaps() { - this.addGabelmooUptimeSample(); - UptimeStatus uptimeStatus = this.documentStore.retrieve( - UptimeStatus.class, true, GABELMOO_FINGERPRINT); + UptimeStatus uptimeStatus = new UptimeStatus(); + uptimeStatus.fromDocumentString(RELAY_UPTIME_SAMPLE); uptimeStatus.addToHistory(true, new TreeSet<Long>(Arrays.asList( new Long[] { DateTimeHelper.parse("2013-09-09 02:00:00"), DateTimeHelper.parse("2013-12-20 00:00:00") }))); assertEquals("Uncompressed history must contain five entries.", 5, uptimeStatus.getRelayHistory().size()); uptimeStatus.compressHistory(); - this.documentStore.store(uptimeStatus, GABELMOO_FINGERPRINT); assertEquals("Compressed history must contain one entry.", 1, uptimeStatus.getRelayHistory().size()); UptimeHistory newUptimeHistory = @@ -129,40 +94,34 @@ public class UptimeStatusTest {
@Test() public void testAddExistingHourToIntervalStart() { - this.addGabelmooUptimeSample(); - UptimeStatus uptimeStatus = this.documentStore.retrieve( - UptimeStatus.class, true, GABELMOO_FINGERPRINT); + UptimeStatus uptimeStatus = new UptimeStatus(); + uptimeStatus.fromDocumentString(RELAY_UPTIME_SAMPLE); uptimeStatus.addToHistory(true, new TreeSet<Long>(Arrays.asList( new Long[] { DateTimeHelper.parse("2013-07-22 17:00:00") }))); uptimeStatus.compressHistory(); - this.documentStore.store(uptimeStatus, GABELMOO_FINGERPRINT); assertFalse("Unchanged history should not make uptime status dirty.", uptimeStatus.isDirty()); }
@Test() public void testAddExistingHourToIntervalEnd() { - this.addGabelmooUptimeSample(); - UptimeStatus uptimeStatus = this.documentStore.retrieve( - UptimeStatus.class, true, GABELMOO_FINGERPRINT); + UptimeStatus uptimeStatus = new UptimeStatus(); + uptimeStatus.fromDocumentString(RELAY_UPTIME_SAMPLE); uptimeStatus.addToHistory(true, new TreeSet<Long>(Arrays.asList( new Long[] { DateTimeHelper.parse("2013-09-09 01:00:00") }))); uptimeStatus.compressHistory(); - this.documentStore.store(uptimeStatus, GABELMOO_FINGERPRINT); assertFalse("Unchanged history should not make uptime status dirty.", uptimeStatus.isDirty()); }
@Test() public void testTwoHoursOverlappingWithIntervalStart() { - this.addGabelmooUptimeSample(); - UptimeStatus uptimeStatus = this.documentStore.retrieve( - UptimeStatus.class, true, GABELMOO_FINGERPRINT); + UptimeStatus uptimeStatus = new UptimeStatus(); + uptimeStatus.fromDocumentString(RELAY_UPTIME_SAMPLE); uptimeStatus.addToHistory(true, new TreeSet<Long>(Arrays.asList( new Long[] { DateTimeHelper.parse("2013-07-22 16:00:00"), DateTimeHelper.parse("2013-07-22 17:00:00")}))); uptimeStatus.compressHistory(); - this.documentStore.store(uptimeStatus, GABELMOO_FINGERPRINT); assertEquals("Compressed history must still contain three entries.", 3, uptimeStatus.getRelayHistory().size()); UptimeHistory newUptimeHistory = @@ -178,14 +137,12 @@ public class UptimeStatusTest {
@Test() public void testTwoHoursOverlappingWithIntervalEnd() { - this.addGabelmooUptimeSample(); - UptimeStatus uptimeStatus = this.documentStore.retrieve( - UptimeStatus.class, true, GABELMOO_FINGERPRINT); + UptimeStatus uptimeStatus = new UptimeStatus(); + uptimeStatus.fromDocumentString(RELAY_UPTIME_SAMPLE); uptimeStatus.addToHistory(true, new TreeSet<Long>(Arrays.asList( new Long[] { DateTimeHelper.parse("2013-09-09 01:00:00"), DateTimeHelper.parse("2013-09-09 02:00:00")}))); uptimeStatus.compressHistory(); - this.documentStore.store(uptimeStatus, GABELMOO_FINGERPRINT); assertEquals("Compressed history must now contain two entries.", 2, uptimeStatus.getRelayHistory().size()); UptimeHistory newUptimeHistory = @@ -199,30 +156,18 @@ public class UptimeStatusTest { newUptimeHistory.getUptimeHours()); }
- private static final String ALL_RELAYS_AND_BRIDGES_FINGERPRINT = null; - - private static final String ALL_RELAYS_AND_BRIDGES_UPTIME_SAMPLE = + private static final String RELAYS_AND_BRIDGES_UPTIME_SAMPLE = "r 2013-07-22-17 5811\n" /* ends 2014-03-21 20:00:00 */ + "b 2013-07-22-17 5811\n"; /* ends 2014-03-21 20:00:00 */
- private void addAllRelaysAndBridgesUptimeSample() { - UptimeStatus uptimeStatus = new UptimeStatus(); - uptimeStatus.fromDocumentString(ALL_RELAYS_AND_BRIDGES_UPTIME_SAMPLE); - this.documentStore.addDocument(uptimeStatus, - ALL_RELAYS_AND_BRIDGES_FINGERPRINT); - } - @Test() public void testAddRelayUptimeHours() { - this.addAllRelaysAndBridgesUptimeSample(); - UptimeStatus uptimeStatus = this.documentStore.retrieve( - UptimeStatus.class, true, ALL_RELAYS_AND_BRIDGES_FINGERPRINT); + UptimeStatus uptimeStatus = new UptimeStatus(); + uptimeStatus.fromDocumentString(RELAYS_AND_BRIDGES_UPTIME_SAMPLE); uptimeStatus.addToHistory(true, new TreeSet<Long>(Arrays.asList( new Long[] { DateTimeHelper.parse("2013-07-22 16:00:00"), DateTimeHelper.parse("2014-03-21 20:00:00")}))); uptimeStatus.compressHistory(); - this.documentStore.store(uptimeStatus, - ALL_RELAYS_AND_BRIDGES_FINGERPRINT); assertEquals("Compressed relay history must still contain one entry.", 1, uptimeStatus.getRelayHistory().size()); UptimeHistory newUptimeHistory = @@ -238,15 +183,12 @@ public class UptimeStatusTest {
@Test() public void testAddBridgeUptimeHours() { - this.addAllRelaysAndBridgesUptimeSample(); - UptimeStatus uptimeStatus = this.documentStore.retrieve( - UptimeStatus.class, true, ALL_RELAYS_AND_BRIDGES_FINGERPRINT); + UptimeStatus uptimeStatus = new UptimeStatus(); + uptimeStatus.fromDocumentString(RELAYS_AND_BRIDGES_UPTIME_SAMPLE); uptimeStatus.addToHistory(false, new TreeSet<Long>(Arrays.asList( new Long[] { DateTimeHelper.parse("2013-07-22 16:00:00"), DateTimeHelper.parse("2014-03-21 20:00:00")}))); uptimeStatus.compressHistory(); - this.documentStore.store(uptimeStatus, - ALL_RELAYS_AND_BRIDGES_FINGERPRINT); assertEquals("Compressed bridge history must still contain one " + "entry.", 1, uptimeStatus.getBridgeHistory().size()); UptimeHistory newUptimeHistory =
tor-commits@lists.torproject.org