use of org.apache.jackrabbit.oak.api.blob.BlobAccessProvider in project jackrabbit-oak by apache.
the class BlobGCTest method setupDirectBinary.
protected void setupDirectBinary(int numCreate, int numDelete) throws CommitFailedException {
for (int i = 0; i < numCreate; i++) {
BlobUpload blobUpload = ((BlobAccessProvider) cluster.blobStore).initiateBlobUpload(100, 1);
Blob blob = ((BlobAccessProvider) cluster.blobStore).completeBlobUpload(blobUpload.getUploadToken());
cluster.blobStoreState.blobsAdded.add(blob.getContentIdentity());
cluster.blobStoreState.blobsPresent.add(blob.getContentIdentity());
NodeBuilder builder = cluster.nodeStore.getRoot().builder();
builder.child("dbu" + i).setProperty("x", blob);
cluster.nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
PropertyState property = cluster.nodeStore.getRoot().getChildNode("dbu" + i).getProperty("x");
Blob blobReturned = property.getValue(Type.BINARY);
((MemoryBlobStoreNodeStore) cluster.nodeStore).getReferencedBlobs().add(blobReturned.getContentIdentity());
}
for (int i = 0; i < Math.min(numCreate, numDelete); i++) {
PropertyState property = cluster.nodeStore.getRoot().getChildNode("dbu" + i).getProperty("x");
String blobId = property.getValue(Type.BINARY).getContentIdentity();
delete("dbu" + i, cluster.nodeStore);
((MemoryBlobStoreNodeStore) cluster.nodeStore).getReferencedBlobs().remove(blobId);
cluster.blobStoreState.blobsPresent.remove(blobId);
}
}
use of org.apache.jackrabbit.oak.api.blob.BlobAccessProvider 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);
}
Oak oak = newOak(builder.build());
if (blobStore instanceof BlobAccessProvider) {
oak.getWhiteboard().register(BlobAccessProvider.class, (BlobAccessProvider) blobStore, Collections.EMPTY_MAP);
}
return oak;
}
@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).setLeaseCheckMode(LeaseCheckMode.DISABLED).setClusterId(i + 1).setLogging(false);
if (blobStore != null) {
builder.setBlobStore(blobStore);
}
nodeStores[i] = builder.build();
cluster[i] = newOak(nodeStores[i]);
if (blobStore instanceof BlobAccessProvider) {
cluster[i].getWhiteboard().register(BlobAccessProvider.class, (BlobAccessProvider) blobStore, Collections.EMPTY_MAP);
}
}
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.api.blob.BlobAccessProvider in project jackrabbit-oak by apache.
the class UserConfigurationImpl method getBlobAccessProvider.
@NotNull
private BlobAccessProvider getBlobAccessProvider() {
BlobAccessProvider provider = blobAccessProvider;
if (provider == null) {
SecurityProvider securityProvider = getSecurityProvider();
if (securityProvider instanceof WhiteboardAware) {
Whiteboard wb = ((WhiteboardAware) securityProvider).getWhiteboard();
if (wb != null) {
provider = WhiteboardUtils.getService(wb, BlobAccessProvider.class);
}
}
}
if (provider == null) {
provider = DEFAULT_BLOB_ACCESS_PROVIDER;
}
blobAccessProvider = provider;
return provider;
}
use of org.apache.jackrabbit.oak.api.blob.BlobAccessProvider in project jackrabbit-oak by apache.
the class UserConfigurationImplOSGiTest method testBindBlobAccessProvider.
@Test
public void testBindBlobAccessProvider() throws Exception {
UserConfigurationImpl uc = new UserConfigurationImpl(getSecurityProvider());
context.registerInjectActivateService(uc, ImmutableMap.of(PARAM_DEFAULT_DEPTH, "8"));
BlobAccessProvider bap = mock(BlobAccessProvider.class);
uc.getUserManager(root, getNamePathMapper());
Field f = UserConfigurationImpl.class.getDeclaredField("blobAccessProvider");
f.setAccessible(true);
// Validate default service
assertSame(PartialValueFactory.DEFAULT_BLOB_ACCESS_PROVIDER, f.get(uc));
ServiceRegistration reg = context.bundleContext().registerService(BlobAccessProvider.class.getName(), bap, new Hashtable<String, Object>());
// Validate newly registered service
assertSame(bap, f.get(uc));
reg.unregister();
// Validate default service after unregistering newly registered service
assertSame(PartialValueFactory.DEFAULT_BLOB_ACCESS_PROVIDER, f.get(uc));
}
use of org.apache.jackrabbit.oak.api.blob.BlobAccessProvider in project jackrabbit-oak by apache.
the class AbstractBinaryAccessIT method createRepository.
/**
* Adjust JCR repository creation to register BlobAccessProvider (BlobStore) in Whiteboard
* so it can be picked up by oak-jcr.
*/
@Override
protected Repository createRepository(NodeStore nodeStore) {
Whiteboard wb = new DefaultWhiteboard();
BlobStore blobStore = getNodeStoreComponent(BlobStore.class);
if (blobStore != null && blobStore instanceof BlobAccessProvider) {
wb.register(BlobAccessProvider.class, (BlobAccessProvider) blobStore, Collections.emptyMap());
}
return initJcr(new Jcr(nodeStore).with(wb)).createRepository();
}
Aggregations