use of com.enonic.xp.blob.BlobRecord in project xp by enonic.
the class ReadThroughBlobStoreTest method last_modified.
@Test
public void last_modified() 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);
final BlobRecord readThroughRecord = this.readThroughStore.getRecord(segment, record.getKey());
assertNotNull(readThroughRecord);
final BlobRecord fileRecord = this.finalStore.getRecord(segment, record.getKey());
assertNotNull(fileRecord);
assertEquals(readThroughRecord.lastModified(), fileRecord.lastModified());
}
use of com.enonic.xp.blob.BlobRecord 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()));
}
use of com.enonic.xp.blob.BlobRecord in project xp by enonic.
the class CachedBlobStoreTest method addLargeRecord.
@Test
public void addLargeRecord() {
final BlobRecord record = newRecord("0123", 20L);
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);
assertSame(record, result1);
final BlobRecord result2 = this.cachedBlobStore.getRecord(segment, record.getKey());
assertSame(record, result2);
Mockito.verify(this.blobStore, Mockito.times(1)).getRecord(segment, record.getKey());
}
use of com.enonic.xp.blob.BlobRecord in project xp by enonic.
the class CachedBlobStoreTest method lastModified_updated.
@Test
public void lastModified_updated() throws Exception {
final MemoryBlobStore memoryBlobStore = new MemoryBlobStore();
final ByteSource source = ByteSource.wrap("abc".getBytes());
final BlobRecord record = memoryBlobStore.addRecord(this.segment, source);
this.cachedBlobStore = CachedBlobStore.create().blobStore(memoryBlobStore).memoryCapacity(100).sizeTreshold(10).build();
// Cache this
this.cachedBlobStore.getRecord(this.segment, record.getKey());
// Add same record again
final BlobRecord updatedRecord = this.cachedBlobStore.addRecord(this.segment, source);
// Only single entry added
final List<BlobRecord> cached = this.cachedBlobStore.list(this.segment).collect(Collectors.toList());
assertEquals(1, cached.size());
final BlobRecord retrievedAfterStore = this.cachedBlobStore.getRecord(this.segment, record.getKey());
assertNotNull(retrievedAfterStore);
assertEquals(updatedRecord.lastModified(), retrievedAfterStore.lastModified());
}
use of com.enonic.xp.blob.BlobRecord in project xp by enonic.
the class CachedBlobStoreTest method deleteSegment.
@Test
public void deleteSegment() {
final BlobRecord record = newRecord("0123", 10L);
assertNull(this.cachedBlobStore.getRecord(segment, record.getKey()));
Mockito.when(this.blobStore.getRecord(segment, record.getKey())).thenReturn(record);
assertNotNull(cachedBlobStore.getRecord(segment, record.getKey()));
Mockito.when(this.blobStore.getRecord(segment, record.getKey())).thenReturn(null);
assertNotNull(cachedBlobStore.getRecord(segment, record.getKey()));
cachedBlobStore.deleteSegment(segment);
Mockito.verify(blobStore).deleteSegment(segment);
assertNull(cachedBlobStore.getRecord(segment, record.getKey()));
}
Aggregations