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());
}
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());
}
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()));
}
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()));
}
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();
}
Aggregations