/** */ @Test public void testBuffers() { ByteBuffer b1 = GridUnsafe.allocateBuffer(10); ByteBuffer b2 = GridUnsafe.allocateBuffer(20); assertEquals(GridUnsafe.NATIVE_BYTE_ORDER, b2.order()); assertTrue(b2.isDirect()); assertEquals(20, b2.capacity()); assertEquals(20, b2.limit()); assertEquals(0, b2.position()); assertEquals(GridUnsafe.NATIVE_BYTE_ORDER, b1.order()); assertTrue(b1.isDirect()); assertEquals(10, b1.capacity()); assertEquals(10, b1.limit()); assertEquals(0, b1.position()); b1.putLong(1L); b1.putShort((short)7); b2.putLong(2L); GridUnsafe.freeBuffer(b1); b2.putLong(3L); b2.putInt(9); for (int i = 0; i <= 16; i++) b2.putInt(i, 100500); GridUnsafe.freeBuffer(b2); }
/** * @throws Exception If failed. */ @Test public void testLong() throws Exception { GridUnsafeMemory mem = new GridUnsafeMemory(64); int size = 32; long addr = mem.allocate(size); try { long l1 = 123456; mem.writeLong(addr, l1); long l2 = mem.readLong(addr); assertEquals(l1, l2); long l3 = 654321; mem.writeLongVolatile(addr, l3); long l4 = 666666; assertTrue(mem.casLong(addr, l3, l4)); assertFalse(mem.casLong(addr, l3, 0)); assertEquals(l4, mem.readLongVolatile(addr)); } finally { mem.release(addr, size); } }
/** * @throws Exception If failed. */ @Test public void testInt() throws Exception { GridUnsafeMemory mem = new GridUnsafeMemory(64); int size = 32; long addr = mem.allocate(size); try { int i1 = 123; mem.writeInt(addr, i1); int i2 = mem.readInt(addr); assertEquals(i1, i2); int i3 = 321; mem.writeIntVolatile(addr, i3); int i4 = 222; assertTrue(mem.casInt(addr, i3, i4)); assertFalse(mem.casInt(addr, i3, 0)); assertEquals(i4, mem.readIntVolatile(addr)); } finally { mem.release(addr, size); } }