Search in sources :

Example 16 with Segment

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);
}
Also used : Segment(com.enonic.xp.blob.Segment)

Example 17 with Segment

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"));
    }
}
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 18 with Segment

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);
}
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 19 with Segment

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());
}
Also used : Segment(com.enonic.xp.blob.Segment) Test(org.junit.jupiter.api.Test)

Example 20 with Segment

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()));
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) BlobStore(com.enonic.xp.blob.BlobStore) Segment(com.enonic.xp.blob.Segment) Test(org.junit.jupiter.api.Test)

Aggregations

Segment (com.enonic.xp.blob.Segment)28 BlobRecord (com.enonic.xp.blob.BlobRecord)20 Test (org.junit.jupiter.api.Test)15 ByteSource (com.google.common.io.ByteSource)11 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)3 BlobStore (com.enonic.xp.blob.BlobStore)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 MemoryBlobRecord (com.enonic.xp.internal.blobstore.MemoryBlobRecord)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 Node (com.enonic.xp.node.Node)2 RepoDumpException (com.enonic.xp.repo.impl.dump.RepoDumpException)2 RepoLoadException (com.enonic.xp.repo.impl.dump.RepoLoadException)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 BlobKey (com.enonic.xp.blob.BlobKey)1 CachingBlobStore (com.enonic.xp.blob.CachingBlobStore)1 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 Pre4NodeVersionJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4NodeVersionJson)1 RepositoryExeption (com.enonic.xp.repository.RepositoryExeption)1