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
}
}
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);
}
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));
}
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);
}
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));
}
Aggregations