Search in sources :

Example 36 with BlobRecord

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

the class ReadThroughBlobStoreTest method obey_size_threshold.

@Test
public void obey_size_threshold() throws Exception {
    final ReadThroughBlobStore actualBlobStore = ReadThroughBlobStore.create().readThroughStore(this.readThroughStore).store(this.finalStore).sizeThreshold(ByteSizeParser.parse("80kb")).build();
    final ByteSource binary = ByteSource.wrap(ByteStreams.toByteArray(this.getClass().getResourceAsStream("fish-86kb.jpg")));
    final Segment segment = Segment.from("test", "blob");
    final BlobRecord record = actualBlobStore.addRecord(segment, binary);
    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 37 with BlobRecord

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

the class ReadThroughBlobStoreTest method removeRecord.

@Test
public void removeRecord() 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.removeRecord(segment, record.getKey());
    assertNull(this.readThroughStore.getRecord(segment, record.getKey()));
    assertNull(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 38 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 39 with BlobRecord

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

the class ReadThroughBlobStoreTest method last_modified_updated.

@Test
public void last_modified_updated() 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());
    final BlobRecord fileRecord = this.finalStore.getRecord(segment, record.getKey());
    assertEquals(readThroughRecord.lastModified(), fileRecord.lastModified());
    // ensure a second difference since
    Thread.sleep(1000);
    actualBlobStore.addRecord(segment, binary);
    final BlobRecord readThroughUpdated = this.readThroughStore.getRecord(segment, record.getKey());
    final BlobRecord finalUpdated = this.finalStore.getRecord(segment, record.getKey());
    assertEquals(readThroughUpdated.lastModified(), finalUpdated.lastModified());
    assertTrue(readThroughUpdated.lastModified() > readThroughRecord.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)

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