Search in sources :

Example 31 with ByteSource

use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.

the class ByteSourceJUnitTest method testGetLongInt.

@Test
public void testGetLongInt() {
    ByteBuffer bb = ByteBuffer.allocate(40);
    LongBuffer lb = bb.asLongBuffer();
    lb.put(0x1110223344556677L);
    lb.put(0x2220334455667788L);
    lb.put(0x3330445566778899L);
    lb.put(0x4440556677889900L);
    lb.put(0x55506677889900AAL);
    byte[] bytes = bb.array();
    ByteSource bs = createByteSource(bytes);
    bs.position(3);
    long l = bs.getLong(0);
    assertEquals(0x1110223344556677L, l);
    assertEquals(3, bs.position());
    l = bs.getLong(8);
    assertEquals(0x2220334455667788L, l);
    assertEquals(3, bs.position());
    l = bs.getLong(4 * 8);
    assertEquals(0x55506677889900AAL, l);
    assertEquals(3, bs.position());
    try {
        bs.getLong((4 * 8) + 1);
        fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {
    }
}
Also used : LongBuffer(java.nio.LongBuffer) ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) UnitTest(org.apache.geode.test.junit.categories.UnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 32 with ByteSource

use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.

the class ByteSourceJUnitTest method testRemaining.

@Test
public void testRemaining() {
    assertEquals(0, createByteSource(new byte[] {}).remaining());
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    assertEquals(10, bs.remaining());
    bs.position(1);
    assertEquals(9, bs.remaining());
    bs.limit(9);
    assertEquals(8, bs.remaining());
    bs.position(8);
    assertEquals(1, bs.remaining());
    bs.position(9);
    assertEquals(0, bs.remaining());
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) UnitTest(org.apache.geode.test.junit.categories.UnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 33 with ByteSource

use of org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource in project geode by apache.

the class ByteSourceJUnitTest method testSliceIntInt.

@Test
public void testSliceIntInt() {
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    try {
        bs.slice(-1, 9);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        bs.slice(0, 11);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(bs, bs.slice(0, 10));
    ByteSource slice = bs.slice(1, 9);
    assertEquals(createByteSource(new byte[] { 2, 3, 4, 5, 6, 7, 8, 9 }), slice);
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) UnitTest(org.apache.geode.test.junit.categories.UnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

ByteSource (org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource)33 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)29 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)29 UnitTest (org.apache.geode.test.junit.categories.UnitTest)29 Test (org.junit.Test)29 ByteBuffer (java.nio.ByteBuffer)16 BufferUnderflowException (java.nio.BufferUnderflowException)9 CharBuffer (java.nio.CharBuffer)2 DoubleBuffer (java.nio.DoubleBuffer)2 FloatBuffer (java.nio.FloatBuffer)2 IntBuffer (java.nio.IntBuffer)2 LongBuffer (java.nio.LongBuffer)2 ShortBuffer (java.nio.ShortBuffer)2 InternalGemFireException (org.apache.geode.InternalGemFireException)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1 Version (org.apache.geode.internal.Version)1