Search in sources :

Example 91 with ChannelBuffer

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));
}
Also used : BlockLogBuffer(org.neo4j.com.BlockLogBuffer) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 92 with ChannelBuffer

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)));
}
Also used : BlockLogBuffer(org.neo4j.com.BlockLogBuffer) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 93 with ChannelBuffer

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();
}
Also used : ControlHandshakePacket(com.navercorp.pinpoint.rpc.packet.ControlHandshakePacket) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 94 with ChannelBuffer

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());
}
Also used : SendPacket(com.navercorp.pinpoint.rpc.packet.SendPacket) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 95 with ChannelBuffer

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;
}
Also used : ResponsePacket(com.navercorp.pinpoint.rpc.packet.ResponsePacket) ControlHandshakeResponsePacket(com.navercorp.pinpoint.rpc.packet.ControlHandshakeResponsePacket) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)494 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)70 Test (org.junit.Test)67 DeviceSession (org.traccar.DeviceSession)64 Position (org.traccar.model.Position)62 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)61 Test (org.testng.annotations.Test)49 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)48 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)44 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)37 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)34 ChannelFuture (org.jboss.netty.channel.ChannelFuture)28 Checkpoint (com.linkedin.databus.core.Checkpoint)27 ByteBuffer (java.nio.ByteBuffer)27 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)26 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)26 DateBuilder (org.traccar.helper.DateBuilder)26 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 IOException (java.io.IOException)23 ArrayList (java.util.ArrayList)23