use of org.apache.jackrabbit.oak.plugins.document.DocumentStore in project jackrabbit-oak by apache.
the class MongoCacheConsistencyTest method getFixture.
@Override
public DocumentStoreFixture getFixture() throws Exception {
Fongo fongo = new OakFongo("fongo") {
private String suppressedEx = null;
@Override
protected void afterInsert(WriteResult result) {
maybeThrow();
}
@Override
protected void afterFindAndModify(DBObject result) {
maybeThrow();
}
@Override
protected void afterUpdate(WriteResult result) {
maybeThrow();
}
@Override
protected void afterRemove(WriteResult result) {
maybeThrow();
}
@Override
protected void beforeExecuteBulkWriteOperation(boolean ordered, Boolean bypassDocumentValidation, List<?> writeRequests, WriteConcern aWriteConcern) {
// suppress potentially set exception message because
// fongo bulk writes call other update methods
suppressedEx = exceptionMsg;
exceptionMsg = null;
}
@Override
protected void afterExecuteBulkWriteOperation(BulkWriteResult result) {
exceptionMsg = suppressedEx;
suppressedEx = null;
maybeThrow();
}
private void maybeThrow() {
if (exceptionMsg != null) {
throw new MongoException(exceptionMsg);
}
}
};
DocumentMK.Builder builder = provider.newBuilder().setAsyncDelay(0);
final DocumentStore store = new MongoDocumentStore(fongo.getDB("oak"), builder);
return new DocumentStoreFixture() {
@Override
public String getName() {
return "MongoDB";
}
@Override
public DocumentStore createDocumentStore(int clusterId) {
return store;
}
};
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentStore in project jackrabbit-oak by apache.
the class JournalIT method cacheInvalidationTest.
@Test
public void cacheInvalidationTest() throws Exception {
final DocumentNodeStore ns1 = createMK(1, 0).getNodeStore();
final DocumentNodeStore ns2 = createMK(2, 0).getNodeStore();
LOG.info("cache size 1: " + getCacheElementCount(ns1.getDocumentStore()));
// invalidate cache under test first
ns1.getDocumentStore().invalidateCache();
{
DocumentStore s = ns1.getDocumentStore();
LOG.info("m.size=" + getCacheElementCount(s));
}
LOG.info("cache size 2: " + getCacheElementCount(ns1.getDocumentStore()));
// first create child node in instance 1
final List<String> paths = createRandomPaths(1, 5000000, 1000);
int i = 0;
for (String path : paths) {
if (i++ % 100 == 0) {
LOG.info("at " + i);
}
getOrCreate(ns1, path, false);
}
final List<String> paths2 = createRandomPaths(20, 2345, 100);
getOrCreate(ns1, paths2, false);
ns1.runBackgroundOperations();
for (String path : paths) {
assertDocCache(ns1, true, path);
}
{
DocumentStore s = ns1.getDocumentStore();
LOG.info("m.size=" + getCacheElementCount(s));
}
LOG.info("cache size 2: " + getCacheElementCount(ns1.getDocumentStore()));
long time = System.currentTimeMillis();
for (int j = 0; j < 100; j++) {
long now = System.currentTimeMillis();
LOG.info("loop " + j + ", " + (now - time) + "ms");
time = now;
final Set<String> electedPaths = choose(paths2, random.nextInt(30));
{
// choose a random few from above created paths and modify them
final long t1 = System.currentTimeMillis();
// make sure ns2 has the latest from ns1
ns2.runBackgroundOperations();
final long t2 = System.currentTimeMillis();
LOG.info("ns2 background took " + (t2 - t1) + "ms");
for (String electedPath : electedPaths) {
// modify /child in another instance 2
setProperty(ns2, electedPath, "p", "ns2" + System.currentTimeMillis(), false);
}
final long t3 = System.currentTimeMillis();
LOG.info("setting props " + (t3 - t2) + "ms");
ns2.runBackgroundOperations();
final long t4 = System.currentTimeMillis();
LOG.info("ns2 background took2 " + (t4 - t3) + "ms");
}
// that should not have changed the fact that we have it cached in 'ns1'
for (String electedPath : electedPaths) {
assertDocCache(ns1, true, electedPath);
}
// doing a backgroundOp now should trigger invalidation
// which thx to the external modification will remove the entry from the cache:
ns1.runBackgroundOperations();
for (String electedPath : electedPaths) {
assertDocCache(ns1, false, electedPath);
}
// when I access it again with 'ns1', then it gets cached again:
for (String electedPath : electedPaths) {
getOrCreate(ns1, electedPath, false);
assertDocCache(ns1, true, electedPath);
}
}
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentStore in project jackrabbit-oak by apache.
the class ReadOnlyDocumentStoreWrapperTest method testPassthrough.
@Test
public void testPassthrough() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
final List<String> disallowedMethods = Lists.newArrayList("create", "update", "remove", "createOrUpdate", "findAndUpdate");
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (disallowedMethods.contains(methodName)) {
Assert.fail(String.format("Invalid passthrough of method (%s) with params %s", method, Arrays.toString(args)));
}
if ("determineServerTimeDifferenceMillis".equals(methodName)) {
return new Long(0);
} else {
return null;
}
}
};
DocumentStore proxyStore = (DocumentStore) Proxy.newProxyInstance(DocumentStore.class.getClassLoader(), new Class[] { DocumentStore.class }, handler);
DocumentStore readOnlyStore = ReadOnlyDocumentStoreWrapperFactory.getInstance(proxyStore);
Collection<? extends Document>[] collections = new Collection[] { Collection.CLUSTER_NODES, Collection.JOURNAL, Collection.NODES, Collection.SETTINGS };
for (Collection collection : collections) {
readOnlyStore.find(collection, null);
readOnlyStore.find(collection, null, 0);
readOnlyStore.query(collection, null, null, 0);
readOnlyStore.query(collection, null, null, null, 0, 0);
boolean uoeThrown = false;
try {
readOnlyStore.remove(collection, "");
} catch (UnsupportedOperationException uoe) {
//catch uoe thrown by read only wrapper
uoeThrown = true;
}
assertTrue("remove must throw UnsupportedOperationException", uoeThrown);
uoeThrown = false;
try {
readOnlyStore.remove(collection, Lists.<String>newArrayList());
} catch (UnsupportedOperationException uoe) {
//catch uoe thrown by read only wrapper
uoeThrown = true;
}
assertTrue("remove must throw UnsupportedOperationException", uoeThrown);
uoeThrown = false;
try {
readOnlyStore.remove(collection, Maps.<String, Map<UpdateOp.Key, UpdateOp.Condition>>newHashMap());
} catch (UnsupportedOperationException uoe) {
//catch uoe thrown by read only wrapper
uoeThrown = true;
}
assertTrue("remove must throw UnsupportedOperationException", uoeThrown);
uoeThrown = false;
try {
readOnlyStore.create(collection, null);
} catch (UnsupportedOperationException uoe) {
//catch uoe thrown by read only wrapper
uoeThrown = true;
}
assertTrue("create must throw UnsupportedOperationException", uoeThrown);
uoeThrown = false;
try {
readOnlyStore.update(collection, null, null);
} catch (UnsupportedOperationException uoe) {
//catch uoe thrown by read only wrapper
uoeThrown = true;
}
assertTrue("update must throw UnsupportedOperationException", uoeThrown);
uoeThrown = false;
try {
readOnlyStore.createOrUpdate(collection, (UpdateOp) null);
} catch (UnsupportedOperationException uoe) {
//catch uoe thrown by read only wrapper
uoeThrown = true;
}
assertTrue("createOrUpdate must throw UnsupportedOperationException", uoeThrown);
uoeThrown = false;
try {
readOnlyStore.createOrUpdate(collection, Lists.<UpdateOp>newArrayList());
} catch (UnsupportedOperationException uoe) {
//catch uoe thrown by read only wrapper
uoeThrown = true;
}
assertTrue("createOrUpdate must throw UnsupportedOperationException", uoeThrown);
uoeThrown = false;
try {
readOnlyStore.findAndUpdate(collection, null);
} catch (UnsupportedOperationException uoe) {
//catch uoe thrown by read only wrapper
uoeThrown = true;
}
assertTrue("findAndUpdate must throw UnsupportedOperationException", uoeThrown);
readOnlyStore.invalidateCache(collection, null);
readOnlyStore.getIfCached(collection, null);
}
readOnlyStore.invalidateCache();
readOnlyStore.invalidateCache(null);
readOnlyStore.dispose();
readOnlyStore.setReadWriteMode(null);
readOnlyStore.getCacheStats();
readOnlyStore.getMetadata();
readOnlyStore.determineServerTimeDifferenceMillis();
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentStore in project jackrabbit-oak by apache.
the class TimingDocumentStoreWrapperTest method createOrUpdate.
@Test
public void createOrUpdate() {
DocumentStore store = new TimingDocumentStoreWrapper(new MemoryDocumentStore());
UpdateOp op = new UpdateOp("foo", true);
store.createOrUpdate(Collection.NODES, Collections.singletonList(op));
}
use of org.apache.jackrabbit.oak.plugins.document.DocumentStore in project jackrabbit-oak by apache.
the class ReadOnlyDocumentStoreWrapperTest method backgroundRead.
@Test
public void backgroundRead() throws Exception {
DocumentStore docStore = new MemoryDocumentStore();
DocumentNodeStore store = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(docStore).setClusterId(2).getNodeStore();
DocumentNodeStore readOnlyStore = builderProvider.newBuilder().setAsyncDelay(0).setDocumentStore(docStore).setClusterId(1).setReadOnlyMode().getNodeStore();
NodeBuilder builder = store.getRoot().builder();
builder.child("node");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
store.runBackgroundOperations();
// at this point node must not be visible
assertFalse(readOnlyStore.getRoot().hasChildNode("node"));
readOnlyStore.runBackgroundOperations();
// at this point node should get visible
assertTrue(readOnlyStore.getRoot().hasChildNode("node"));
}
Aggregations