Skip to content

MNEMONIC-109:Create a testcase to manage durable object on volatile m… #22

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 3 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ To run several test cases:
```bash
$ # a testcase for module "mnemonic-core" that requires 'pmalloc' memory service to pass
$ mvn -Dtest=DurablePersonNGTest test -pl mnemonic-core -DskipTests=false

$ # a testcase for module "mnemonic-core" that requires 'vmem' memory service to pass
$ mvn -Dtest=VolatilePersonNGTest test -pl mnemonic-core -DskipTests=false

$ # a testcase for module "mnemonic-core" that requires 'pmalloc' memory service to pass
$ mvn -Dtest=NonVolatileMemAllocatorNGTest test -pl mnemonic-core -DskipTests=false
Expand Down
9 changes: 9 additions & 0 deletions build-tools/runall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ exit 1
fi
echo [SUCCESS] Test case DurablePersonNGTest for \"mnemonic-core\" is completed!

echo [INFO] Running VolatilePersonNGTest test case for \"mnemonic-core\"...
mvn -Dtest=VolatilePersonNGTest test -pl mnemonic-core -DskipTests=false > testlog/VolatilePersonNGTest.log
if [ $? -gt 0 ]
then
echo [ERROR] This test case requires \"vmem\" memory service to pass, please check if \"vmem\" has been configured correctly! If \"vmem\" is installed, please refer to testlog/VolatilePersonNGTest.log for detailed information.
exit 1
fi
echo [SUCCESS] Test case VolatilePersonNGTest for \"mnemonic-core\" is completed!

echo [INFO] Running NonVolatileMemAllocatorNGTest test case for \"mnemonic-core\"...
mvn -Dtest=NonVolatileMemAllocatorNGTest test -pl mnemonic-core -DskipTests=false > testlog/NonVolatileMemAllocatorNGTest.log
if [ $? -gt 0 ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
*
*
*/
public class VolatileMemAllocator extends RestorableAllocator<VolatileMemAllocator> {
public class VolatileMemAllocator extends RestorableAllocator<VolatileMemAllocator>
implements AddressTranslator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this change because it parent class already implemented the interface of AddressTranslator.


private boolean m_activegc = true;
private long m_gctimeout = 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.mnemonic;

/**
*
*
*/

import java.nio.ByteBuffer;
import java.util.Random;
import java.util.UUID;

import org.testng.annotations.Test;

public class VolatilePersonNGTest {
private long cKEYCAPACITY;

@Test(expectedExceptions = { OutOfHybridMemory.class })
public void testGenPeople() throws OutOfHybridMemory, RetrieveDurableEntityError {
Random rand = Utils.createRandom();
VolatileMemAllocator act = new VolatileMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"),
1024 * 1024 * 8, "./pobj_person.dat", true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use "." instead of "./pobj_person.dat" because this parameter is native library specific.


cKEYCAPACITY = act.handlerCapacity();
act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
@Override
public boolean reclaim(ByteBuffer mres, Long sz) {
System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
null == sz ? "NULL" : sz.toString()));
return false;
}
});
act.setChunkReclaimer(new Reclaim<Long>() {
@Override
public boolean reclaim(Long mres, Long sz) {
System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres),
null == sz ? "NULL" : sz.toString()));
return false;
}
});

for (long i = 0; i < cKEYCAPACITY; ++i) {
act.setHandler(i, 0L);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no handler store for Volatile memory service so you cannot use setHandler()/getHandler()

}

Person<Integer> mother;
Person<Integer> person;

long keyidx = 0;
long val;

try {
while (true) {
// if (keyidx >= KEYCAPACITY) break;

keyidx %= cKEYCAPACITY;

System.out.printf("************ Generating People on Key %d ***********\n", keyidx);

val = act.getHandler(keyidx);
if (0L != val) {
PersonFactory.restore(act, val, true);
}

person = PersonFactory.create(act);
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);
mother.setAge((short) (50 + rand.nextInt(50)));
mother.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);

person.setMother(mother, true);

person = mother;

}
++keyidx;
}
} finally {
act.close();
}
}

@Test(dependsOnMethods = { "testGenPeople" })
public void testCheckPeople() throws RetrieveDurableEntityError {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this testcase because volatile memory service does not support any persistence feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a new testcase to verify the data that has already been installed by the first testcase.

VolatileMemAllocator act = new VolatileMemAllocator(Utils.getVolatileMemoryAllocatorService("pmalloc"),
1024 * 1024 * 8, "./pobj_person.dat", true);
act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
@Override
public boolean reclaim(ByteBuffer mres, Long sz) {
System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
null == sz ? "NULL" : sz.toString()));
return false;
}
});
act.setChunkReclaimer(new Reclaim<Long>() {
@Override
public boolean reclaim(Long mres, Long sz) {
System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres),
null == sz ? "NULL" : sz.toString()));
return false;
}
});

long val;
for (long i = 0; i < cKEYCAPACITY; ++i) {
System.out.printf("----------Key %d--------------\n", i);
val = act.getHandler(i);
if (0L == val) {
break;
}
Person<Integer> person = PersonFactory.restore(act, val, true);
while (null != person) {
person.testOutput();
person = person.getMother();
}
}

act.close();
}
}