Search in sources :

Example 6 with ByteSource

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

the class ByteSourceJUnitTest method testHashCode.

@Test
public void testHashCode() {
    ByteSource bs = createByteSource(new byte[] {});
    bs.hashCode();
    bs = createByteSource(new byte[] { 1, 2, 3, 4, 5 });
    int hc1 = bs.hashCode();
    bs = createByteSource(new byte[] { 1, 2, 3, 4, 5 });
    int hc2 = bs.hashCode();
    assertEquals(hc1, hc2);
}
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 7 with ByteSource

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

the class ByteSourceJUnitTest method testGetLong.

@Test
public void testGetLong() {
    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);
    long l = bs.getLong();
    assertEquals(0x1110223344556677L, l);
    assertEquals(8, bs.position());
    l = bs.getLong();
    assertEquals(0x2220334455667788L, l);
    assertEquals(16, bs.position());
    bs.position(4 * 8);
    l = bs.getLong();
    assertEquals(0x55506677889900AAL, l);
    assertEquals(40, bs.position());
    try {
        bs.getLong();
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
}
Also used : LongBuffer(java.nio.LongBuffer) ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) ByteBuffer(java.nio.ByteBuffer) 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 8 with ByteSource

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

the class ByteSourceJUnitTest method testCapacity.

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

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

the class ByteSourceJUnitTest method testGetByteArrayIntInt.

@Test
public void testGetByteArrayIntInt() {
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    byte[] bytes = new byte[10];
    bs.get(bytes, 0, 2);
    assertEquals(2, bs.position());
    bs.get(bytes, 2, 0);
    assertEquals(2, bs.position());
    bs.get(bytes, 2, 3);
    assertEquals(5, bs.position());
    try {
        bs.get(bytes, 4, 6);
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
    bs.get(bytes, 5, 5);
    assertEquals(10, bs.position());
    bs.get(bytes, 10, 0);
    assertEquals(10, bs.position());
    assertArrayEquals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }, bytes);
    try {
        bs.get(bytes, 9, 1);
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
    try {
        bs.get(bytes, 10, 1);
        fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.get(bytes, 3, -1);
        fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {
    }
    try {
        bs.get(bytes, -1, 2);
        fail("expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException expected) {
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) 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 10 with ByteSource

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

the class ByteSourceJUnitTest method testGetByteArray.

@Test
public void testGetByteArray() {
    ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
    byte[] bytes = new byte[2];
    bs.get(bytes);
    assertArrayEquals(new byte[] { 1, 2 }, bytes);
    assertEquals(2, bs.position());
    bytes = new byte[0];
    bs.get(bytes);
    assertEquals(2, bs.position());
    bytes = new byte[3];
    bs.get(bytes);
    assertArrayEquals(new byte[] { 3, 4, 5 }, bytes);
    assertEquals(5, bs.position());
    try {
        bytes = new byte[6];
        bs.get(bytes);
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
    bytes = new byte[5];
    bs.get(bytes);
    assertArrayEquals(new byte[] { 6, 7, 8, 9, 0 }, bytes);
    assertEquals(10, bs.position());
    bytes = new byte[0];
    bs.get(bytes);
    assertEquals(10, bs.position());
    try {
        bytes = new byte[1];
        bs.get(bytes);
        fail("expected BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
}
Also used : ByteSource(org.apache.geode.internal.tcp.ByteBufferInputStream.ByteSource) 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)

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