Search in sources :

Example 1 with Segment

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

the class FileBlobStoreTest method listSegments.

@Test
public void listSegments() {
    final Segment secondSegment = Segment.from("test", "blob2");
    assertEquals(0, blobStore.listSegments().count());
    createRecord("hello").getKey();
    assertEquals(1, blobStore.listSegments().count());
    assertEquals(segment, blobStore.listSegments().findFirst().get());
    createRecord(secondSegment, "hello").getKey();
    assertEquals(2, blobStore.listSegments().count());
}
Also used : Segment(com.enonic.xp.blob.Segment) Test(org.junit.jupiter.api.Test)

Example 2 with Segment

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

the class BlobStoreFactoryTest method doTestProviderStore.

private void doTestProviderStore(final boolean cache) {
    final MemoryBlobStore memory1 = new MemoryBlobStore();
    final MemoryBlobStoreProvider provider1 = new MemoryBlobStoreProvider("memory1", memory1, createProviderConfig("memory2", true));
    final MemoryBlobStore memory2 = new MemoryBlobStore();
    final MemoryBlobStoreProvider provider2 = new MemoryBlobStoreProvider("memory2", memory2, createProviderConfig(null, false));
    final BlobStoreProviders blobStoreProviders = new BlobStoreProviders();
    blobStoreProviders.add(provider2);
    final BlobStore finalBlobStore = BlobStoreFactory.create().provider(provider1).config(createBlobstoreConfig(cache)).providers(blobStoreProviders).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()), memory1.getRecord(segment, record.getKey()));
    assertEquals(finalBlobStore.getRecord(segment, record.getKey()), memory2.getRecord(segment, record.getKey()));
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) BlobStore(com.enonic.xp.blob.BlobStore) Segment(com.enonic.xp.blob.Segment)

Example 3 with Segment

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

the class ReadThroughBlobStoreTest method invalidate.

@Test
public void invalidate() throws Exception {
    final ByteSource binary = ByteSource.wrap("this is a record".getBytes());
    final Segment segment = Segment.from("test", "blob");
    final BlobRecord record = this.finalStore.addRecord(segment, binary);
    final ReadThroughBlobStore actualBlobStore = ReadThroughBlobStore.create().readThroughStore(this.readThroughStore).store(this.finalStore).build();
    assertNull(this.readThroughStore.getRecord(segment, record.getKey()));
    actualBlobStore.getRecord(segment, record.getKey());
    assertNotNull(this.readThroughStore.getRecord(segment, record.getKey()));
    actualBlobStore.invalidate(segment, record.getKey());
    assertNull(this.readThroughStore.getRecord(segment, record.getKey()));
    assertNotNull(this.finalStore.getRecord(segment, record.getKey()));
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) ByteSource(com.google.common.io.ByteSource) Segment(com.enonic.xp.blob.Segment) Test(org.junit.jupiter.api.Test)

Example 4 with Segment

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

the class ReadThroughBlobStoreTest method stored_in_readthrough.

@Test
public void stored_in_readthrough() throws Exception {
    final ReadThroughBlobStore actualBlobStore = ReadThroughBlobStore.create().readThroughStore(this.readThroughStore).store(this.finalStore).sizeThreshold(ByteSizeParser.parse("80kb")).build();
    final ByteSource binary = ByteSource.wrap("this is a record".getBytes());
    final Segment segment = Segment.from("test", "blob");
    final BlobRecord record = actualBlobStore.addRecord(segment, binary);
    assertNotNull(this.readThroughStore.getRecord(segment, record.getKey()));
    assertNotNull(this.finalStore.getRecord(segment, record.getKey()));
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) ByteSource(com.google.common.io.ByteSource) Segment(com.enonic.xp.blob.Segment) Test(org.junit.jupiter.api.Test)

Example 5 with Segment

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

the class BinaryServiceImpl method get.

@Override
public ByteSource get(final RepositoryId repositoryId, final AttachedBinary attachedBinary) {
    final Segment segment = RepositorySegmentUtils.toSegment(repositoryId, NodeConstants.BINARY_SEGMENT_LEVEL);
    final BlobRecord record = blobStore.getRecord(segment, BlobKey.from(attachedBinary.getBlobKey()));
    if (record == null) {
        throw new RepositoryExeption("Cannot load binary with key [" + attachedBinary.getBlobKey() + "], not found");
    }
    return record.getBytes();
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) RepositoryExeption(com.enonic.xp.repository.RepositoryExeption) Segment(com.enonic.xp.blob.Segment)

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