Skip to content

Java run time error #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
41 changes: 39 additions & 2 deletions mnemonic-core/src/test/java/org/apache/mnemonic/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
*/

package org.apache.mnemonic;

/**
import java.nio.ByteBuffer;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
/*
*
*
*/
Expand All @@ -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<E> anotherPerson) {
Expand All @@ -54,6 +72,13 @@ public int compareTo(Person<E> 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;
}

Expand All @@ -70,6 +95,18 @@ public int compareTo(Person<E> 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<E> getMother() throws RetrieveDurableEntityError;

Expand Down