@Test public void testQueryWithTimestampAndEmptyMap_shouldWork() throws Exception { Map<String, EDBObjectEntry> data1 = new HashMap<String, EDBObjectEntry>(); putValue("K", "B", data1); putValue("Cow", "Milk", data1); putValue("Dog", "Food", data1); EDBObject v1 = new EDBObject("/test/querynew3", data1); EDBCommit ci = getEDBCommit(); ci.insert(v1); db.commit(ci); data1 = new HashMap<String, EDBObjectEntry>(); putValue("Dog", "Food", data1); v1 = new EDBObject("/test/querynew3", data1); ci = getEDBCommit(); ci.update(v1); db.commit(ci); data1 = new HashMap<String, EDBObjectEntry>(); putValue("K", "B", data1); putValue("Dog", "Food", data1); v1 = new EDBObject("/test/querynew4", data1); ci = getEDBCommit(); ci.insert(v1); db.commit(ci); List<EDBObject> result = db.query(QueryRequest.create()); EDBObject result1 = getEDBObjectOutOfList(result, "/test/querynew3"); EDBObject result2 = getEDBObjectOutOfList(result, "/test/querynew4"); assertThat(result.size(), is(2)); assertThat(result1.containsKey("K"), is(false)); assertThat(result2.containsKey("Dog"), is(true)); }
@Test public void testIfRetrievingCommitRevisionsByRequestGivesCorrectRevisions_shouldWork() throws Exception { Map<String, EDBObjectEntry> entries = new HashMap<String, EDBObjectEntry>(); entries.put("test", new EDBObjectEntry("test", "test", String.class)); EDBObject obj = new EDBObject("/test/query/11", entries); EDBCommit ci = getEDBCommit(); ci.insert(obj); Long timestamp1 = db.commit(ci); String revision1 = ci.getRevisionNumber().toString(); obj.putEDBObjectEntry("test2", "test2", String.class); ci = getEDBCommit(); ci.setComment("this is a comment"); ci.update(obj); Long timestamp2 = db.commit(ci); String revision2 = ci.getRevisionNumber().toString(); CommitQueryRequest request = new CommitQueryRequest(); request.setCommitter("wrongName"); assertThat(db.getRevisionsOfMatchingCommits(request).size(), is(0)); request = new CommitQueryRequest(); request.setCommitter("wrongContext"); assertThat(db.getRevisionsOfMatchingCommits(request).size(), is(0)); request = new CommitQueryRequest(); request.setStartTimestamp(timestamp1); List<CommitMetaInfo> revisions = db.getRevisionsOfMatchingCommits(request); assertThat(revisions.size(), is(2)); assertThat(revisions.get(0).getRevision(), is(revision1)); assertThat(revisions.get(1).getRevision(), is(revision2)); request = new CommitQueryRequest(); request.setStartTimestamp(timestamp1); request.setCommitter("testuser"); revisions = db.getRevisionsOfMatchingCommits(request); assertThat(revisions.size(), is(2)); assertThat(revisions.get(0).getRevision(), is(revision1)); assertThat(revisions.get(1).getRevision(), is(revision2)); request = new CommitQueryRequest(); request.setStartTimestamp(timestamp2); revisions = db.getRevisionsOfMatchingCommits(request); assertThat(revisions.size(), is(1)); assertThat(revisions.get(0).getRevision(), is(revision2)); assertThat(revisions.get(0).getCommitter(), is(COMMITTER)); assertThat(revisions.get(0).getContext(), is(CONTEXT)); assertThat(revisions.get(0).getTimestamp(), is(timestamp2)); assertThat(revisions.get(0).getComment(), is("this is a comment")); }
@Test public void testIfRetrievingCommitByRevisionWithIntermediateCommitsWorks_shouldWork() throws Exception { Map<String, EDBObjectEntry> entries = new HashMap<String, EDBObjectEntry>(); entries.put("test", new EDBObjectEntry("test", "test", String.class)); EDBObject obj = new EDBObject("/test/query/10", entries); EDBCommit ci = getEDBCommit(); ci.insert(obj); db.commit(ci); String revision = ci.getRevisionNumber().toString(); obj.putEDBObjectEntry("test", "test2", String.class); EDBCommit ci2 = getEDBCommit(); ci2.update(obj); db.commit(ci2); EDBCommit test = db.getCommitByRevision(revision); assertThat(test, notNullValue()); assertThat(test, is(ci)); assertThat(test.getInserts().get(0).getString("test"), is("test")); }
@Test public void testQueryOfOldVersion_shouldWork() throws Exception { Map<String, EDBObjectEntry> data1v1 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 1", data1v1); putValue("pre:KeyB", "pre:Value A 1", data1v1); EDBObject v11 = new EDBObject("pre:/test/object1", data1v1); EDBCommit ci = getEDBCommit(); ci.insert(v11); Map<String, EDBObjectEntry> data2v1 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 2", data2v1); putValue("pre:KeyB", "pre:Value A 1", data2v1); EDBObject v12 = new EDBObject("pre:/test/object2", data2v1); ci.insert(v12); Map<String, EDBObjectEntry> data3v1 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 3", data3v1); putValue("pre:KeyB", "pre:Value A 1", data3v1); EDBObject v13 = new EDBObject("pre:/test/object3", data3v1); ci.insert(v13); long time1 = db.commit(ci); Map<String, EDBObjectEntry> data1v2 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 1", data1v2); putValue("pre:KeyB", "pre:Value A 1", data1v2); EDBObject v21 = new EDBObject("pre:/test/object1", data1v2); ci = getEDBCommit(); ci.update(v21); Map<String, EDBObjectEntry> data2v2 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 2", data2v2); putValue("pre:KeyB", "pre:Value A 1", data2v2); EDBObject v22 = new EDBObject("pre:/test/object2", data2v2); ci.update(v22); Map<String, EDBObjectEntry> data4v1 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 4", data4v1); putValue("pre:KeyB", "pre:Value A 1", data4v1); EDBObject v23 = new EDBObject("pre:/test/object4", data4v1); ci.update(v23); long time2 = db.commit(ci); Map<String, EDBObjectEntry> data1v3 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 1", data1v3); putValue("pre:KeyB", "pre:Value A 1", data1v3); EDBObject v31 = new EDBObject("pre:/test/object1", data1v3); ci = getEDBCommit(); ci.update(v31); Map<String, EDBObjectEntry> data2v3 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 2a", data2v3); putValue("pre:KeyB", "pre:Value A 1", data2v3); EDBObject v32 = new EDBObject("pre:/test/object2", data2v3); ci.update(v32); Map<String, EDBObjectEntry> data4v2 = new HashMap<String, EDBObjectEntry>(); putValue("pre:KeyA", "pre:Value A 4", data4v2); putValue("pre:KeyB", "pre:Value A 1", data4v2); EDBObject v33 = new EDBObject("pre:/test/object4", data4v2); ci.update(v33); long time3 = db.commit(ci); List<EDBObject> result = db.query(QueryRequest.query("pre:KeyB", "pre:Value A 1").setTimestamp(time2)); boolean b1 = false; boolean b2 = false; boolean b3 = false; for (EDBObject e : result) { if (e.getString("pre:KeyA").equals("pre:Value A 1")) { b1 = true; } if (e.getString("pre:KeyA").equals("pre:Value A 2")) { b2 = true; } if (e.getString("pre:KeyA").equals("pre:Value A 3")) { b3 = true; } } assertThat(b1, is(true)); assertThat(b2, is(true)); assertThat(b3, is(true)); assertThat(time1 > 0, is(true)); assertThat(time2 > 0, is(true)); assertThat(time3 > 0, is(true)); }