Skip to content

Commit

Permalink
Fix tests from protocol changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW committed Sep 11, 2018
1 parent 3a204ae commit e349329
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 45 deletions.
Expand Up @@ -48,27 +48,6 @@ public class TransactionRepresentationReplicatedTransactionTest
@Rule
public final Buffers buffers = new Buffers();

@Test
public void shouldDecodeAndUnmarshalSameBytes() throws IOException
{
PhysicalTransactionRepresentation expectedTx =
new PhysicalTransactionRepresentation( Collections.singleton( new Command.NodeCommand( new NodeRecord( 1 ), new NodeRecord( 2 ) ) ) );

expectedTx.setHeader( new byte[0], 1, 2, 3, 4, 5, 6 );

ByteBuf buffer = buffers.buffer();
TransactionRepresentationReplicatedTransaction replicatedTransaction = ReplicatedTransaction.from( expectedTx );
replicatedTransaction.marshal( new BoundedNetworkWritableChannel( buffer ) );

ReplicatedTransaction decoded = ReplicatedTransactionSerializer.decode( buffer );
buffer.readerIndex( 0 );
ReplicatedTransaction unmarshaled = ReplicatedTransactionSerializer.unmarshal( new NetworkReadableClosableChannelNetty4( buffer ) );

assertEquals( decoded, unmarshaled );

buffer.release();
}

@Test
public void shouldMarshalToSameByteIfByteBufBackedOrNot() throws IOException
{
Expand Down
Expand Up @@ -26,8 +26,6 @@
import org.junit.Rule;
import org.junit.Test;

import java.io.IOException;

import org.neo4j.causalclustering.helpers.Buffers;

import static org.junit.Assert.assertArrayEquals;
Expand All @@ -38,45 +36,30 @@ public class ByteArrayChunkedEncoderTest
{
@Rule
public final Buffers buffers = new Buffers();

@Test
public void shouldWriteToBufferInChunks()
{
int chunkSize = 5;
byte[] data = new byte[]{1, 2, 3, 4, 5, 6};
byte[] readData = new byte[6];
ByteArrayChunkedEncoder byteArraySerializer = new ByteArrayChunkedEncoder( data, 5 );
ByteArrayChunkedEncoder byteArraySerializer = new ByteArrayChunkedEncoder( data, chunkSize );

ByteBuf buffer = byteArraySerializer.readChunk( buffers );
assertEquals( 6, buffer.readInt() );
assertEquals( 1, buffer.readableBytes() );
buffer.readBytes( readData, 0, 1 );
buffer.readBytes( readData, 0, chunkSize );
assertEquals( 0, buffer.readableBytes() );

buffer = byteArraySerializer.readChunk( buffers );
buffer.readBytes( readData, 1, buffer.readableBytes() );
buffer.readBytes( readData, chunkSize, 1 );
assertArrayEquals( data, readData );
assertEquals( 0, buffer.readableBytes() );

assertNull( byteArraySerializer.readChunk( buffers ) );
}

@Test
public void shouldHandleSmallByteBuf()
{
byte[] data = new byte[1];

ByteBuf byteBuf = new ByteArrayChunkedEncoder( data ).readChunk( buffers );
assertEquals( 1, byteBuf.readInt() );
assertEquals( 1, byteBuf.readableBytes() );
}

@Test( expected = IllegalArgumentException.class )
public void shouldThrowOnToSmallChunk()
public void shouldThrowOnTooSmallChunk()
{
new ByteArrayChunkedEncoder( new byte[1], 0 );
}

@Test( expected = IllegalArgumentException.class )
public void shoudThrowOnEmprtContent()
{
new ByteArrayChunkedEncoder( new byte[0] );
}
}

0 comments on commit e349329

Please sign in to comment.