MongoDBStore { public static Set<String> getExpiredJobs() { Set<Document> documents = new HashSet(); Long currentMS = System.currentTimeMillis(); Document query = new Document("expireDate", new Document("$lte", currentMS).append("$ne", 0)); Bson projection = Projections.fields(include("_id", "expireDate")); FindIterable<Document> iterable = jobs.find(query).projection(projection); Iterator iterator = iterable.iterator(); while(iterator.hasNext()) { Document document = (Document) iterator.next(); documents.add(document); } Long expireEndTime = currentMS - LGJob.DAY*LGJob.DEFAULT_EXPIRE_DAYS; query = new Document("endTime", new Document("$lte", expireEndTime).append("$ne", 0)); projection = Projections.fields(include("_id", "endTime")); iterable = jobs.find(query).projection(projection); iterator = iterable.iterator(); while(iterator.hasNext()) { Document document = (Document) iterator.next(); documents.add(document); } Long expireStartTime = currentMS - LGJob.DAY*LGJob.DEFAULT_EXPIRE_DAYS; query = new Document("startTime", new Document("$lte", expireStartTime)); Document zero = new Document("$eq", 0); query.append("endTime", zero); projection = Projections.fields(include("_id", "endTime")); iterable = jobs.find(query).projection(projection); iterator = iterable.iterator(); while(iterator.hasNext()) { Document document = (Document) iterator.next(); documents.add(document); } return getIDs(documents); } MongoDBStore(); static void open(); static void close(); static MongoDatabase getDatabase(); static void deleteJob(String jobId); static void deleteTask(String taskId); static void deleteTasksByJob(String jobId); static void deleteTasks(String key, String value); static void deleteItem(MongoCollection collection, String key, String value); static void deleteMany(MongoCollection collection, String key, String value); static ArrayList<Document> getTasksFromJob(String jobId); static ArrayList<Document> getJob(String jobId); static ArrayList<Document> getJobs(JSONArray jobIds); static ArrayList<Document> getJobs(); static ArrayList<Document> getDocuments(MongoCollection collection, String key, String value); static ArrayList<Document> getDocuments(MongoCollection collection, String key, JSONArray input); static JSONObject toJSON(ArrayList<Document> input); static void printDocuments(Iterable<Document> iterable); static boolean hasNode(String job_id, String key); static Set<Document> getPastJobs(String field); static Set<String> getResetJobs(); static Set<String> getExpiredJobs(); static JSONObject getNodeByKey(String job_id, String key); static void saveNode(String job_id, String key, JSONObject metadata); static boolean hasEdge(String job_id, String key); static boolean hasId(String collection, String _id); static JSONObject getEdgeByKey(String job_id, String key); static void saveEdge(String job_id, String key, String srcKey, String dstKey, JSONObject metadata); static JSONObject getGraphByJobId(String job_id); static void appendToDBValues(String collection, String _id, String key, Object listItem); static void appendToTask(String taskId, String key, Object update); static void appendToAdapters(String _id, String key, Object update); static void appendToJob(String jobId, String key, Object update); static void updateJob(String jobId, String key, Object update); static void insertToObject(String collection, String _id, String objectName, JSONObject value); static void appendToList(String collection, String _id, String key, Object listItem); static void appendToList(String collection, String _id, String key, Object listItem, boolean upsert); static void removeFromList(String collection, String _id, String key, Object listItem); static BasicDBObject createObject(JSONObject object, String insert); static void appendToDocument(String collection, String _id, Object input); static void appendToDocument(String collection, String _id, String key, Object update); static void updateDocument(String collection, String _id, Document doc); static void insertDocument(String collection, Document doc); static void saveDocument(String collection, String _id, Document doc); static Set<String> getIDs(Set<Document> input);  }
@Test public void getExpiredJobsTest() { Set<String> jobIds = MongoDBStore.getExpiredJobs(); int expiredJobs = jobIds.size(); assert expiredJobs >= 0; jobIds = MongoDBStore.getResetJobs(); int resetJobs = jobIds.size(); assert resetJobs >= 0; }