diff --git a/mnemonic-core/src/test/java/org/apache/mnemonic/DurablePersonNGTest.java b/mnemonic-core/src/test/java/org/apache/mnemonic/DurablePersonNGTest.java index e66c66f6..fe830130 100644 --- a/mnemonic-core/src/test/java/org/apache/mnemonic/DurablePersonNGTest.java +++ b/mnemonic-core/src/test/java/org/apache/mnemonic/DurablePersonNGTest.java @@ -25,14 +25,15 @@ import java.nio.ByteBuffer; import java.util.Random; import java.util.UUID; - +import org.testng.Assert; import org.testng.annotations.Test; +import sun.misc.Unsafe; public class DurablePersonNGTest { private long cKEYCAPACITY; @Test(expectedExceptions = { OutOfHybridMemory.class }) - public void testGenPeople() throws OutOfHybridMemory, RetrieveDurableEntityError { + public void testGenPeople() throws OutOfHybridMemory, RetrieveDurableEntityError, Exception { Random rand = Utils.createRandom(); NonVolatileMemAllocator act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 8, "./pobj_person.dat", true); @@ -63,7 +64,8 @@ public boolean reclaim(Long mres, Long sz) { long keyidx = 0; long val; - + MemBufferHolder mbh; + MemChunkHolder mch; try { while (true) { // if (keyidx >= KEYCAPACITY) break; @@ -78,25 +80,74 @@ public boolean reclaim(Long mres, Long sz) { } person = PersonFactory.create(act); + int size = rand.nextInt(1024 * 1024) + 1024 * 1024; +/////////////////////////if size is smaller than remaining act capacity//// + + mbh = act.createBuffer(size); + if (mbh != null) { + Assert.assertNotNull(mbh); + for (int i = 0; i < size; i++) { + mbh.get().put((byte) rand.nextInt(255)); + } + person.setPicture(mbh, true); +// mbh.destroy(); + } + Unsafe unsafe = Utils.getUnsafe(); + mch = act.createChunk(size); + if (mch != null) { + Assert.assertNotNull(mch); + for (int i = 0; i < mch.getSize(); i++) { + //mch.get().put((byte) rand.nextInt(255)); + unsafe.putByte(mch.get() + i, (byte) rand.nextInt(255)); + } + person.setFingerprint(mch, true); +// mch.destroy(); + } person.setAge((short) rand.nextInt(50)); person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); + + + act.setHandler(keyidx, person.getHandler()); for (int deep = 0; deep < rand.nextInt(100); ++deep) { mother = PersonFactory.create(act); + mbh = act.createBuffer(size); + if (mbh != null) { + Assert.assertNotNull(mbh); + for (int i = 0; i < size; i++) { + mbh.get().put((byte) rand.nextInt(255)); + } + mother.setPicture(mbh, true); + +// mbh.destroy(); + } + //mother = PersonFactory.create(act); + mch = act.createChunk(size); + if (mch != null) { + Assert.assertNotNull(mch); + /* for (int i = 0; i < size; i++) { + mch.get().put((byte) rand.nextInt(255)); + }*/ + mother.setFingerprint(mch, true); +// mch.destroy(); + } mother.setAge((short) (50 + rand.nextInt(50))); mother.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true); + person.setMother(mother, true); person = mother; +// mbh.destroy(); } +// mbh.destroy(); ++keyidx; } } finally { diff --git a/mnemonic-core/src/test/java/org/apache/mnemonic/Person.java b/mnemonic-core/src/test/java/org/apache/mnemonic/Person.java index fa2b564d..651eb177 100644 --- a/mnemonic-core/src/test/java/org/apache/mnemonic/Person.java +++ b/mnemonic-core/src/test/java/org/apache/mnemonic/Person.java @@ -16,8 +16,10 @@ */ package org.apache.mnemonic; - -/** +import java.nio.ByteBuffer; +import java.util.zip.CRC32; +import java.util.zip.Checksum; +/* * * */ @@ -44,6 +46,22 @@ public void setupGenericInfo(EntityFactoryProxy[] efproxies, DurableType[] gftyp public void testOutput() throws RetrieveDurableEntityError { System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(), null == getMother() ? "No Recorded Mother" : "Has Recorded Mother"); + if (null != getPicture()) { + System.err.println("getPicture"); + ByteBuffer mres = (ByteBuffer) getPicture().get(); + System.err.println("getPicture().get()"); + byte bytes[] = new byte[mres.capacity()]; + System.err.println("mres.capacity()"); + mres.get(bytes, 0, bytes.length); + System.err.println("mres.get()"); + Checksum checksum = new CRC32(); + System.err.println("CRC32()"); + checksum.update(bytes, 0, bytes.length); + System.err.println("checksum.updates()"); + long checksumValue = checksum.getValue(); + System.err.println("checksum.getValue()"); + System.out.println("CRC code of this person's buffer: \n" + checksumValue); + } } public int compareTo(Person anotherPerson) { @@ -54,6 +72,13 @@ public int compareTo(Person anotherPerson) { if (0 == ret) { ret = getName().compareTo(anotherPerson.getName()); } + if (0 == ret) { + ret = (int) (getPicture().getSize() - anotherPerson.getPicture().getSize()); + } + if (0 == ret) { + ret = (int) (getFingerprint().getSize() - anotherPerson.getFingerprint().getSize()); + } + return ret; } @@ -70,6 +95,18 @@ public int compareTo(Person anotherPerson) { public abstract void setName(String name, boolean destroy) throws OutOfHybridMemory, RetrieveDurableEntityError; + @DurableGetter + public abstract MemBufferHolder getPicture(); + + @DurableSetter + public abstract void setPicture(MemBufferHolder mbh, boolean destroy); + + @DurableGetter + public abstract MemChunkHolder getFingerprint(); + + @DurableSetter + public abstract void setFingerprint(MemChunkHolder mch, boolean destroy); + @DurableGetter public abstract Person getMother() throws RetrieveDurableEntityError;