Search in sources :

Example 21 with Segment

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

the class ReadThroughBlobStoreTest method stored_after_read.

@Test
public void stored_after_read() 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()));
}
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 22 with Segment

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

the class ReadThroughBlobStoreTest method deleteSegment.

@Test
public void deleteSegment() {
    final ReadThroughBlobStore actualBlobStore = ReadThroughBlobStore.create().readThroughStore(readThroughStore).store(finalStore).build();
    final ByteSource binary = ByteSource.wrap("this is a record".getBytes());
    final Segment segment = Segment.from("test", "blob");
    final BlobRecord record = finalStore.addRecord(segment, binary);
    assertEquals(1, actualBlobStore.listSegments().count());
    assertEquals(record, actualBlobStore.getRecord(segment, record.getKey()));
    finalStore.removeRecord(segment, record.getKey());
    assertEquals(record, actualBlobStore.getRecord(segment, record.getKey()));
    actualBlobStore.deleteSegment(segment);
    assertEquals(0, actualBlobStore.listSegments().count());
    assertNull(actualBlobStore.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 23 with Segment

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

the class ReadThroughBlobStoreTest method list.

@Test
public void list() 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();
    final Stream<BlobRecord> stream = actualBlobStore.list(segment);
    final List<BlobRecord> records = stream.collect(Collectors.toList());
    assertTrue(records.contains(record));
}
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 24 with Segment

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

the class ReadThroughBlobStoreTest method listSegments.

@Test
public void listSegments() {
    final ReadThroughBlobStore actualBlobStore = ReadThroughBlobStore.create().readThroughStore(readThroughStore).store(finalStore).build();
    assertEquals(0, actualBlobStore.listSegments().count());
    final ByteSource binary = ByteSource.wrap("this is a record".getBytes());
    final Segment segment = Segment.from("test", "blob");
    finalStore.addRecord(segment, binary);
    assertEquals(1, actualBlobStore.listSegments().count());
}
Also used : ByteSource(com.google.common.io.ByteSource) Segment(com.enonic.xp.blob.Segment) Test(org.junit.jupiter.api.Test)

Example 25 with Segment

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

Aggregations

Segment (com.enonic.xp.blob.Segment)28 BlobRecord (com.enonic.xp.blob.BlobRecord)20 Test (org.junit.jupiter.api.Test)15 ByteSource (com.google.common.io.ByteSource)11 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)3 BlobStore (com.enonic.xp.blob.BlobStore)2 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 MemoryBlobRecord (com.enonic.xp.internal.blobstore.MemoryBlobRecord)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 Node (com.enonic.xp.node.Node)2 RepoDumpException (com.enonic.xp.repo.impl.dump.RepoDumpException)2 RepoLoadException (com.enonic.xp.repo.impl.dump.RepoLoadException)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 BlobKey (com.enonic.xp.blob.BlobKey)1 CachingBlobStore (com.enonic.xp.blob.CachingBlobStore)1 CachedBlobStore (com.enonic.xp.internal.blobstore.cache.CachedBlobStore)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 NodeVersion (com.enonic.xp.node.NodeVersion)1 Pre4NodeVersionJson (com.enonic.xp.repo.impl.dump.upgrade.obsoletemodel.pre4.Pre4NodeVersionJson)1 RepositoryExeption (com.enonic.xp.repository.RepositoryExeption)1