Search in sources :

Example 6 with NetworkReadableClosableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4 in project neo4j by neo4j.

the class MemberIdMarshalTest method shouldThrowExceptionForHalfWrittenInstance.

@Test
public void shouldThrowExceptionForHalfWrittenInstance() throws Exception {
    // given
    // a CoreMember and a ByteBuffer to write it to
    MemberId.Marshal marshal = new MemberId.Marshal();
    final MemberId aRealMember = new MemberId(UUID.randomUUID());
    ByteBuf buffer = Unpooled.buffer(1000);
    // and the CoreMember is serialized but for 5 bytes at the end
    marshal.marshal(aRealMember, new NetworkFlushableChannelNetty4(buffer));
    ByteBuf bufferWithMissingBytes = buffer.copy(0, buffer.writerIndex() - 5);
    // when
    try {
        marshal.unmarshal(new NetworkReadableClosableChannelNetty4(bufferWithMissingBytes));
        fail("Should have thrown exception");
    } catch (EndOfStreamException e) {
    // expected
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) EndOfStreamException(org.neo4j.causalclustering.messaging.EndOfStreamException) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) Test(org.junit.Test)

Example 7 with NetworkReadableClosableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4 in project neo4j by neo4j.

the class MemberIdMarshalTest method shouldSerializeAndDeserialize.

@Test
public void shouldSerializeAndDeserialize() throws Exception {
    // given
    MemberId.Marshal marshal = new MemberId.Marshal();
    final MemberId member = new MemberId(UUID.randomUUID());
    // when
    ByteBuf buffer = Unpooled.buffer(1_000);
    marshal.marshal(member, new NetworkFlushableChannelNetty4(buffer));
    final MemberId recovered = marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer));
    // then
    assertEquals(member, recovered);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) Test(org.junit.Test)

Example 8 with NetworkReadableClosableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4 in project neo4j by neo4j.

the class RaftContentByteBufferMarshalTest method assertMarshalingEquality.

private void assertMarshalingEquality(CoreReplicatedContentMarshal marshal, ByteBuf buffer, ReplicatedContent replicatedTx) throws IOException, EndOfStreamException {
    marshal.marshal(replicatedTx, new NetworkFlushableByteBuf(buffer));
    assertThat(marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer)), equalTo(replicatedTx));
}
Also used : NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)

Example 9 with NetworkReadableClosableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4 in project neo4j by neo4j.

the class RaftContentByteBufferMarshalTest method shouldSerializeTransactionRepresentation.

@Test
public void shouldSerializeTransactionRepresentation() throws Exception {
    // given
    CoreReplicatedContentMarshal serializer = new CoreReplicatedContentMarshal();
    Collection<StorageCommand> commands = new ArrayList<>();
    IndexCommand.AddNodeCommand addNodeCommand = new IndexCommand.AddNodeCommand();
    addNodeCommand.init(0, 0, 0, 0);
    commands.add(addNodeCommand);
    byte[] extraHeader = new byte[0];
    PhysicalTransactionRepresentation txIn = new PhysicalTransactionRepresentation(commands);
    txIn.setHeader(extraHeader, -1, -1, 0, 0, 0, 0);
    ReplicatedTransaction in = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(txIn);
    // when
    ByteBuf buf = Unpooled.buffer();
    serializer.marshal(in, new NetworkFlushableByteBuf(buf));
    ReplicatedTransaction out = (ReplicatedTransaction) serializer.unmarshal(new NetworkReadableClosableChannelNetty4(buf));
    TransactionRepresentation txOut = ReplicatedTransactionFactory.extractTransactionRepresentation(out, extraHeader);
    // then
    assertEquals(in, out);
    assertEquals(txIn, txOut);
}
Also used : NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) ReplicatedTransaction(org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction) StorageCommand(org.neo4j.storageengine.api.StorageCommand) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) CoreReplicatedContentMarshal(org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 10 with NetworkReadableClosableChannelNetty4

use of org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4 in project neo4j by neo4j.

the class CoreReplicatedContentMarshalTest method assertMarshalingEquality.

private void assertMarshalingEquality(ByteBuf buffer, ReplicatedContent replicatedTx) throws IOException, EndOfStreamException {
    marshal.marshal(replicatedTx, new NetworkFlushableByteBuf(buffer));
    assertThat(marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer)), equalTo(replicatedTx));
}
Also used : NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)

Aggregations

NetworkReadableClosableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)13 ByteBuf (io.netty.buffer.ByteBuf)6 Test (org.junit.Test)4 StoreId (org.neo4j.causalclustering.identity.StoreId)4 MemberId (org.neo4j.causalclustering.identity.MemberId)3 NetworkFlushableByteBuf (org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf)3 NetworkFlushableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4)3 IOException (java.io.IOException)2 RecordStorageCommandReaderFactory (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)1 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)1 ReplicatedContent (org.neo4j.causalclustering.core.replication.ReplicatedContent)1 ReplicatedTransaction (org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction)1 ClusterId (org.neo4j.causalclustering.identity.ClusterId)1 CoreReplicatedContentMarshal (org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal)1 EndOfStreamException (org.neo4j.causalclustering.messaging.EndOfStreamException)1