Search in sources :

Example 26 with BlobRecord

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());
}
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 27 with BlobRecord

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

Example 28 with BlobRecord

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

Example 29 with BlobRecord

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());
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) ByteSource(com.google.common.io.ByteSource) MemoryBlobStore(com.enonic.xp.internal.blobstore.MemoryBlobStore) Test(org.junit.jupiter.api.Test)

Example 30 with BlobRecord

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

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