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);
}
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) {
}
}
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());
}
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) {
}
}
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) {
}
}
Aggregations