Search in sources :

Example 1 with MemoryBlobRecord

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"));
    }
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Segment(com.enonic.xp.blob.Segment) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 2 with MemoryBlobRecord

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);
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) NodeVersion(com.enonic.xp.node.NodeVersion) CachedBlobStore(com.enonic.xp.internal.blobstore.cache.CachedBlobStore) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Segment(com.enonic.xp.blob.Segment) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

BlobRecord (com.enonic.xp.blob.BlobRecord)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 Segment (com.enonic.xp.blob.Segment)2 MemoryBlobRecord (com.enonic.xp.internal.blobstore.MemoryBlobRecord)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 Node (com.enonic.xp.node.Node)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 Test (org.junit.jupiter.api.Test)2 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1 NodeVersion (com.enonic.xp.node.NodeVersion)1