Search in sources :

Example 1 with RDBOptions

use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions in project jackrabbit-oak by apache.

the class DocumentRdbFixture method createNodeStore.

@Override
public NodeStore createNodeStore() {
    String prefix = "T" + Long.toHexString(System.currentTimeMillis());
    RDBOptions options = new RDBOptions().tablePrefix(prefix).dropTablesOnClose(true);
    this.jdbcUrl = pUrl.replace("{fname}", fname);
    DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcUrl, pUser, pPasswd);
    NodeStore result = new DocumentMK.Builder().setPersistentCache("target/persistentCache,time").setRDBConnection(ds, options).getNodeStore();
    this.dataSources.put(result, ds);
    return result;
}
Also used : DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) RDBOptions(org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions) DataSource(javax.sql.DataSource)

Example 2 with RDBOptions

use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions in project jackrabbit-oak by apache.

the class OakFixture method getRDB.

public static OakFixture getRDB(final String name, final String jdbcuri, final String jdbcuser, final String jdbcpasswd, final String tablePrefix, final boolean dropDBAfterTest, final long cacheSize, final boolean useDataStore, final File base, final int dsCacheInMB, final int vgcMaxAge) {
    return new OakFixture(name) {

        private DocumentNodeStore[] nodeStores;

        private VersionGarbageCollectionJob versionGarbageCollectionJob = null;

        private BlobStoreFixture blobStoreFixture;

        private RDBOptions getOptions(boolean dropDBAFterTest, String tablePrefix) {
            return new RDBOptions().dropTablesOnClose(dropDBAfterTest).tablePrefix(tablePrefix);
        }

        private BlobStore getBlobStore(StatisticsProvider statsProvider) {
            try {
                if (useDataStore) {
                    initializeBlobStoreFixture(statsProvider);
                    return blobStoreFixture.setUp();
                } else {
                    DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
                    return new RDBBlobStore(ds, getOptions(dropDBAfterTest, tablePrefix));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public Oak getOak(int clusterId) throws Exception {
            DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
            DocumentNodeStoreBuilder<?> builder = newRDBDocumentNodeStoreBuilder().setRDBConnection(ds, getOptions(dropDBAfterTest, tablePrefix)).memoryCacheSize(cacheSize).setClusterId(clusterId).setLogging(false);
            BlobStore blobStore = getBlobStore(StatisticsProvider.NOOP);
            if (blobStore != null) {
                builder.setBlobStore(blobStore);
            }
            return newOak(builder.build());
        }

        @Override
        public Oak[] setUpCluster(int n, StatisticsProvider statsProvider) throws Exception {
            Oak[] cluster = new Oak[n];
            nodeStores = new DocumentNodeStore[cluster.length];
            for (int i = 0; i < cluster.length; i++) {
                BlobStore blobStore = getBlobStore(statsProvider);
                DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
                DocumentNodeStoreBuilder<?> builder = newRDBDocumentNodeStoreBuilder().setRDBConnection(ds, getOptions(dropDBAfterTest, tablePrefix)).memoryCacheSize(cacheSize).setStatisticsProvider(statsProvider).setLeaseCheck(false).setClusterId(i + 1).setLogging(false);
                if (blobStore != null) {
                    builder.setBlobStore(blobStore);
                }
                nodeStores[i] = builder.build();
                cluster[i] = newOak(nodeStores[i]);
            }
            if (vgcMaxAge > 0 && nodeStores.length >= 1) {
                versionGarbageCollectionJob = new VersionGarbageCollectionJob(nodeStores[0], vgcMaxAge);
                Thread t = new Thread(versionGarbageCollectionJob);
                t.setDaemon(true);
                t.start();
            }
            return cluster;
        }

        @Override
        public void tearDownCluster() {
            String dropped = "";
            if (versionGarbageCollectionJob != null) {
                versionGarbageCollectionJob.stop();
            }
            for (DocumentNodeStore ns : nodeStores) {
                ns.dispose();
                if (ns.getDocumentStore() instanceof RDBDocumentStore) {
                    dropped += ((RDBDocumentStore) ns.getDocumentStore()).getDroppedTables();
                }
            }
            if (dropDBAfterTest) {
                if (blobStoreFixture != null) {
                    blobStoreFixture.tearDown();
                }
                if (dropped.isEmpty()) {
                    throw new RuntimeException("dropdb was set, but tables have not been dropped");
                }
            }
        }

        private void initializeBlobStoreFixture(StatisticsProvider statsProvider) {
            if (useDataStore && blobStoreFixture == null) {
                blobStoreFixture = BlobStoreFixture.create(base, true, dsCacheInMB, statsProvider);
            }
        }
    };
}
Also used : DocumentNodeStore(org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) RDBOptions(org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions) UnknownHostException(java.net.UnknownHostException) DataSource(javax.sql.DataSource) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) Oak(org.apache.jackrabbit.oak.Oak) RDBBlobStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore) RDBBlobStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore)

Example 3 with RDBOptions

use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions in project jackrabbit-oak by apache.

the class AbstractRDBConnectionTest method newBuilder.

protected DocumentMK.Builder newBuilder(DataSource db) throws Exception {
    String prefix = "T" + Long.toHexString(System.currentTimeMillis());
    RDBOptions opt = new RDBOptions().tablePrefix(prefix).dropTablesOnClose(true);
    return new DocumentMK.Builder().clock(getTestClock()).setRDBConnection(dataSource, opt);
}
Also used : RDBOptions(org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions)

Example 4 with RDBOptions

use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions in project jackrabbit-oak by apache.

the class CacheConsistencyRDBTest method setUpConnection.

@Before
@Override
public void setUpConnection() throws Exception {
    dataSource = RDBDataSourceFactory.forJdbcUrl(URL, USERNAME, PASSWD);
    DocumentMK.Builder builder = new DocumentMK.Builder().clock(getTestClock()).setAsyncDelay(0);
    RDBOptions opt = new RDBOptions().tablePrefix("T" + Long.toHexString(System.currentTimeMillis())).dropTablesOnClose(true);
    store = new TestStore(dataSource, builder, opt);
    mk = builder.setDocumentStore(store).setLeaseCheck(false).open();
}
Also used : Builder(org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder) Builder(org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder) RDBOptions(org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions) Before(org.junit.Before)

Aggregations

RDBOptions (org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions)4 DataSource (javax.sql.DataSource)2 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)2 UnknownHostException (java.net.UnknownHostException)1 Oak (org.apache.jackrabbit.oak.Oak)1 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)1 Builder (org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder)1 RDBBlobStore (org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore)1 RDBDocumentStore (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore)1 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)1 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)1 StatisticsProvider (org.apache.jackrabbit.oak.stats.StatisticsProvider)1 Before (org.junit.Before)1