use of org.jboss.netty.buffer.ChannelBuffer in project graphdb by neo4j-attic.
the class TestBlockLogBuffer method onlyOneFullBlock.
@Test
public void onlyOneFullBlock() throws Exception {
byte[] bytes = new byte[256];
ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
wrappedBuffer.resetWriterIndex();
BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer);
byte[] bytesValue = new byte[255];
bytesValue[0] = 1;
bytesValue[254] = -1;
buffer.put(bytesValue);
buffer.done();
ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);
assertEquals((byte) 255, verificationBuffer.get());
byte[] actualBytes = new byte[bytesValue.length];
verificationBuffer.get(actualBytes);
assertThat(actualBytes, new ArrayMatches<byte[]>(bytesValue));
}
use of org.jboss.netty.buffer.ChannelBuffer in project graphdb by neo4j-attic.
the class TestBlockLogBuffer method canWriteReallyLargeByteArray.
@Test
public void canWriteReallyLargeByteArray() throws Exception {
byte[] bytes = new byte[650];
ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
wrappedBuffer.resetWriterIndex();
BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer);
byte[] bytesValue = new byte[600];
bytesValue[1] = 1;
bytesValue[99] = 2;
bytesValue[199] = 3;
bytesValue[299] = 4;
bytesValue[399] = 5;
bytesValue[499] = 6;
bytesValue[599] = 7;
buffer.put(bytesValue);
buffer.done();
byte[] actual;
ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);
assertEquals((byte) 0, verificationBuffer.get());
actual = new byte[255];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 0, 255)));
assertEquals((byte) 0, verificationBuffer.get());
actual = new byte[255];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 255, 510)));
assertEquals((byte) 90, verificationBuffer.get());
actual = new byte[90];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 510, 600)));
}
use of org.jboss.netty.buffer.ChannelBuffer in project pinpoint by naver.
the class PinpointServerStateTest method createHandshakePayload.
private byte[] createHandshakePayload(Map<String, Object> data) throws ProtocolException {
byte[] payload = ControlMessageEncodingUtils.encode(data);
ControlHandshakePacket handshakePacket = new ControlHandshakePacket(payload);
ChannelBuffer channelBuffer = handshakePacket.toBuffer();
return channelBuffer.toByteBuffer().array();
}
use of org.jboss.netty.buffer.ChannelBuffer in project pinpoint by naver.
the class SendPacketTest method testToBuffer.
@Test
public void testToBuffer() throws Exception {
byte[] bytes = new byte[10];
SendPacket packetSend = new SendPacket(bytes);
ChannelBuffer channelBuffer = packetSend.toBuffer();
short packetType = channelBuffer.readShort();
SendPacket packet = (SendPacket) SendPacket.readBuffer(packetType, channelBuffer);
Assert.assertArrayEquals(bytes, packet.getPayload());
}
use of org.jboss.netty.buffer.ChannelBuffer in project pinpoint by naver.
the class ControlPacketServerTest method readSimpleResponsePacket.
private ResponsePacket readSimpleResponsePacket(InputStream inputStream) throws ProtocolException, IOException {
byte[] payload = readData(inputStream);
ChannelBuffer cb = ChannelBuffers.wrappedBuffer(payload);
short packetType = cb.readShort();
ResponsePacket packet = ResponsePacket.readBuffer(packetType, cb);
return packet;
}
Aggregations