use of com.enonic.xp.blob.Segment in project xp by enonic.
the class VersionTableVacuumCommand method removeNodeBlobRecord.
private void removeNodeBlobRecord(final RepositoryId repositoryId, final SegmentLevel blobType, final BlobKey blobKey) {
if (LOG.isDebugEnabled()) {
LOG.debug("No other version found using " + blobType.toString() + " blob [" + blobKey + "]");
}
final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, blobType);
blobStore.removeRecord(segment, blobKey);
}
use of com.enonic.xp.blob.Segment in project xp by enonic.
the class NodeVersionServiceImplTest method getVersionCorrupted.
@Test
public void getVersionCorrupted() throws Exception {
final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
final Node createdNode = createNode(createNodeParams);
final NodeVersionKey nodeVersionKey = getNodeVersionKey(createdNode);
final Segment segment = createSegment(NODE_SEGMENT_LEVEL);
final BlobRecord blob = this.blobStore.getRecord(segment, nodeVersionKey.getNodeBlobKey());
byte[] blobData = blob.getBytes().read();
blobData = Arrays.copyOf(blobData, blobData.length / 2);
final MemoryBlobRecord corruptedBlob = new MemoryBlobRecord(blob.getKey(), ByteSource.wrap(blobData));
this.blobStore.addRecord(segment, corruptedBlob);
try {
nodeDao.get(nodeVersionKey, createInternalContext());
fail("Expected exception");
} catch (RuntimeException e) {
assertTrue(e.getMessage().startsWith("Failed to load blobs with keys"));
}
}
use of com.enonic.xp.blob.Segment in project xp by enonic.
the class NodeVersionServiceImplTest method avoidCachingVersionCorrupted.
@Test
public void avoidCachingVersionCorrupted() throws Exception {
final CachedBlobStore cachedBlobStore = CachedBlobStore.create().blobStore(this.blobStore).build();
this.nodeDao.setBlobStore(cachedBlobStore);
final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
final Node createdNode = createNode(createNodeParams);
final NodeVersionKey nodeVersionKey = getNodeVersionKey(createdNode);
final Segment segment = createSegment(NODE_SEGMENT_LEVEL);
final BlobRecord blob = this.blobStore.getRecord(segment, nodeVersionKey.getNodeBlobKey());
final byte[] blobData = blob.getBytes().read();
final byte[] blobDataTruncated = Arrays.copyOf(blobData, blobData.length / 2);
final MemoryBlobRecord corruptedBlob = new MemoryBlobRecord(blob.getKey(), ByteSource.wrap(blobDataTruncated));
this.blobStore.addRecord(segment, corruptedBlob);
cachedBlobStore.invalidate(segment, blob.getKey());
try {
nodeDao.get(nodeVersionKey, createInternalContext());
fail("Expected exception");
} catch (RuntimeException e) {
assertTrue(e.getMessage().startsWith("Failed to load blobs with keys"));
}
// restore original blob in source blob store
this.blobStore.addRecord(segment, blob);
final NodeVersion nodeVersion = nodeDao.get(nodeVersionKey, createInternalContext());
assertNotNull(nodeVersion);
}
use of com.enonic.xp.blob.Segment in project xp by enonic.
the class FileBlobStoreTest method deleteSegment.
@Test
public void deleteSegment() {
final Segment secondSegment = Segment.from("test", "blob2");
createRecord("hello").getKey();
createRecord(secondSegment, "hello").getKey();
blobStore.deleteSegment(secondSegment);
assertEquals(1, blobStore.listSegments().count());
assertEquals(segment, blobStore.listSegments().findFirst().get());
}
use of com.enonic.xp.blob.Segment in project xp by enonic.
the class BlobStoreFactoryTest method no_cache_no_provider.
@Test
public void no_cache_no_provider() throws Exception {
final MemoryBlobStore blobStore = new MemoryBlobStore();
final MemoryBlobStoreProvider memoryBlobStoreProvider = new MemoryBlobStoreProvider("memory", blobStore, createProviderConfig("none", false));
final BlobStore finalBlobStore = BlobStoreFactory.create().provider(memoryBlobStoreProvider).config(createBlobstoreConfig(false)).build().execute();
assertNotNull(finalBlobStore);
final Segment segment = Segment.from("test", "blob");
final BlobRecord record = finalBlobStore.addRecord(segment, ByteSource.wrap("hei".getBytes()));
assertEquals(finalBlobStore.getRecord(segment, record.getKey()), blobStore.getRecord(segment, record.getKey()));
}
Aggregations