Search in sources :

Example 11 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey 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)

Example 12 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.

the class NodeVersionServiceImplTest method store.

@Test
public void store() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addString("myName", "myValue");
    final NodeVersion nodeVersion = NodeVersion.create().nodeType(NodeType.DEFAULT_NODE_COLLECTION).id(new NodeId()).childOrder(ChildOrder.defaultOrder()).data(data).build();
    final NodeVersionKey nodeVersionKey = nodeDao.store(nodeVersion, createInternalContext());
    assertNotNull(nodeVersionKey);
    final BlobRecord nodeBlobRecord = blobStore.getRecord(createSegment(NODE_SEGMENT_LEVEL), nodeVersionKey.getNodeBlobKey());
    assertNotNull(nodeBlobRecord);
    final BlobRecord indexBlobRecord = blobStore.getRecord(createSegment(INDEX_CONFIG_SEGMENT_LEVEL), nodeVersionKey.getIndexConfigBlobKey());
    assertNotNull(indexBlobRecord);
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) BlobRecord(com.enonic.xp.blob.BlobRecord) MemoryBlobRecord(com.enonic.xp.internal.blobstore.MemoryBlobRecord) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) PropertyTree(com.enonic.xp.data.PropertyTree) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 13 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.

the class NodeStorageServiceImplTest method testGetNode_NodeVersionNotFound.

@Test
public void testGetNode_NodeVersionNotFound() {
    when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(NodeVersionMetadata.create().nodeVersionKey(versionKey).build());
    when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(null);
    final Node result = instance.getNode(nodeId, nodeVersionId, context);
    assertNull(result);
    verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
    verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
    verifyNoMoreInteractions(versionService, nodeVersionService);
}
Also used : NodeVersionId(com.enonic.xp.node.NodeVersionId) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Example 14 with NodeVersionKey

use of com.enonic.xp.blob.NodeVersionKey in project xp by enonic.

the class NodeStorageServiceImplTest method testGetNode_ByPath.

@Test
public void testGetNode_ByPath() {
    final NodeBranchEntry nodeBranchEntry = NodeBranchEntry.create().nodeId(nodeId).nodePath(nodePath).nodeState(NodeState.DEFAULT).build();
    final NodeVersionMetadata nodeVersionMetadata = NodeVersionMetadata.create().nodeVersionId(nodeVersionId).nodeVersionKey(versionKey).nodePath(nodePath).build();
    final NodeVersion nodeVersion = NodeVersion.create().permissions(AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()).build();
    when(branchService.get(any(NodePath.class), any(InternalContext.class))).thenReturn(nodeBranchEntry);
    when(versionService.getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class))).thenReturn(nodeVersionMetadata);
    when(nodeVersionService.get(any(NodeVersionKey.class), any(InternalContext.class))).thenReturn(nodeVersion);
    final Node result = instance.getNode(nodePath, nodeVersionId, context);
    assertNotNull(result);
    verify(branchService, times(1)).get(any(NodePath.class), any(InternalContext.class));
    verify(versionService, times(1)).getVersion(any(NodeId.class), any(NodeVersionId.class), any(InternalContext.class));
    verify(nodeVersionService, times(1)).get(any(NodeVersionKey.class), any(InternalContext.class));
    verifyNoMoreInteractions(branchService, versionService, nodeVersionService);
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeVersionKey(com.enonic.xp.blob.NodeVersionKey) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Aggregations

NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)14 NodeVersionId (com.enonic.xp.node.NodeVersionId)7 Node (com.enonic.xp.node.Node)6 Test (org.junit.jupiter.api.Test)6 NodeVersion (com.enonic.xp.node.NodeVersion)5 NodeId (com.enonic.xp.node.NodeId)4 RoutableNodeVersionId (com.enonic.xp.node.RoutableNodeVersionId)4 BlobRecord (com.enonic.xp.blob.BlobRecord)3 MemoryBlobRecord (com.enonic.xp.internal.blobstore.MemoryBlobRecord)3 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)3 InternalContext (com.enonic.xp.repo.impl.InternalContext)3 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)3 BlobKeys (com.enonic.xp.blob.BlobKeys)2 Segment (com.enonic.xp.blob.Segment)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 NodePath (com.enonic.xp.node.NodePath)2 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)2 ReturnValue (com.enonic.xp.repo.impl.ReturnValue)2 PropertyTree (com.enonic.xp.data.PropertyTree)1 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1