Search in sources :

Example 1 with BlobStoragePipeline

use of com.swirlds.blob.internal.db.BlobStoragePipeline in project hedera-services by hashgraph.

the class LegacyMerkleOptionalBlobTest method testReleases.

@Test
void testReleases() throws SQLException {
    try (final BlobStoragePipeline pipeline = DbManager.getInstance().blob()) {
        final long binaryObjectCountBefore = pipeline.retrieveNumberOfBlobs();
        byte[] fileContents = new byte[1024];
        random.nextBytes(fileContents);
        final MerkleOptionalBlob sv = new MerkleOptionalBlob(fileContents);
        final long svId = sv.getDelegate().getId();
        byte[] fileContents2 = new byte[1024];
        random.nextBytes(fileContents2);
        final MerkleOptionalBlob sv2 = new MerkleOptionalBlob(fileContents2);
        final long binaryObjectCountAfterCreate = pipeline.retrieveNumberOfBlobs();
        assertEquals(binaryObjectCountBefore + 2, binaryObjectCountAfterCreate);
        sv.release();
        final long binaryObjectCountAfterDelete = pipeline.retrieveNumberOfBlobs();
        assertEquals(binaryObjectCountAfterCreate - 1, binaryObjectCountAfterDelete);
        assertThrows(BinaryObjectNotFoundException.class, () -> pipeline.get(svId));
        assertDoesNotThrow(() -> sv2.getData());
    }
}
Also used : MerkleOptionalBlob(com.hedera.services.state.merkle.MerkleOptionalBlob) BlobStoragePipeline(com.swirlds.blob.internal.db.BlobStoragePipeline) Test(org.junit.jupiter.api.Test)

Example 2 with BlobStoragePipeline

use of com.swirlds.blob.internal.db.BlobStoragePipeline in project hedera-services by hashgraph.

the class LegacyMerkleOptionalBlobTest method testCreates.

@Test
void testCreates() throws SQLException {
    try (BlobStoragePipeline pipeline = DbManager.getInstance().blob()) {
        final long binaryObjectCountBefore = pipeline.retrieveNumberOfBlobs();
        byte[] fileContents = new byte[1024];
        random.nextBytes(fileContents);
        MerkleOptionalBlob sv = new MerkleOptionalBlob(fileContents);
        final long binaryObjectCountAfter = pipeline.retrieveNumberOfBlobs();
        assertEquals(binaryObjectCountBefore + 1, binaryObjectCountAfter);
    }
}
Also used : MerkleOptionalBlob(com.hedera.services.state.merkle.MerkleOptionalBlob) BlobStoragePipeline(com.swirlds.blob.internal.db.BlobStoragePipeline) Test(org.junit.jupiter.api.Test)

Aggregations

MerkleOptionalBlob (com.hedera.services.state.merkle.MerkleOptionalBlob)2 BlobStoragePipeline (com.swirlds.blob.internal.db.BlobStoragePipeline)2 Test (org.junit.jupiter.api.Test)2