/** */ @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 testCompare1() throws Exception { checkCompare("123"); }
/** * @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); } }
/** * @throws Exception If failed. */ @Test public void testByte() throws Exception { GridUnsafeMemory mem = new GridUnsafeMemory(64); int size = 32; long addr = mem.allocate(size); try { byte b1 = 123; mem.writeByte(addr, b1); byte b2 = mem.readByte(addr); assertEquals(b1, b2); byte b3 = 11; mem.writeByteVolatile(addr, b3); assertEquals(b3, mem.readByteVolatile(addr)); } finally { mem.release(addr, size); } }
/** * @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); } }
/** * */ @Test public void testFloat() { GridUnsafeMemory mem = new GridUnsafeMemory(64); int size = 32; long addr = mem.allocate(size); try { float f1 = 0.23223f; mem.writeFloat(addr, f1); assertEquals(f1, mem.readFloat(addr)); } finally { mem.release(addr, size); } }
assertEquals(i, allowed); assertTrue(oom); assertEquals(mem.allocatedSize(), 0);
/** * @throws Exception If failed. */ @Test public void testShort() throws Exception { GridUnsafeMemory mem = new GridUnsafeMemory(64); int size = 16; long addr = mem.allocate(size); try { short s1 = (short)56777; mem.writeShort(addr, s1); assertEquals(s1, mem.readShort(addr)); } finally { mem.release(addr, size); } }
/** * @throws Exception If failed. */ @Test public void testCompare2() throws Exception { checkCompare("1234567890"); }
/** * */ @Test public void testDouble() { GridUnsafeMemory mem = new GridUnsafeMemory(64); int size = 32; long addr = mem.allocate(size); try { double d1 = 0.2323423; mem.writeDouble(addr, d1); assertEquals(d1, mem.readDouble(addr)); } finally { mem.release(addr, size); } }
/** * @throws Exception If failed. */ @Test public void testCompare3() throws Exception { checkCompare("12345678901234567890"); }