Search in sources :

Example 1 with MerkleOptionalBlob

use of com.hedera.services.state.merkle.MerkleOptionalBlob in project hedera-services by hashgraph.

the class FcBlobsBytesStoreTest method putDeletesReplacedValueIfNoCopyIsHeld.

@Test
void putDeletesReplacedValueIfNoCopyIsHeld() {
    final MerkleMap<String, MerkleOptionalBlob> blobs = new MerkleMap<>();
    blobs.put("path", new MerkleOptionalBlob("FIRST".getBytes()));
    final var replaced = blobs.put("path", new MerkleOptionalBlob("SECOND".getBytes()));
    assertTrue(replaced.getDelegate().isReleased());
}
Also used : MerkleOptionalBlob(com.hedera.services.state.merkle.MerkleOptionalBlob) MerkleMap(com.swirlds.merkle.map.MerkleMap) Test(org.junit.jupiter.api.Test)

Example 2 with MerkleOptionalBlob

use of com.hedera.services.state.merkle.MerkleOptionalBlob in project hedera-services by hashgraph.

the class FcBlobsBytesStoreTest method putDoesNotDeleteReplacedValueIfCopyIsHeld.

@Test
void putDoesNotDeleteReplacedValueIfCopyIsHeld() {
    final MerkleMap<String, MerkleOptionalBlob> blobs = new MerkleMap<>();
    blobs.put("path", new MerkleOptionalBlob("FIRST".getBytes()));
    final var copy = blobs.copy();
    final var replaced = copy.put("path", new MerkleOptionalBlob("SECOND".getBytes()));
    assertFalse(replaced.getDelegate().isReleased());
}
Also used : MerkleOptionalBlob(com.hedera.services.state.merkle.MerkleOptionalBlob) MerkleMap(com.swirlds.merkle.map.MerkleMap) Test(org.junit.jupiter.api.Test)

Example 3 with MerkleOptionalBlob

use of com.hedera.services.state.merkle.MerkleOptionalBlob 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 4 with MerkleOptionalBlob

use of com.hedera.services.state.merkle.MerkleOptionalBlob 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)

Example 5 with MerkleOptionalBlob

use of com.hedera.services.state.merkle.MerkleOptionalBlob in project hedera-services by hashgraph.

the class FcmToJsonUtil method convertStorageToJson.

@Test
void convertStorageToJson() throws Exception {
    String[] round60Locs = { // "/Users/tinkerm/Dev/hgn3/hedera-services/hedera-node/n0-storage-round60.fcm",
    "/Users/tinkerm/Dev/hgn3/hedera-services/hedera-node/n1-storage-round60.fcm" // "/Users/tinkerm/Dev/hgn3/hedera-services/hedera-node/n2-storage-round60.fcm",
    // "/Users/tinkerm/Dev/hgn3/hedera-services/hedera-node/n3-storage-round60.fcm",
    };
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleLong.class, MerkleLong::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleBlobMeta.class, MerkleBlobMeta::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleOptionalBlob.class, MerkleOptionalBlob::new));
    for (String dumpLoc : round60Locs) {
        System.out.println("Reading " + dumpLoc);
        PojoFs.fromDisk(dumpLoc).asJsonTo(jsonSuffixed(dumpLoc));
    }
}
Also used : MerkleLong(com.swirlds.common.merkle.utility.MerkleLong) MerkleOptionalBlob(com.hedera.services.state.merkle.MerkleOptionalBlob) MerkleBlobMeta(com.hedera.services.state.merkle.MerkleBlobMeta) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Aggregations

MerkleOptionalBlob (com.hedera.services.state.merkle.MerkleOptionalBlob)7 Test (org.junit.jupiter.api.Test)5 BlobStoragePipeline (com.swirlds.blob.internal.db.BlobStoragePipeline)2 MerkleMap (com.swirlds.merkle.map.MerkleMap)2 MerkleBlobMeta (com.hedera.services.state.merkle.MerkleBlobMeta)1 ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)1 MerkleDataInputStream (com.swirlds.common.merkle.io.MerkleDataInputStream)1 MerkleLong (com.swirlds.common.merkle.utility.MerkleLong)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1