use of org.apache.jackrabbit.oak.commons.junit.LogCustomizer in project jackrabbit-oak by apache.
the class RDBDocumentStoreSchemaUpgradeTest method init11.
@Test
public void init11() {
LogCustomizer logCustomizer = LogCustomizer.forLogger(RDBDocumentStore.class.getName()).enable(Level.INFO).contains("to DB level 1").create();
logCustomizer.starting();
RDBOptions op = new RDBOptions().tablePrefix("T11").initialSchema(1).upgradeToSchema(1).dropTablesOnClose(true);
RDBDocumentStore rdb = null;
try {
rdb = new RDBDocumentStore(this.ds, new DocumentMK.Builder(), op);
RDBTableMetaData meta = rdb.getTable(Collection.NODES);
assertEquals(op.getTablePrefix() + "_NODES", meta.getName());
assertTrue(meta.hasVersion());
assertEquals("unexpected # of log entries: " + logCustomizer.getLogs(), 0, logCustomizer.getLogs().size());
} finally {
logCustomizer.finished();
if (rdb != null) {
rdb.dispose();
}
}
}
use of org.apache.jackrabbit.oak.commons.junit.LogCustomizer in project jackrabbit-oak by apache.
the class RDBDocumentStoreJDBCTest method queryIteratorNotConsumedTest.
@Test
public void queryIteratorNotConsumedTest() throws SQLException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
LogCustomizer customLogs = LogCustomizer.forLogger(RDBDocumentStoreJDBC.class.getName()).enable(Level.DEBUG).contains("finalizing unclosed").create();
customLogs.starting();
insertTestResource(this.getClass().getName() + "." + name.getMethodName());
MyConnectionHandler ch = new MyConnectionHandler(super.rdbDataSource);
RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES);
List<QueryCondition> conditions = Collections.emptyList();
Iterator<RDBRow> qi = jdbc.queryAsIterator(ch, tmd, null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions, Integer.MAX_VALUE, null);
assertTrue(qi instanceof Closeable);
assertEquals(1, ch.cnt.get());
Method fin = qi.getClass().getDeclaredMethod("finalize");
try {
fin.setAccessible(true);
fin.invoke(qi);
assertTrue("finalizing non-consumed iterator should generate log entry", customLogs.getLogs().size() >= 1);
} finally {
Utils.closeIfCloseable(qi);
fin.setAccessible(false);
customLogs.finished();
}
}
use of org.apache.jackrabbit.oak.commons.junit.LogCustomizer in project jackrabbit-oak by apache.
the class RDBDocumentStoreJDBCTest method queryMinLastModifiedTest.
@Test
public void queryMinLastModifiedTest() throws SQLException {
String baseName = this.getClass().getName() + "." + name.getMethodName();
long magicValue = (long) (Math.random() * 100000);
String baseNameNullModified = baseName + "-1";
super.ds.remove(Collection.NODES, baseNameNullModified);
UpdateOp op = new UpdateOp(baseNameNullModified, true);
op.set(RDBDocumentStore.COLLISIONSMODCOUNT, magicValue);
op.set(NodeDocument.DELETED_ONCE, true);
assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
removeMe.add(baseNameNullModified);
String baseName10Modified = baseName + "-2";
super.ds.remove(Collection.NODES, baseName10Modified);
op = new UpdateOp(baseName10Modified, true);
op.set(RDBDocumentStore.COLLISIONSMODCOUNT, magicValue);
op.set(NodeDocument.MODIFIED_IN_SECS, 10);
op.set(NodeDocument.DELETED_ONCE, true);
assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
removeMe.add(baseName10Modified);
String baseName20Modified = baseName + "-3";
super.ds.remove(Collection.NODES, baseName20Modified);
op = new UpdateOp(baseName20Modified, true);
op.set(RDBDocumentStore.COLLISIONSMODCOUNT, magicValue);
op.set(NodeDocument.MODIFIED_IN_SECS, 20);
op.set(NodeDocument.DELETED_ONCE, true);
assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
removeMe.add(baseName20Modified);
String baseName5ModifiedNoDeletedOnce = baseName + "-4";
super.ds.remove(Collection.NODES, baseName5ModifiedNoDeletedOnce);
op = new UpdateOp(baseName5ModifiedNoDeletedOnce, true);
op.set(RDBDocumentStore.COLLISIONSMODCOUNT, magicValue);
op.set(NodeDocument.MODIFIED_IN_SECS, 5);
assertTrue(super.ds.create(Collection.NODES, Collections.singletonList(op)));
removeMe.add(baseName5ModifiedNoDeletedOnce);
LogCustomizer customLogs = LogCustomizer.forLogger(RDBDocumentStoreJDBC.class.getName()).enable(Level.DEBUG).contains("Aggregate query").contains("min(MODIFIED)").create();
customLogs.starting();
Connection con = super.rdbDataSource.getConnection();
try {
con.setReadOnly(true);
RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES);
List<QueryCondition> conditions = new ArrayList<QueryCondition>();
conditions.add(new QueryCondition(RDBDocumentStore.COLLISIONSMODCOUNT, "=", magicValue));
long min = jdbc.getLong(con, tmd, "min", "_modified", null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions);
assertEquals(5, min);
con.commit();
} finally {
con.close();
assertEquals("should have a DEBUG level log entry", 1, customLogs.getLogs().size());
customLogs.finished();
customLogs = null;
}
con = super.rdbDataSource.getConnection();
try {
con.setReadOnly(true);
RDBTableMetaData tmd = ((RDBDocumentStore) super.ds).getTable(Collection.NODES);
List<QueryCondition> conditions = new ArrayList<QueryCondition>();
conditions.add(new QueryCondition(RDBDocumentStore.COLLISIONSMODCOUNT, "=", magicValue));
conditions.add(new QueryCondition(NodeDocument.DELETED_ONCE, "=", 1));
long min = jdbc.getLong(con, tmd, "min", "_modified", null, null, RDBDocumentStore.EMPTY_KEY_PATTERN, conditions);
assertEquals(10, min);
con.commit();
} finally {
con.close();
}
}
use of org.apache.jackrabbit.oak.commons.junit.LogCustomizer in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method closeWithSoftLimit.
@Test
public void closeWithSoftLimit() throws Exception {
NodeStore store = new MemoryNodeStore();
IndexEditorProvider provider = new PropertyIndexEditorProvider();
NodeBuilder builder = store.getRoot().builder();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null).setProperty(ASYNC_PROPERTY_NAME, "async");
builder.child("testRoot").setProperty("foo", "abc");
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
final Semaphore asyncLock = new Semaphore(1);
final AsyncIndexUpdate async = new AsyncIndexUpdate("async", store, provider) {
@Override
protected AsyncUpdateCallback newAsyncUpdateCallback(NodeStore store, String name, long leaseTimeOut, String beforeCheckpoint, AsyncIndexStats indexStats, AtomicBoolean stopFlag) {
try {
asyncLock.acquire();
} catch (InterruptedException ignore) {
}
return super.newAsyncUpdateCallback(store, name, leaseTimeOut, beforeCheckpoint, indexStats, stopFlag);
}
};
async.setCloseTimeOut(1000);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
async.run();
}
});
Thread closer = new Thread(new Runnable() {
@Override
public void run() {
async.close();
}
});
asyncLock.acquire();
t.start();
//Wait till async gets to wait state i.e. inside run
while (!asyncLock.hasQueuedThreads()) ;
LogCustomizer lc = createLogCustomizer(Level.DEBUG);
closer.start();
//Wait till closer is in waiting state
while (!async.isClosing()) ;
//For softLimit case the flag should not be set
assertFalse(async.isClosed());
assertLogPhrase(lc.getLogs(), "[WAITING]");
//Let indexing run complete now
asyncLock.release();
//Wait for both threads
t.join();
closer.join();
//Close call should complete
assertLogPhrase(lc.getLogs(), "[CLOSED OK]");
}
use of org.apache.jackrabbit.oak.commons.junit.LogCustomizer in project jackrabbit-oak by apache.
the class AsyncIndexUpdateTest method createLogCustomizer.
private static LogCustomizer createLogCustomizer(Level level) {
LogCustomizer lc = LogCustomizer.forLogger(AsyncIndexUpdate.class.getName()).filter(level).enable(level).create();
lc.starting();
return lc;
}
Aggregations