Search in sources :

Example 11 with BlobRecord

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

the class CachedBlobStoreTest method invalidate.

@Test
public void invalidate() throws Exception {
    final BlobRecord record = newRecord("0123", 10L);
    Mockito.when(this.blobStore.getRecord(segment, record.getKey())).thenReturn(record);
    this.cachedBlobStore.getRecord(this.segment, record.getKey());
    this.cachedBlobStore.getRecord(this.segment, record.getKey());
    this.cachedBlobStore.getRecord(this.segment, record.getKey());
    Mockito.verify(this.blobStore, Mockito.times(1)).getRecord(segment, record.getKey());
    this.cachedBlobStore.invalidate(this.segment, record.getKey());
    this.cachedBlobStore.getRecord(this.segment, record.getKey());
    Mockito.verify(this.blobStore, Mockito.times(2)).getRecord(segment, record.getKey());
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) Test(org.junit.jupiter.api.Test)

Example 12 with BlobRecord

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

the class CachedBlobStoreTest method addSmallRecord.

@Test
public void addSmallRecord() {
    final BlobRecord record = newRecord("0123", 10L);
    final ByteSource byteSource = ByteSource.wrap("0123".getBytes());
    Mockito.when(this.blobStore.getRecord(segment, record.getKey())).thenReturn(record);
    Mockito.when(this.blobStore.addRecord(segment, byteSource)).thenReturn(record);
    final BlobRecord result1 = this.cachedBlobStore.addRecord(segment, byteSource);
    assertNotNull(result1);
    final BlobRecord result2 = this.cachedBlobStore.getRecord(segment, record.getKey());
    assertNotNull(result2);
    Mockito.verify(this.blobStore, Mockito.times(0)).getRecord(segment, record.getKey());
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) ByteSource(com.google.common.io.ByteSource) Test(org.junit.jupiter.api.Test)

Example 13 with BlobRecord

use of com.enonic.xp.blob.BlobRecord 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 14 with BlobRecord

use of com.enonic.xp.blob.BlobRecord 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 15 with BlobRecord

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

BlobRecord (com.enonic.xp.blob.BlobRecord)39 Test (org.junit.jupiter.api.Test)27 Segment (com.enonic.xp.blob.Segment)20 ByteSource (com.google.common.io.ByteSource)14 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)3 MemoryBlobRecord (com.enonic.xp.internal.blobstore.MemoryBlobRecord)3 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)3 BlobStore (com.enonic.xp.blob.BlobStore)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 Node (com.enonic.xp.node.Node)2 NodeVersion (com.enonic.xp.node.NodeVersion)2 RepoDumpException (com.enonic.xp.repo.impl.dump.RepoDumpException)2 BlobKey (com.enonic.xp.blob.BlobKey)1 CachingBlobStore (com.enonic.xp.blob.CachingBlobStore)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 MemoryBlobStore (com.enonic.xp.internal.blobstore.MemoryBlobStore)1 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 NodeId (com.enonic.xp.node.NodeId)1 RepoLoadException (com.enonic.xp.repo.impl.dump.RepoLoadException)1