Search in sources :

Example 11 with LogCustomizer

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();
        }
    }
}
Also used : RDBTableMetaData(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) Test(org.junit.Test)

Example 12 with LogCustomizer

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();
    }
}
Also used : RDBTableMetaData(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) Closeable(java.io.Closeable) Method(java.lang.reflect.Method) QueryCondition(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition) Test(org.junit.Test) AbstractDocumentStoreTest(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)

Example 13 with LogCustomizer

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();
    }
}
Also used : RDBTableMetaData(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) QueryCondition(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition) Test(org.junit.Test) AbstractDocumentStoreTest(org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)

Example 14 with LogCustomizer

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]");
}
Also used : PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Semaphore(java.util.concurrent.Semaphore) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProxyNodeStore(org.apache.jackrabbit.oak.spi.state.ProxyNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) AsyncIndexStats(org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats) LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) Test(org.junit.Test)

Example 15 with LogCustomizer

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;
}
Also used : LogCustomizer(org.apache.jackrabbit.oak.commons.junit.LogCustomizer)

Aggregations

LogCustomizer (org.apache.jackrabbit.oak.commons.junit.LogCustomizer)18 Test (org.junit.Test)16 MarkSweepGarbageCollector (org.apache.jackrabbit.oak.plugins.blob.MarkSweepGarbageCollector)5 RDBTableMetaData (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.RDBTableMetaData)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)4 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)4 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)4 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)4 AbstractDocumentStoreTest (org.apache.jackrabbit.oak.plugins.document.AbstractDocumentStoreTest)3 QueryCondition (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 Closeable (java.io.Closeable)2 Semaphore (java.util.concurrent.Semaphore)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)2 AsyncIndexStats (org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate.AsyncIndexStats)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1