[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/master] Use factory instead of passing around references.
commit f2e453070bd5e7bf2023a639178734adb5d8b022
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Fri Mar 21 20:41:33 2014 +0100
Use factory instead of passing around references.
---
src/org/torproject/onionoo/ApplicationFactory.java | 40 ++++++++++++++++++++
.../onionoo/BandwidthDocumentWriter.java | 9 ++---
.../torproject/onionoo/BandwidthStatusUpdater.java | 9 ++---
.../torproject/onionoo/ClientsDocumentWriter.java | 9 ++---
.../torproject/onionoo/ClientsStatusUpdater.java | 9 ++---
src/org/torproject/onionoo/DescriptorSource.java | 8 ++--
.../torproject/onionoo/DetailsDocumentWriter.java | 9 ++---
src/org/torproject/onionoo/DocumentStore.java | 21 +++++-----
src/org/torproject/onionoo/LockFile.java | 12 ++----
src/org/torproject/onionoo/Logger.java | 4 +-
src/org/torproject/onionoo/Main.java | 35 ++++++++---------
.../onionoo/NodeDetailsStatusUpdater.java | 11 +++---
src/org/torproject/onionoo/RequestHandler.java | 7 ++--
src/org/torproject/onionoo/ResourceServlet.java | 13 +++----
src/org/torproject/onionoo/ResponseBuilder.java | 4 +-
.../onionoo/ReverseDomainNameResolver.java | 4 +-
.../torproject/onionoo/UptimeDocumentWriter.java | 9 ++---
.../torproject/onionoo/UptimeStatusUpdater.java | 7 ++--
.../torproject/onionoo/WeightsDocumentWriter.java | 9 ++---
.../torproject/onionoo/WeightsStatusUpdater.java | 9 ++---
.../org/torproject/onionoo/DummyDocumentStore.java | 4 +-
.../torproject/onionoo/ResourceServletTest.java | 23 +++++++----
22 files changed, 142 insertions(+), 123 deletions(-)
diff --git a/src/org/torproject/onionoo/ApplicationFactory.java b/src/org/torproject/onionoo/ApplicationFactory.java
new file mode 100644
index 0000000..98952df
--- /dev/null
+++ b/src/org/torproject/onionoo/ApplicationFactory.java
@@ -0,0 +1,40 @@
+/* Copyright 2014 The Tor Project
+ * See LICENSE for licensing information */
+package org.torproject.onionoo;
+
+public class ApplicationFactory {
+
+ private static Time timeInstance;
+ public static void setTime(Time time) {
+ timeInstance = time;
+ }
+ public static Time getTime() {
+ if (timeInstance == null) {
+ timeInstance = new Time();
+ }
+ return timeInstance;
+ }
+
+ private static DescriptorSource descriptorSourceInstance;
+ public static void setDescriptorSource(
+ DescriptorSource descriptorSource) {
+ descriptorSourceInstance = descriptorSource;
+ }
+ public static DescriptorSource getDescriptorSource() {
+ if (descriptorSourceInstance == null) {
+ descriptorSourceInstance = new DescriptorSource();
+ }
+ return descriptorSourceInstance;
+ }
+
+ private static DocumentStore documentStoreInstance;
+ public static void setDocumentStore(DocumentStore documentStore) {
+ documentStoreInstance = documentStore;
+ }
+ public static DocumentStore getDocumentStore() {
+ if (documentStoreInstance == null) {
+ documentStoreInstance = new DocumentStore();
+ }
+ return documentStoreInstance;
+ }
+}
diff --git a/src/org/torproject/onionoo/BandwidthDocumentWriter.java b/src/org/torproject/onionoo/BandwidthDocumentWriter.java
index 8e9b93c..0bc8387 100644
--- a/src/org/torproject/onionoo/BandwidthDocumentWriter.java
+++ b/src/org/torproject/onionoo/BandwidthDocumentWriter.java
@@ -19,11 +19,10 @@ public class BandwidthDocumentWriter implements FingerprintListener,
private long now;
- public BandwidthDocumentWriter(DescriptorSource descriptorSource,
- DocumentStore documentStore, Time time) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ public BandwidthDocumentWriter() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerFingerprintListeners();
}
diff --git a/src/org/torproject/onionoo/BandwidthStatusUpdater.java b/src/org/torproject/onionoo/BandwidthStatusUpdater.java
index 7633e9f..6320f6e 100644
--- a/src/org/torproject/onionoo/BandwidthStatusUpdater.java
+++ b/src/org/torproject/onionoo/BandwidthStatusUpdater.java
@@ -17,11 +17,10 @@ public class BandwidthStatusUpdater implements DescriptorListener,
private long now;
- public BandwidthStatusUpdater(DescriptorSource descriptorSource,
- DocumentStore documentStore, Time time) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ public BandwidthStatusUpdater() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerDescriptorListeners();
}
diff --git a/src/org/torproject/onionoo/ClientsDocumentWriter.java b/src/org/torproject/onionoo/ClientsDocumentWriter.java
index 34047b5..bab78e9 100644
--- a/src/org/torproject/onionoo/ClientsDocumentWriter.java
+++ b/src/org/torproject/onionoo/ClientsDocumentWriter.java
@@ -43,11 +43,10 @@ public class ClientsDocumentWriter implements FingerprintListener,
private long now;
- public ClientsDocumentWriter(DescriptorSource descriptorSource,
- DocumentStore documentStore, Time time) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ public ClientsDocumentWriter() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerFingerprintListeners();
}
diff --git a/src/org/torproject/onionoo/ClientsStatusUpdater.java b/src/org/torproject/onionoo/ClientsStatusUpdater.java
index 56803d4..ed4390e 100644
--- a/src/org/torproject/onionoo/ClientsStatusUpdater.java
+++ b/src/org/torproject/onionoo/ClientsStatusUpdater.java
@@ -38,11 +38,10 @@ public class ClientsStatusUpdater implements DescriptorListener,
private long now;
- public ClientsStatusUpdater(DescriptorSource descriptorSource,
- DocumentStore documentStore, Time time) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ public ClientsStatusUpdater() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerDescriptorListeners();
}
diff --git a/src/org/torproject/onionoo/DescriptorSource.java b/src/org/torproject/onionoo/DescriptorSource.java
index 86fba25..f5adf56 100644
--- a/src/org/torproject/onionoo/DescriptorSource.java
+++ b/src/org/torproject/onionoo/DescriptorSource.java
@@ -267,15 +267,13 @@ class DescriptorQueue {
public class DescriptorSource {
- private File inDir;
+ private final File inDir = new File("in");
- private File statusDir;
+ private final File statusDir = new File("status");
private List<DescriptorQueue> descriptorQueues;
- public DescriptorSource(File inDir, File statusDir) {
- this.inDir = inDir;
- this.statusDir = statusDir;
+ public DescriptorSource() {
this.descriptorQueues = new ArrayList<DescriptorQueue>();
this.descriptorListeners =
new HashMap<DescriptorType, Set<DescriptorListener>>();
diff --git a/src/org/torproject/onionoo/DetailsDocumentWriter.java b/src/org/torproject/onionoo/DetailsDocumentWriter.java
index 309b80d..c1ae9d0 100644
--- a/src/org/torproject/onionoo/DetailsDocumentWriter.java
+++ b/src/org/torproject/onionoo/DetailsDocumentWriter.java
@@ -24,11 +24,10 @@ public class DetailsDocumentWriter implements DescriptorListener,
private long now;
- public DetailsDocumentWriter(DescriptorSource descriptorSource,
- DocumentStore documentStore, Time time) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ public DetailsDocumentWriter() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerDescriptorListeners();
this.registerFingerprintListeners();
}
diff --git a/src/org/torproject/onionoo/DocumentStore.java b/src/org/torproject/onionoo/DocumentStore.java
index 95f8f93..e8b35b5 100644
--- a/src/org/torproject/onionoo/DocumentStore.java
+++ b/src/org/torproject/onionoo/DocumentStore.java
@@ -29,12 +29,19 @@ import com.google.gson.JsonParseException;
// TODO Also look into simple key-value stores instead of real databases.
public class DocumentStore {
- private File statusDir;
+ private final File statusDir = new File("status");
- private File outDir;
+ private File outDir = new File("out");
+ public void setOutDir(File outDir) {
+ this.outDir = outDir;
+ }
private Time time;
+ public DocumentStore() {
+ this.time = ApplicationFactory.getTime();
+ }
+
private boolean listedArchivedNodeStatuses = false,
listedCurrentNodeStatuses = false;
@@ -48,16 +55,6 @@ public class DocumentStore {
* operations depend on which NodeStatus documents were listed. */
private SortedMap<String, NodeStatus> cachedNodeStatuses;
- public DocumentStore(File outDir, Time time) {
- this(null, outDir, time);
- }
-
- public DocumentStore(File statusDir, File outDir, Time time) {
- this.statusDir = statusDir;
- this.outDir = outDir;
- this.time = time;
- }
-
public <T extends Document> SortedSet<String> list(
Class<T> documentType, boolean includeArchive) {
if (documentType.equals(NodeStatus.class)) {
diff --git a/src/org/torproject/onionoo/LockFile.java b/src/org/torproject/onionoo/LockFile.java
index acf2dc2..768db53 100644
--- a/src/org/torproject/onionoo/LockFile.java
+++ b/src/org/torproject/onionoo/LockFile.java
@@ -9,16 +9,10 @@ import java.io.IOException;
public class LockFile {
- private File lockFile;
-
- private Time time;
-
- public LockFile(File lockFile, Time time) {
- this.lockFile = lockFile;
- this.time = time;
- }
+ private final File lockFile = new File("lock");
public boolean acquireLock() {
+ Time time = ApplicationFactory.getTime();
try {
if (this.lockFile.exists()) {
return false;
@@ -28,7 +22,7 @@ public class LockFile {
}
BufferedWriter bw = new BufferedWriter(new FileWriter(
this.lockFile));
- bw.append("" + this.time.currentTimeMillis() + "\n");
+ bw.append("" + time.currentTimeMillis() + "\n");
bw.close();
return true;
} catch (IOException e) {
diff --git a/src/org/torproject/onionoo/Logger.java b/src/org/torproject/onionoo/Logger.java
index 5ae9be1..d84adf2 100644
--- a/src/org/torproject/onionoo/Logger.java
+++ b/src/org/torproject/onionoo/Logger.java
@@ -11,8 +11,8 @@ public class Logger {
private static Time time;
- public static void setTime(Time timeParam) {
- time = timeParam;
+ public static void setTime() {
+ time = ApplicationFactory.getTime();
}
private static long currentTimeMillis() {
diff --git a/src/org/torproject/onionoo/Main.java b/src/org/torproject/onionoo/Main.java
index a4e2d92..141e44b 100644
--- a/src/org/torproject/onionoo/Main.java
+++ b/src/org/torproject/onionoo/Main.java
@@ -12,9 +12,8 @@ public class Main {
public static void main(String[] args) {
- Time t = new Time();
- LockFile lf = new LockFile(new File("lock"), t);
- Logger.setTime(t);
+ LockFile lf = new LockFile();
+ Logger.setTime();
Logger.printStatus("Initializing.");
if (lf.acquireLock()) {
Logger.printStatusTime("Acquired lock");
@@ -24,39 +23,37 @@ public class Main {
return;
}
- DescriptorSource dso = new DescriptorSource(new File("in"),
- new File("status"));
+ DescriptorSource dso = ApplicationFactory.getDescriptorSource();
Logger.printStatusTime("Initialized descriptor source");
- DocumentStore ds = new DocumentStore(new File("status"),
- new File("out"), t);
+ DocumentStore ds = ApplicationFactory.getDocumentStore();
Logger.printStatusTime("Initialized document store");
LookupService ls = new LookupService(new File("geoip"));
Logger.printStatusTime("Initialized Geoip lookup service");
- ReverseDomainNameResolver rdnr = new ReverseDomainNameResolver(t);
+ ReverseDomainNameResolver rdnr = new ReverseDomainNameResolver();
Logger.printStatusTime("Initialized reverse domain name resolver");
- NodeDetailsStatusUpdater ndsu = new NodeDetailsStatusUpdater(dso,
- rdnr, ls, ds, t);
+ NodeDetailsStatusUpdater ndsu = new NodeDetailsStatusUpdater(rdnr,
+ ls);
Logger.printStatusTime("Initialized node data writer");
- BandwidthStatusUpdater bsu = new BandwidthStatusUpdater(dso, ds, t);
+ BandwidthStatusUpdater bsu = new BandwidthStatusUpdater();
Logger.printStatusTime("Initialized bandwidth status updater");
- WeightsStatusUpdater wsu = new WeightsStatusUpdater(dso, ds, t);
+ WeightsStatusUpdater wsu = new WeightsStatusUpdater();
Logger.printStatusTime("Initialized weights status updater");
- ClientsStatusUpdater csu = new ClientsStatusUpdater(dso, ds, t);
+ ClientsStatusUpdater csu = new ClientsStatusUpdater();
Logger.printStatusTime("Initialized clients status updater");
- UptimeStatusUpdater usu = new UptimeStatusUpdater(dso, ds);
+ UptimeStatusUpdater usu = new UptimeStatusUpdater();
Logger.printStatusTime("Initialized uptime status updater");
StatusUpdater[] sus = new StatusUpdater[] { ndsu, bsu, wsu, csu,
usu };
- DetailsDocumentWriter ddw = new DetailsDocumentWriter(dso, ds, t);
+ DetailsDocumentWriter ddw = new DetailsDocumentWriter();
Logger.printStatusTime("Initialized details document writer");
- BandwidthDocumentWriter bdw = new BandwidthDocumentWriter(dso, ds, t);
+ BandwidthDocumentWriter bdw = new BandwidthDocumentWriter();
Logger.printStatusTime("Initialized bandwidth document writer");
- WeightsDocumentWriter wdw = new WeightsDocumentWriter(dso, ds, t);
+ WeightsDocumentWriter wdw = new WeightsDocumentWriter();
Logger.printStatusTime("Initialized weights document writer");
- ClientsDocumentWriter cdw = new ClientsDocumentWriter(dso, ds, t);
+ ClientsDocumentWriter cdw = new ClientsDocumentWriter();
Logger.printStatusTime("Initialized clients document writer");
- UptimeDocumentWriter udw = new UptimeDocumentWriter(dso, ds, t);
+ UptimeDocumentWriter udw = new UptimeDocumentWriter();
Logger.printStatusTime("Initialized uptime document writer");
DocumentWriter[] dws = new DocumentWriter[] { ddw, bdw, wdw, cdw,
udw };
diff --git a/src/org/torproject/onionoo/NodeDetailsStatusUpdater.java b/src/org/torproject/onionoo/NodeDetailsStatusUpdater.java
index 2cf5061..4d32b2c 100644
--- a/src/org/torproject/onionoo/NodeDetailsStatusUpdater.java
+++ b/src/org/torproject/onionoo/NodeDetailsStatusUpdater.java
@@ -49,15 +49,14 @@ public class NodeDetailsStatusUpdater implements DescriptorListener,
private int relayConsensusesProcessed = 0, bridgeStatusesProcessed = 0;
- public NodeDetailsStatusUpdater(DescriptorSource descriptorSource,
+ public NodeDetailsStatusUpdater(
ReverseDomainNameResolver reverseDomainNameResolver,
- LookupService lookupService, DocumentStore documentStore,
- Time time) {
- this.descriptorSource = descriptorSource;
+ LookupService lookupService) {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
this.reverseDomainNameResolver = reverseDomainNameResolver;
this.lookupService = lookupService;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerDescriptorListeners();
}
diff --git a/src/org/torproject/onionoo/RequestHandler.java b/src/org/torproject/onionoo/RequestHandler.java
index 6a25549..89871ae 100644
--- a/src/org/torproject/onionoo/RequestHandler.java
+++ b/src/org/torproject/onionoo/RequestHandler.java
@@ -31,10 +31,9 @@ public class RequestHandler {
relaysByLastSeenDays = null, bridgesByLastSeenDays = null;
private static final long SUMMARY_MAX_AGE = DateTimeHelper.SIX_HOURS;
- public static void initialize(DocumentStore documentStoreParam,
- Time timeParam) {
- documentStore = documentStoreParam;
- time = timeParam;
+ public static void initialize() {
+ documentStore = ApplicationFactory.getDocumentStore();
+ time = ApplicationFactory.getTime();
readSummaryFile();
}
diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java
index 0c01d9f..dcfefc5 100644
--- a/src/org/torproject/onionoo/ResourceServlet.java
+++ b/src/org/torproject/onionoo/ResourceServlet.java
@@ -31,19 +31,18 @@ public class ResourceServlet extends HttpServlet {
config.getInitParameter("maintenance") != null
&& config.getInitParameter("maintenance").equals("1");
File outDir = new File(config.getInitParameter("outDir"));
- Time time = new Time();
- DocumentStore documentStore = new DocumentStore(outDir, time);
- this.init(maintenanceMode, documentStore, time);
+ DocumentStore documentStore = ApplicationFactory.getDocumentStore();
+ documentStore.setOutDir(outDir);
+ this.init(maintenanceMode);
}
/* Called (indirectly) by servlet container and (directly) by test
* class. */
- protected void init(boolean maintenanceMode,
- DocumentStore documentStore, Time time) {
+ protected void init(boolean maintenanceMode) {
this.maintenanceMode = maintenanceMode;
if (!maintenanceMode) {
- RequestHandler.initialize(documentStore, time);
- ResponseBuilder.initialize(documentStore);
+ RequestHandler.initialize();
+ ResponseBuilder.initialize();
}
}
diff --git a/src/org/torproject/onionoo/ResponseBuilder.java b/src/org/torproject/onionoo/ResponseBuilder.java
index 69b5c62..a841d29 100644
--- a/src/org/torproject/onionoo/ResponseBuilder.java
+++ b/src/org/torproject/onionoo/ResponseBuilder.java
@@ -11,8 +11,8 @@ public class ResponseBuilder {
private static DocumentStore documentStore;
- public static void initialize(DocumentStore documentStoreParam) {
- documentStore = documentStoreParam;
+ public static void initialize() {
+ documentStore = ApplicationFactory.getDocumentStore();
}
private String resourceType;
diff --git a/src/org/torproject/onionoo/ReverseDomainNameResolver.java b/src/org/torproject/onionoo/ReverseDomainNameResolver.java
index e762811..3dbf9d1 100644
--- a/src/org/torproject/onionoo/ReverseDomainNameResolver.java
+++ b/src/org/torproject/onionoo/ReverseDomainNameResolver.java
@@ -85,8 +85,8 @@ public class ReverseDomainNameResolver {
private Time time;
- public ReverseDomainNameResolver(Time time) {
- this.time = time;
+ public ReverseDomainNameResolver() {
+ this.time = ApplicationFactory.getTime();
}
private static final long RDNS_LOOKUP_MAX_REQUEST_MILLIS =
diff --git a/src/org/torproject/onionoo/UptimeDocumentWriter.java b/src/org/torproject/onionoo/UptimeDocumentWriter.java
index a7b1bba..6b44b24 100644
--- a/src/org/torproject/onionoo/UptimeDocumentWriter.java
+++ b/src/org/torproject/onionoo/UptimeDocumentWriter.java
@@ -17,11 +17,10 @@ public class UptimeDocumentWriter implements FingerprintListener,
private long now;
- public UptimeDocumentWriter(DescriptorSource descriptorSource,
- DocumentStore documentStore, Time time) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ public UptimeDocumentWriter() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerFingerprintListeners();
}
diff --git a/src/org/torproject/onionoo/UptimeStatusUpdater.java b/src/org/torproject/onionoo/UptimeStatusUpdater.java
index 97a6be1..4430387 100644
--- a/src/org/torproject/onionoo/UptimeStatusUpdater.java
+++ b/src/org/torproject/onionoo/UptimeStatusUpdater.java
@@ -20,10 +20,9 @@ public class UptimeStatusUpdater implements DescriptorListener,
private DocumentStore documentStore;
- public UptimeStatusUpdater(DescriptorSource descriptorSource,
- DocumentStore documentStore) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
+ public UptimeStatusUpdater() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
this.registerDescriptorListeners();
}
diff --git a/src/org/torproject/onionoo/WeightsDocumentWriter.java b/src/org/torproject/onionoo/WeightsDocumentWriter.java
index 8dcca0a..d2f2a67 100644
--- a/src/org/torproject/onionoo/WeightsDocumentWriter.java
+++ b/src/org/torproject/onionoo/WeightsDocumentWriter.java
@@ -20,11 +20,10 @@ public class WeightsDocumentWriter implements FingerprintListener,
private long now;
- public WeightsDocumentWriter(DescriptorSource descriptorSource,
- DocumentStore documentStore, Time time) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ public WeightsDocumentWriter() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerFingerprintListeners();
}
diff --git a/src/org/torproject/onionoo/WeightsStatusUpdater.java b/src/org/torproject/onionoo/WeightsStatusUpdater.java
index 1e5d559..d3ddff1 100644
--- a/src/org/torproject/onionoo/WeightsStatusUpdater.java
+++ b/src/org/torproject/onionoo/WeightsStatusUpdater.java
@@ -26,11 +26,10 @@ public class WeightsStatusUpdater implements DescriptorListener,
private long now;
- public WeightsStatusUpdater(DescriptorSource descriptorSource,
- DocumentStore documentStore, Time time) {
- this.descriptorSource = descriptorSource;
- this.documentStore = documentStore;
- this.now = time.currentTimeMillis();
+ public WeightsStatusUpdater() {
+ this.descriptorSource = ApplicationFactory.getDescriptorSource();
+ this.documentStore = ApplicationFactory.getDocumentStore();
+ this.now = ApplicationFactory.getTime().currentTimeMillis();
this.registerDescriptorListeners();
}
diff --git a/test/org/torproject/onionoo/DummyDocumentStore.java b/test/org/torproject/onionoo/DummyDocumentStore.java
index 2f32833..c7ca7ff 100644
--- a/test/org/torproject/onionoo/DummyDocumentStore.java
+++ b/test/org/torproject/onionoo/DummyDocumentStore.java
@@ -1,6 +1,5 @@
package org.torproject.onionoo;
-import java.io.File;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
@@ -10,8 +9,7 @@ public class DummyDocumentStore extends DocumentStore {
private long lastModified;
- public DummyDocumentStore(long lastModified, Time time) {
- super((File) null, time);
+ public DummyDocumentStore(long lastModified) {
this.lastModified = lastModified;
}
diff --git a/test/org/torproject/onionoo/ResourceServletTest.java b/test/org/torproject/onionoo/ResourceServletTest.java
index 37963c8..3b8b5ae 100644
--- a/test/org/torproject/onionoo/ResourceServletTest.java
+++ b/test/org/torproject/onionoo/ResourceServletTest.java
@@ -32,21 +32,21 @@ public class ResourceServletTest {
private SortedMap<String, String> relays, bridges;
- private DummyDocumentStore documentStore;
-
// 2013-04-24 12:22:22
private static long lastModified = 1366806142000L;
private long currentTimeMillis = 1366806142000L;
private class TestingTime extends Time {
+ private long currentTimeMillis;
+ public TestingTime(long currentTimeMillis) {
+ this.currentTimeMillis = currentTimeMillis;
+ }
public long currentTimeMillis() {
- return currentTimeMillis;
+ return this.currentTimeMillis;
}
}
- private Time testingTime = new TestingTime();
-
private boolean maintenanceMode = false;
private class TestingHttpServletRequestWrapper
@@ -155,6 +155,7 @@ public class ResourceServletTest {
private void runTest(String requestURI,
Map<String, String[]> parameterMap) {
try {
+ this.createDummyTime();
this.createDummyDocumentStore();
this.makeRequest(requestURI, parameterMap);
this.parseResponse();
@@ -163,25 +164,31 @@ public class ResourceServletTest {
}
}
+ private void createDummyTime() {
+ Time dummyTime = new TestingTime(this.currentTimeMillis);
+ ApplicationFactory.setTime(dummyTime);
+ }
+
private void createDummyDocumentStore() {
/* TODO Incrementing static lastModified is necessary for
* ResponseBuilder to read state from the newly created DocumentStore.
* Otherwise, ResponseBuilder would use data from the previous test
* run. This is bad design and should be fixed. */
- this.documentStore = new DummyDocumentStore(lastModified++,
- this.testingTime);
+ DummyDocumentStore documentStore = new DummyDocumentStore(
+ lastModified++);
for (String relay : relays.values()) {
documentStore.addNodeStatus(relay);
}
for (String bridge : bridges.values()) {
documentStore.addNodeStatus(bridge);
}
+ ApplicationFactory.setDocumentStore(documentStore);
}
private void makeRequest(String requestURI,
Map<String, String[]> parameterMap) throws IOException {
ResourceServlet rs = new ResourceServlet();
- rs.init(maintenanceMode, this.documentStore, this.testingTime);
+ rs.init(this.maintenanceMode);
this.request = new TestingHttpServletRequestWrapper(requestURI,
parameterMap);
this.response = new TestingHttpServletResponseWrapper();
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits