use of com.enonic.xp.internal.blobstore.MemoryBlobRecord 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.internal.blobstore.MemoryBlobRecord 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);
}
Aggregations