You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mnemonic.apache.org by ga...@apache.org on 2016/04/09 00:00:08 UTC
[6/7] incubator-mnemonic git commit: format codestyle & add Apache
License
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java b/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java
index 82829ef..2cda052 100644
--- a/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java
+++ b/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.collections;
import java.nio.ByteBuffer;
@@ -24,232 +41,232 @@ import org.testng.annotations.Test;
*
*/
-
public class NonVolatileNodeValueNGTest {
- private long KEYCAPACITY;
- private Random m_rand;
- private BigDataPMemAllocator m_act;
-
- @BeforeClass
- public void setUp() {
- m_rand = Utils.createRandom();
- m_act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024, "./pobj_NodeValue.dat", true);
- KEYCAPACITY = m_act.handlerCapacity();
- m_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;
- }
- });
- m_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 < KEYCAPACITY; ++i) {
- m_act.setHandler(i, 0L);
- }
- }
-
- @AfterClass
- public void tearDown() {
- m_act.close();
- }
-
- @Test(enabled = false)
- public void testSingleNodeValueWithInteger() {
- int val = m_rand.nextInt();
- GenericField.GType gtypes[] = {GenericField.GType.INTEGER};
- NonVolatileNodeValue<Integer> plln = NonVolatileNodeValueFactory.create(m_act, null, gtypes, false);
- plln.setItem(val, false);
- Long handler = plln.getNonVolatileHandler();
- System.err.println("-------------Start to Restore Integer -----------");
- NonVolatileNodeValue<Integer> plln2 = NonVolatileNodeValueFactory.restore(m_act, null, gtypes, handler, false);
- AssertJUnit.assertEquals(val, (int)plln2.getItem());
- }
-
- @Test(enabled = false)
- public void testNodeValueWithString() {
- String val = Utils.genRandomString();
- GenericField.GType gtypes[] = {GenericField.GType.STRING};
- NonVolatileNodeValue<String> plln = NonVolatileNodeValueFactory.create(m_act, null, gtypes, false);
- plln.setItem(val, false);
- Long handler = plln.getNonVolatileHandler();
- System.err.println("-------------Start to Restore String-----------");
- NonVolatileNodeValue<String> plln2 = NonVolatileNodeValueFactory.restore(m_act, null, gtypes, handler, false);
- AssertJUnit.assertEquals(val, plln2.getItem());
- }
-
- @Test(enabled = false)
- public void testNodeValueWithPerson() {
-
- Person<Long> person = PersonFactory.create(m_act);
- person.setAge((short)31);
-
- GenericField.GType gtypes[] = {GenericField.GType.DURABLE};
- EntityFactoryProxy efproxies[] = {new EntityFactoryProxy(){
- @Override
- public <A extends CommonPersistAllocator<A>> Durable restore(A allocator,
- EntityFactoryProxy[] factoryproxys, GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
- return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
- }
- }
- };
-
- NonVolatileNodeValue<Person<Long>> plln = NonVolatileNodeValueFactory.create(m_act, efproxies, gtypes, false);
- plln.setItem(person, false);
- Long handler = plln.getNonVolatileHandler();
-
- NonVolatileNodeValue<Person<Long>> plln2 = NonVolatileNodeValueFactory.restore(m_act, efproxies, gtypes, handler, false);
- AssertJUnit.assertEquals(31, (int)plln2.getItem().getAge());
-
- }
- @Test(enabled = false)
- public void testLinkedNodeValueWithPerson() {
-
- int elem_count = 10;
- List<Long> referlist = new ArrayList();
-
- GenericField.GType listgftypes[] = {GenericField.GType.DURABLE};
- EntityFactoryProxy listefproxies[] = {
- new EntityFactoryProxy(){
- @Override
- public <A extends CommonPersistAllocator<A>> Durable restore(A allocator,
- EntityFactoryProxy[] factoryproxys, GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
- return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
- }
- }
- };
-
- NonVolatileNodeValue<Person<Long>> firstnv = NonVolatileNodeValueFactory.create(m_act, listefproxies, listgftypes, false);
-
- NonVolatileNodeValue<Person<Long>> nextnv = firstnv;
-
- Person<Long> person;
- long val;
- NonVolatileNodeValue<Person<Long>> newnv;
- for (int i = 0; i < elem_count; ++i) {
- person = PersonFactory.create(m_act);
- person.setAge((short)m_rand.nextInt(50));
- person.setName(String.format("Name: [%s]", Utils.genRandomString()), true);
- nextnv.setItem(person, false);
- newnv = NonVolatileNodeValueFactory.create(m_act, listefproxies, listgftypes, false);
- nextnv.setNext(newnv, false);
- nextnv = newnv;
- }
-
- Person<Long> eval;
- NonVolatileNodeValue<Person<Long>> iternv = firstnv;
- while(null != iternv) {
- System.out.printf(" Stage 1 --->\n");
- eval = iternv.getItem();
- if (null != eval)
- eval.testOutput();
- iternv = iternv.getNext();
- }
-
- long handler = firstnv.getNonVolatileHandler();
-
- NonVolatileNodeValue<Person<Long>> firstnv2 = NonVolatileNodeValueFactory.restore(m_act, listefproxies, listgftypes, handler, false);
-
- for (Person<Long> eval2 : firstnv2) {
- System.out.printf(" Stage 2 ---> \n");
- if (null != eval2)
- eval2.testOutput();
- }
-
- //Assert.assert, expected);(plist, plist2);
-
- }
-
- @Test(enabled = true)
- public void testLinkedNodeValueWithLinkedNodeValue() {
-
- int elem_count = 10;
- long slotKeyId = 10;
-
- GenericField.GType[] elem_gftypes = {GenericField.GType.DOUBLE};
- EntityFactoryProxy[] elem_efproxies = null;
-
- GenericField.GType linkedgftypes[] = {GenericField.GType.DURABLE, GenericField.GType.DOUBLE};
- EntityFactoryProxy linkedefproxies[] = {
- new EntityFactoryProxy(){
- @Override
- public <A extends CommonPersistAllocator<A>> Durable restore(A allocator,
- EntityFactoryProxy[] factoryproxys, GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
- EntityFactoryProxy[] val_efproxies = null;
- GenericField.GType[] val_gftypes = null;
- if ( null != factoryproxys && factoryproxys.length >= 2 ) {
- val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
- }
- if ( null != gfields && gfields.length >= 2 ) {
- val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
- }
- return NonVolatileNodeValueFactory.restore(allocator, val_efproxies, val_gftypes, phandler, autoreclaim);
- }
- }
- };
-
- NonVolatileNodeValue<NonVolatileNodeValue<Double>> nextnv = null, pre_nextnv = null;
- NonVolatileNodeValue<Double> elem = null, pre_elem = null, first_elem = null;
-
- Long linkhandler = 0L;
-
- System.out.printf(" Stage 1 -testLinkedNodeValueWithLinkedNodeValue--> \n");
-
- pre_nextnv = null;
- Double val;
- for (int i=0; i< elem_count; ++i) {
- first_elem = null;
- pre_elem = null;
- for (int v=0; v<3 ; ++v) {
- elem = NonVolatileNodeValueFactory.create(m_act, elem_efproxies, elem_gftypes, false);
- val = m_rand.nextDouble();
- elem.setItem(val, false);
- if (null == pre_elem) {
- first_elem = elem;
- } else {
- pre_elem.setNext(elem, false);
- }
- pre_elem = elem;
- System.out.printf("%f ", val);
- }
-
- nextnv = NonVolatileNodeValueFactory.create(m_act, linkedefproxies, linkedgftypes, false);
- nextnv.setItem(first_elem, false);
- if (null == pre_nextnv) {
- linkhandler = nextnv.getNonVolatileHandler();
- } else {
- pre_nextnv.setNext(nextnv, false);
- }
- pre_nextnv = nextnv;
- System.out.printf(" generated an item... \n");
- }
- m_act.setHandler(slotKeyId, linkhandler);
-
- long handler = m_act.getHandler(slotKeyId);
-
- NonVolatileNodeValue<NonVolatileNodeValue<Double>> linkedvals = NonVolatileNodeValueFactory.restore(m_act, linkedefproxies, linkedgftypes, handler, false);
- Iterator<NonVolatileNodeValue<Double>> iter = linkedvals.iterator();
- Iterator<Double> elemiter = null;
-
- System.out.printf(" Stage 2 -testLinkedNodeValueWithLinkedNodeValue--> \n");
- while(iter.hasNext()) {
- elemiter = iter.next().iterator();
- while(elemiter.hasNext()) {
- System.out.printf("%f ", elemiter.next());
- }
- System.out.printf(" Fetched an item... \n");
- }
-
- //Assert.assert, expected);(plist, plist2);
-
- }
+ private long KEYCAPACITY;
+ private Random m_rand;
+ private BigDataPMemAllocator m_act;
+
+ @BeforeClass
+ public void setUp() {
+ m_rand = Utils.createRandom();
+ m_act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024,
+ "./pobj_NodeValue.dat", true);
+ KEYCAPACITY = m_act.handlerCapacity();
+ m_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;
+ }
+ });
+ m_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 < KEYCAPACITY; ++i) {
+ m_act.setHandler(i, 0L);
+ }
+ }
+
+ @AfterClass
+ public void tearDown() {
+ m_act.close();
+ }
+
+ @Test(enabled = false)
+ public void testSingleNodeValueWithInteger() {
+ int val = m_rand.nextInt();
+ GenericField.GType gtypes[] = { GenericField.GType.INTEGER };
+ NonVolatileNodeValue<Integer> plln = NonVolatileNodeValueFactory.create(m_act, null, gtypes, false);
+ plln.setItem(val, false);
+ Long handler = plln.getNonVolatileHandler();
+ System.err.println("-------------Start to Restore Integer -----------");
+ NonVolatileNodeValue<Integer> plln2 = NonVolatileNodeValueFactory.restore(m_act, null, gtypes, handler, false);
+ AssertJUnit.assertEquals(val, (int) plln2.getItem());
+ }
+
+ @Test(enabled = false)
+ public void testNodeValueWithString() {
+ String val = Utils.genRandomString();
+ GenericField.GType gtypes[] = { GenericField.GType.STRING };
+ NonVolatileNodeValue<String> plln = NonVolatileNodeValueFactory.create(m_act, null, gtypes, false);
+ plln.setItem(val, false);
+ Long handler = plln.getNonVolatileHandler();
+ System.err.println("-------------Start to Restore String-----------");
+ NonVolatileNodeValue<String> plln2 = NonVolatileNodeValueFactory.restore(m_act, null, gtypes, handler, false);
+ AssertJUnit.assertEquals(val, plln2.getItem());
+ }
+
+ @Test(enabled = false)
+ public void testNodeValueWithPerson() {
+
+ Person<Long> person = PersonFactory.create(m_act);
+ person.setAge((short) 31);
+
+ GenericField.GType gtypes[] = { GenericField.GType.DURABLE };
+ EntityFactoryProxy efproxies[] = { new EntityFactoryProxy() {
+ @Override
+ public <A extends CommonPersistAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
+ return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
+ }
+ } };
+
+ NonVolatileNodeValue<Person<Long>> plln = NonVolatileNodeValueFactory.create(m_act, efproxies, gtypes, false);
+ plln.setItem(person, false);
+ Long handler = plln.getNonVolatileHandler();
+
+ NonVolatileNodeValue<Person<Long>> plln2 = NonVolatileNodeValueFactory.restore(m_act, efproxies, gtypes, handler,
+ false);
+ AssertJUnit.assertEquals(31, (int) plln2.getItem().getAge());
+
+ }
+
+ @Test(enabled = false)
+ public void testLinkedNodeValueWithPerson() {
+
+ int elem_count = 10;
+ List<Long> referlist = new ArrayList();
+
+ GenericField.GType listgftypes[] = { GenericField.GType.DURABLE };
+ EntityFactoryProxy listefproxies[] = { new EntityFactoryProxy() {
+ @Override
+ public <A extends CommonPersistAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
+ return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
+ }
+ } };
+
+ NonVolatileNodeValue<Person<Long>> firstnv = NonVolatileNodeValueFactory.create(m_act, listefproxies, listgftypes,
+ false);
+
+ NonVolatileNodeValue<Person<Long>> nextnv = firstnv;
+
+ Person<Long> person;
+ long val;
+ NonVolatileNodeValue<Person<Long>> newnv;
+ for (int i = 0; i < elem_count; ++i) {
+ person = PersonFactory.create(m_act);
+ person.setAge((short) m_rand.nextInt(50));
+ person.setName(String.format("Name: [%s]", Utils.genRandomString()), true);
+ nextnv.setItem(person, false);
+ newnv = NonVolatileNodeValueFactory.create(m_act, listefproxies, listgftypes, false);
+ nextnv.setNext(newnv, false);
+ nextnv = newnv;
+ }
+
+ Person<Long> eval;
+ NonVolatileNodeValue<Person<Long>> iternv = firstnv;
+ while (null != iternv) {
+ System.out.printf(" Stage 1 --->\n");
+ eval = iternv.getItem();
+ if (null != eval)
+ eval.testOutput();
+ iternv = iternv.getNext();
+ }
+
+ long handler = firstnv.getNonVolatileHandler();
+
+ NonVolatileNodeValue<Person<Long>> firstnv2 = NonVolatileNodeValueFactory.restore(m_act, listefproxies, listgftypes,
+ handler, false);
+
+ for (Person<Long> eval2 : firstnv2) {
+ System.out.printf(" Stage 2 ---> \n");
+ if (null != eval2)
+ eval2.testOutput();
+ }
+
+ // Assert.assert, expected);(plist, plist2);
+
+ }
+
+ @Test(enabled = true)
+ public void testLinkedNodeValueWithLinkedNodeValue() {
+
+ int elem_count = 10;
+ long slotKeyId = 10;
+
+ GenericField.GType[] elem_gftypes = { GenericField.GType.DOUBLE };
+ EntityFactoryProxy[] elem_efproxies = null;
+
+ GenericField.GType linkedgftypes[] = { GenericField.GType.DURABLE, GenericField.GType.DOUBLE };
+ EntityFactoryProxy linkedefproxies[] = { new EntityFactoryProxy() {
+ @Override
+ public <A extends CommonPersistAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
+ EntityFactoryProxy[] val_efproxies = null;
+ GenericField.GType[] val_gftypes = null;
+ if (null != factoryproxys && factoryproxys.length >= 2) {
+ val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
+ }
+ if (null != gfields && gfields.length >= 2) {
+ val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
+ }
+ return NonVolatileNodeValueFactory.restore(allocator, val_efproxies, val_gftypes, phandler, autoreclaim);
+ }
+ } };
+
+ NonVolatileNodeValue<NonVolatileNodeValue<Double>> nextnv = null, pre_nextnv = null;
+ NonVolatileNodeValue<Double> elem = null, pre_elem = null, first_elem = null;
+
+ Long linkhandler = 0L;
+
+ System.out.printf(" Stage 1 -testLinkedNodeValueWithLinkedNodeValue--> \n");
+
+ pre_nextnv = null;
+ Double val;
+ for (int i = 0; i < elem_count; ++i) {
+ first_elem = null;
+ pre_elem = null;
+ for (int v = 0; v < 3; ++v) {
+ elem = NonVolatileNodeValueFactory.create(m_act, elem_efproxies, elem_gftypes, false);
+ val = m_rand.nextDouble();
+ elem.setItem(val, false);
+ if (null == pre_elem) {
+ first_elem = elem;
+ } else {
+ pre_elem.setNext(elem, false);
+ }
+ pre_elem = elem;
+ System.out.printf("%f ", val);
+ }
+
+ nextnv = NonVolatileNodeValueFactory.create(m_act, linkedefproxies, linkedgftypes, false);
+ nextnv.setItem(first_elem, false);
+ if (null == pre_nextnv) {
+ linkhandler = nextnv.getNonVolatileHandler();
+ } else {
+ pre_nextnv.setNext(nextnv, false);
+ }
+ pre_nextnv = nextnv;
+ System.out.printf(" generated an item... \n");
+ }
+ m_act.setHandler(slotKeyId, linkhandler);
+
+ long handler = m_act.getHandler(slotKeyId);
+
+ NonVolatileNodeValue<NonVolatileNodeValue<Double>> linkedvals = NonVolatileNodeValueFactory.restore(m_act,
+ linkedefproxies, linkedgftypes, handler, false);
+ Iterator<NonVolatileNodeValue<Double>> iter = linkedvals.iterator();
+ Iterator<Double> elemiter = null;
+
+ System.out.printf(" Stage 2 -testLinkedNodeValueWithLinkedNodeValue--> \n");
+ while (iter.hasNext()) {
+ elemiter = iter.next().iterator();
+ while (elemiter.hasNext()) {
+ System.out.printf("%f ", elemiter.next());
+ }
+ System.out.printf(" Fetched an item... \n");
+ }
+
+ // Assert.assert, expected);(plist, plist2);
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java b/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java
index fb75eac..d5efb7e 100644
--- a/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java
+++ b/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.collections;
import org.apache.mnemonic.*;
@@ -17,118 +34,112 @@ public class NonVolatilePersonNGTest {
@Test(expectedExceptions = { OutOfPersistentMemory.class })
public void testGenPeople() throws OutOfPersistentMemory, RetrieveNonVolatileEntityError {
- Random rand = Utils.createRandom();
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 8, "./pobj_person.dat", true);
- KEYCAPACITY = 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 < KEYCAPACITY; ++i) {
- act.setHandler(i, 0L);
- }
-
- Person<Integer> mother;
- Person<Integer> person;
-
- long keyidx = 0;
- long val;
-
- try {
- while(true) {
- //if (keyidx >= KEYCAPACITY) break;
-
- keyidx %= KEYCAPACITY;
-
- 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.getNonVolatileHandler());
-
- 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();
- }
+ Random rand = Utils.createRandom();
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 8, "./pobj_person.dat", true);
+ KEYCAPACITY = 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 < KEYCAPACITY; ++i) {
+ act.setHandler(i, 0L);
+ }
+
+ Person<Integer> mother;
+ Person<Integer> person;
+
+ long keyidx = 0;
+ long val;
+
+ try {
+ while (true) {
+ // if (keyidx >= KEYCAPACITY) break;
+
+ keyidx %= KEYCAPACITY;
+
+ 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.getNonVolatileHandler());
+
+ 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"})
+ @Test(dependsOnMethods = { "testGenPeople" })
public void testCheckPeople() throws RetrieveNonVolatileEntityError {
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("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 < KEYCAPACITY; ++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();
- }
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("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 < KEYCAPACITY; ++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();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/test/java/org/apache/mnemonic/collections/Payload.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/mnemonic/collections/Payload.java b/collections/src/test/java/org/apache/mnemonic/collections/Payload.java
index 31945bd..a6f6518 100644
--- a/collections/src/test/java/org/apache/mnemonic/collections/Payload.java
+++ b/collections/src/test/java/org/apache/mnemonic/collections/Payload.java
@@ -1,3 +1,19 @@
+/*
+ * 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.collections;
@@ -8,22 +24,21 @@ package org.apache.mnemonic.collections;
*
*/
public class Payload implements java.io.Serializable, Comparable<Payload> {
-
- private static final long serialVersionUID = 187397440699436500L;
- public Payload(int iv, String strv, double dv) {
- ival = iv;
- strval = strv;
- dval = dv;
- }
+ private static final long serialVersionUID = 187397440699436500L;
+
+ public Payload(int iv, String strv, double dv) {
+ ival = iv;
+ strval = strv;
+ dval = dv;
+ }
- public int ival;
- public String strval;
- public double dval;
+ public int ival;
+ public String strval;
+ public double dval;
- @Override
- public int compareTo(Payload pl) {
- return ival == pl.ival && strval.equals(pl.strval) && dval == pl.dval ? 0
- : 1;
- }
+ @Override
+ public int compareTo(Payload pl) {
+ return ival == pl.ival && strval.equals(pl.strval) && dval == pl.dval ? 0 : 1;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/test/java/org/apache/mnemonic/collections/Person.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/mnemonic/collections/Person.java b/collections/src/test/java/org/apache/mnemonic/collections/Person.java
index c7afa64..bf2a0d3 100644
--- a/collections/src/test/java/org/apache/mnemonic/collections/Person.java
+++ b/collections/src/test/java/org/apache/mnemonic/collections/Person.java
@@ -1,3 +1,20 @@
+/*
+ * 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.collections;
import org.apache.mnemonic.*;
@@ -11,54 +28,60 @@ import java.util.List;
@NonVolatileEntity
public abstract class Person<E> implements Durable, Comparable<Person<E>> {
- E element;
-
- @Override
- public void initializeAfterCreate() {
- System.out.println("Initializing After Created");
- }
-
- @Override
- public void initializeAfterRestore() {
- System.out.println("Initializing After Restored");
- }
-
- @Override
- public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
-
- }
-
- @Test
- public void testOutput() throws RetrieveNonVolatileEntityError {
- System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(),
- null == getMother()? "No Recorded Mother" : "Has Recorded Mother");
- }
-
- public int compareTo(Person<E> anotherPerson) {
- int ret = 0;
- if (0 == ret) ret = getAge().compareTo(anotherPerson.getAge());
- if (0 == ret) ret = getName().compareTo(anotherPerson.getName());
- return ret;
- }
-
- @NonVolatileGetter(Id = 1L)
- abstract public Short getAge();
- @NonVolatileSetter
- abstract public void setAge(Short age);
-
- @NonVolatileGetter(Id = 2L)
- abstract public String getName() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setName(String name, boolean destroy) throws OutOfPersistentMemory, RetrieveNonVolatileEntityError;
-
- @NonVolatileGetter(Id = 3L)
- abstract public Person<E> getMother() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setMother(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
-
- @NonVolatileGetter(Id = 4L)
- abstract public Person<E> getFather() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setFather(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
-}
+ E element;
+
+ @Override
+ public void initializeAfterCreate() {
+ System.out.println("Initializing After Created");
+ }
+
+ @Override
+ public void initializeAfterRestore() {
+ System.out.println("Initializing After Restored");
+ }
+
+ @Override
+ public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
+
+ }
+
+ @Test
+ public void testOutput() throws RetrieveNonVolatileEntityError {
+ System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(),
+ null == getMother() ? "No Recorded Mother" : "Has Recorded Mother");
+ }
+ public int compareTo(Person<E> anotherPerson) {
+ int ret = 0;
+ if (0 == ret)
+ ret = getAge().compareTo(anotherPerson.getAge());
+ if (0 == ret)
+ ret = getName().compareTo(anotherPerson.getName());
+ return ret;
+ }
+
+ @NonVolatileGetter(Id = 1L)
+ abstract public Short getAge();
+
+ @NonVolatileSetter
+ abstract public void setAge(Short age);
+
+ @NonVolatileGetter(Id = 2L)
+ abstract public String getName() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setName(String name, boolean destroy)
+ throws OutOfPersistentMemory, RetrieveNonVolatileEntityError;
+
+ @NonVolatileGetter(Id = 3L)
+ abstract public Person<E> getMother() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setMother(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileGetter(Id = 4L)
+ abstract public Person<E> getFather() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setFather(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/Allocatable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/Allocatable.java b/core/src/main/java/org/apache/mnemonic/Allocatable.java
index 76ec38d..1009316 100644
--- a/core/src/main/java/org/apache/mnemonic/Allocatable.java
+++ b/core/src/main/java/org/apache/mnemonic/Allocatable.java
@@ -1,102 +1,117 @@
+/*
+ * 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;
/**
- * an interface to allocate memory resources from any underlying memory kind
- * of storage.
+ * an interface to allocate memory resources from any underlying memory kind of
+ * storage.
*
*/
public interface Allocatable<A extends CommonAllocator<A>> {
-
- /**
- * create a memory chunk that is managed by its holder.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * chunk automatically
- *
- * @return a holder contains a memory chunk
- */
- public MemChunkHolder<A> createChunk(long size, boolean autoreclaim);
- /**
- * create a memory chunk that is managed by its holder.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @return a holder contains a memory chunk
- */
- public MemChunkHolder<A> createChunk(long size);
+ /**
+ * create a memory chunk that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this chunk automatically
+ *
+ * @return a holder contains a memory chunk
+ */
+ public MemChunkHolder<A> createChunk(long size, boolean autoreclaim);
+
+ /**
+ * create a memory chunk that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @return a holder contains a memory chunk
+ */
+ public MemChunkHolder<A> createChunk(long size);
+
+ /**
+ * create a memory buffer that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this buffer automatically
+ *
+ * @return a holder contains a memory buffer
+ */
+ public MemBufferHolder<A> createBuffer(long size, boolean autoreclaim);
+
+ /**
+ * create a memory buffer that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @return a holder contains a memory buffer
+ */
+ public MemBufferHolder<A> createBuffer(long size);
- /**
- * create a memory buffer that is managed by its holder.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * buffer automatically
- *
- * @return a holder contains a memory buffer
- */
- public MemBufferHolder<A> createBuffer(long size, boolean autoreclaim);
-
- /**
- * create a memory buffer that is managed by its holder.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @return a holder contains a memory buffer
- */
- public MemBufferHolder<A> createBuffer(long size);
+ /**
+ * register a memory chunk for auto-reclaim
+ *
+ * @param mholder
+ * specify a chunk holder to register
+ */
+ public void registerChunkAutoReclaim(MemChunkHolder<A> mholder);
- /**
- * register a memory chunk for auto-reclaim
- *
- * @param mholder
- * specify a chunk holder to register
- */
- public void registerChunkAutoReclaim(MemChunkHolder<A> mholder);
+ /**
+ * register a memory buffer for auto-reclaim
+ *
+ * @param mholder
+ * specify a buffer holder to register
+ */
+ public void registerBufferAutoReclaim(MemBufferHolder<A> mholder);
- /**
- * register a memory buffer for auto-reclaim
- *
- * @param mholder
- * specify a buffer holder to register
- */
- public void registerBufferAutoReclaim(MemBufferHolder<A> mholder);
+ /**
+ * resize a memory chunk.
+ *
+ * @param mholder
+ * specify a chunk holder for resizing
+ *
+ * @param size
+ * specify a new size of this memory chunk
+ *
+ * @return the resized memory chunk holder
+ *
+ */
+ public MemChunkHolder<A> resizeChunk(MemChunkHolder<A> mholder, long size);
- /**
- * resize a memory chunk.
- *
- * @param mholder
- * specify a chunk holder for resizing
- *
- * @param size
- * specify a new size of this memory chunk
- *
- * @return the resized memory chunk holder
- *
- */
- public MemChunkHolder<A> resizeChunk(MemChunkHolder<A> mholder, long size);
-
- /**
- * resize a memory buffer.
- *
- * @param mholder
- * specify a buffer holder for resizing
- *
- * @param size
- * specify a new size of this memory buffer
- *
- * @return the resized memory buffer holder
- *
- */
- public MemBufferHolder<A> resizeBuffer(MemBufferHolder<A> mholder, long size);
+ /**
+ * resize a memory buffer.
+ *
+ * @param mholder
+ * specify a buffer holder for resizing
+ *
+ * @param size
+ * specify a new size of this memory buffer
+ *
+ * @return the resized memory buffer holder
+ *
+ */
+ public MemBufferHolder<A> resizeBuffer(MemBufferHolder<A> mholder, long size);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/Allocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/Allocator.java b/core/src/main/java/org/apache/mnemonic/Allocator.java
index c887b07..950b890 100644
--- a/core/src/main/java/org/apache/mnemonic/Allocator.java
+++ b/core/src/main/java/org/apache/mnemonic/Allocator.java
@@ -1,3 +1,20 @@
+/*
+ * 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;
/**
@@ -6,34 +23,34 @@ package org.apache.mnemonic;
*/
public interface Allocator<A extends CommonAllocator<A>> extends Allocatable<A> {
- /**
- * release the underlying memory pool and close it.
- *
- */
- public void close();
+ /**
+ * release the underlying memory pool and close it.
+ *
+ */
+ public void close();
- /**
- * sync. dirty data to underlying memory-like device
- *
- */
- public void sync();
+ /**
+ * sync. dirty data to underlying memory-like device
+ *
+ */
+ public void sync();
- /**
- * enable active garbage collection. the GC will be forced to collect garbages when
- * there is no more space for current allocation request.
- *
- * @param timeout
- * the timeout is used to yield for GC performing
- *
- * @return this allocator
- */
- public A enableActiveGC(long timeout);
+ /**
+ * enable active garbage collection. the GC will be forced to collect garbages
+ * when there is no more space for current allocation request.
+ *
+ * @param timeout
+ * the timeout is used to yield for GC performing
+ *
+ * @return this allocator
+ */
+ public A enableActiveGC(long timeout);
- /**
- * disable active garbage collection.
- *
- * @return this allocator
- */
- public A disableActiveGC();
+ /**
+ * disable active garbage collection.
+ *
+ * @return this allocator
+ */
+ public A disableActiveGC();
}