use of com.mongodb.ReadPreference in project jackrabbit-oak by apache.
the class ReadPreferenceIT method testMongoReadPreferencesForLocalChanges.
@Test
public void testMongoReadPreferencesForLocalChanges() throws Exception {
//Change the default
ReadPreference testPref = ReadPreference.secondary();
mongoDS.getDBCollection(NODES).getDB().setReadPreference(testPref);
NodeStore nodeStore = mk.getNodeStore();
NodeBuilder b1 = nodeStore.getRoot().builder();
b1.child("x").child("y");
nodeStore.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
mongoDS.invalidateCache();
// the local change hasn't been replicated yet, primary must be used
assertEquals(ReadPreference.primary(), mongoDS.getMongoReadPreference(NODES, null, "/x/y", DocumentReadPreference.PREFER_SECONDARY_IF_OLD_ENOUGH));
// make the secondary up-to-date
long now = Revision.getCurrentTimestamp();
primary.addRevision(now, 0, 1, false);
primary.addRevision(now, 0, 2, false);
secondary.addRevision(now, 0, 1, false);
secondary.addRevision(now, 0, 2, false);
replica.updateRevisions();
// local change has been replicated by now, it's fine to use secondary
for (int i = 0; i < 400; i++) {
assertEquals(testPref, mongoDS.getMongoReadPreference(NODES, null, "/x/y", DocumentReadPreference.PREFER_SECONDARY_IF_OLD_ENOUGH));
Thread.sleep(5);
}
}
Aggregations