Search in sources :

Example 16 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class MerkleSpecialFilesTest method liveFireSerdeWorksWithEmpty.

@Test
void liveFireSerdeWorksWithEmpty() throws IOException, ConstructableRegistryException {
    final var baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleSpecialFiles.class, MerkleSpecialFiles::new));
    subject.serialize(dos);
    dos.flush();
    final var bytes = baos.toByteArray();
    final var bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    final var newSubject = new MerkleSpecialFiles();
    newSubject.deserialize(din, MerkleSpecialFiles.CURRENT_VERSION);
    assertTrue(newSubject.getFileContents().isEmpty(), "Deserialized instance should be empty");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Example 17 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class MerkleSpecialFilesTest method liveFireSerdeWorksWithNonEmpty.

@Test
void liveFireSerdeWorksWithNonEmpty() throws IOException, ConstructableRegistryException {
    final var baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleSpecialFiles.class, MerkleSpecialFiles::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FCQueue.class, FCQueue::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(FilePart.class, FilePart::new));
    subject.update(fid, Arrays.copyOfRange(stuff, 0, stuff.length / 2));
    subject.update(secondFid, Arrays.copyOfRange(stuff, stuff.length / 2, stuff.length));
    subject.serialize(dos);
    dos.flush();
    final var bytes = baos.toByteArray();
    final var bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    final var newSubject = new MerkleSpecialFiles();
    newSubject.deserialize(din, MerkleSpecialFiles.CURRENT_VERSION);
    assertArrayEquals(subject.get(fid), newSubject.get(fid), "Deserialized contents should match for first file");
    assertArrayEquals(subject.get(secondFid), newSubject.get(secondFid), "Deserialized contents should match for second file");
}
Also used : FCQueue(com.swirlds.fcqueue.FCQueue) ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FilePart(com.hedera.services.state.merkle.internals.FilePart) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Example 18 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class MerkleUniqueTokenTest method liveFireSerdeWorks.

@Test
void liveFireSerdeWorks() throws IOException, ConstructableRegistryException {
    // setup:
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final var dos = new SerializableDataOutputStream(baos);
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(MerkleUniqueToken.class, MerkleUniqueToken::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(EntityId.class, EntityId::new));
    // given:
    subject.serialize(dos);
    dos.flush();
    // and:
    final var bytes = baos.toByteArray();
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    final var din = new SerializableDataInputStream(bais);
    // when:
    final var newSubject = new MerkleUniqueToken();
    newSubject.deserialize(din, MerkleToken.CURRENT_VERSION);
    // then:
    assertEquals(subject, newSubject);
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) ByteArrayInputStream(java.io.ByteArrayInputStream) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair) Test(org.junit.jupiter.api.Test)

Example 19 with ClassConstructorPair

use of com.swirlds.common.constructable.ClassConstructorPair in project hedera-services by hashgraph.

the class RecordStreamCmpTest method registerConstructables.

private void registerConstructables() throws ConstructableRegistryException {
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(Hash.class, Hash::new));
    ConstructableRegistry.registerConstructable(new ClassConstructorPair(RecordStreamObject.class, RecordStreamObject::new));
}
Also used : RecordStreamObject(com.hedera.services.stream.RecordStreamObject) Hash(com.swirlds.common.crypto.Hash) ClassConstructorPair(com.swirlds.common.constructable.ClassConstructorPair)

Aggregations

ClassConstructorPair (com.swirlds.common.constructable.ClassConstructorPair)19 Test (org.junit.jupiter.api.Test)13 SerializableDataInputStream (com.swirlds.common.io.SerializableDataInputStream)9 SerializableDataOutputStream (com.swirlds.common.io.SerializableDataOutputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 EntityId (com.hedera.services.state.submerkle.EntityId)5 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)4 ExpirableTxnRecord (com.hedera.services.state.submerkle.ExpirableTxnRecord)3 MerkleLong (com.swirlds.common.merkle.utility.MerkleLong)3 FCQueue (com.swirlds.fcqueue.FCQueue)3 TxnReceipt (com.hedera.services.legacy.core.jproto.TxnReceipt)2 MerkleAccountState (com.hedera.services.state.merkle.MerkleAccountState)2 MerkleEntityId (com.hedera.services.state.merkle.MerkleEntityId)2 CurrencyAdjustments (com.hedera.services.state.submerkle.CurrencyAdjustments)2 EvmFnResult (com.hedera.services.state.submerkle.EvmFnResult)2 TxnId (com.hedera.services.state.submerkle.TxnId)2 MerkleMap (com.swirlds.merkle.map.MerkleMap)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 ServicesState (com.hedera.services.ServicesState)1