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;
}
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);
}
}
};
}
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);
}
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();
}
Aggregations