Search in sources :

Example 21 with ByteSource

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

the class ByteSourceJUnitTest method testArrayOffset.

@Test
public void testArrayOffset() {
    byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    ByteSource bs = createByteSource(bytes);
    if (bs.hasArray()) {
        assertEquals(0, bs.arrayOffset());
        ByteBuffer bb = ByteBuffer.wrap(bytes);
        bb.position(1);
        bs = ByteSourceFactory.create(bb.slice());
        assertEquals(1, bs.arrayOffset());
    } else {
        try {
            bs.array();
            fail("expected UnsupportedOperationException");
        } catch (UnsupportedOperationException expected) {
        }
    }
}
Also used : 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 22 with ByteSource

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

the class ByteSourceJUnitTest method testGetIntInt.

@Test
public void testGetIntInt() {
    ByteBuffer bb = ByteBuffer.allocate(20);
    IntBuffer ib = bb.asIntBuffer();
    ib.put(0x11102233);
    ib.put(0x22203344);
    ib.put(0x33304455);
    ib.put(0x44405566);
    ib.put(0x55506677);
    byte[] bytes = bb.array();
    ByteSource bs = createByteSource(bytes);
    bs.position(3);
    int i = bs.getInt(0);
    assertEquals(0x11102233, i);
    assertEquals(3, bs.position());
    i = bs.getInt(4);
    assertEquals(0x22203344, i);
    assertEquals(3, bs.position());
    i = bs.getInt(4 * 4);
    assertEquals(0x55506677, i);
    assertEquals(3, bs.position());
    try {
        bs.getInt((4 * 4) + 1);
        fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {
    }
}
Also used : IntBuffer(java.nio.IntBuffer) 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 23 with ByteSource

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

the class ByteSourceJUnitTest method testPosition.

@Test
public void testPosition() {
    assertEquals(0, createByteSource(new byte[] {}).position());
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    assertEquals(0, bs.position());
    try {
        bs.position(-1);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        bs.position(11);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(0, bs.position());
    bs.position(10);
    assertEquals(10, bs.position());
    bs.limit(3);
    assertEquals(3, bs.position());
    try {
        bs.position(4);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
}
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 24 with ByteSource

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

the class ByteSourceJUnitTest method testGetShort.

@Test
public void testGetShort() {
    ByteBuffer bb = ByteBuffer.allocate(10);
    ShortBuffer sb = bb.asShortBuffer();
    sb.put((short) 0x1110);
    sb.put((short) 0x2220);
    sb.put((short) 0x3330);
    sb.put((short) 0x4440);
    sb.put((short) 0x5550);
    byte[] bytes = bb.array();
    ByteSource bs = createByteSource(bytes);
    short s = bs.getShort();
    assertEquals(0x1110, s);
    assertEquals(2, bs.position());
    s = bs.getShort();
    assertEquals(0x2220, s);
    assertEquals(4, bs.position());
    bs.position(8);
    s = bs.getShort();
    assertEquals(0x5550, s);
    assertEquals(10, bs.position());
    try {
        bs.getShort();
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer) BufferUnderflowException(java.nio.BufferUnderflowException) 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 25 with ByteSource

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

the class ByteSourceJUnitTest method testHasArray.

@Test
public void testHasArray() {
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    assertEquals(!isTestOffHeap(), bs.hasArray());
}
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