mnemonic-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [2/3] incubator-mnemonic git commit: MNEMONIC-50: Create a test case to drive print service implementation
Date Wed, 01 Jun 2016 01:43:59 GMT
MNEMONIC-50: Create a test case to drive print service implementation


Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/7dfa60b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/7dfa60b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/7dfa60b4

Branch: refs/heads/master
Commit: 7dfa60b4c9a379a560f3634251b08b37e373b5af
Parents: 7217351
Author: Wang, Gang(Gary) <gang1.wang@intel.com>
Authored: Tue May 31 17:53:44 2016 -0700
Committer: Wang, Gang(Gary) <gang1.wang@intel.com>
Committed: Tue May 31 18:40:06 2016 -0700

----------------------------------------------------------------------
 .../mnemonic-utilities-service/pom.xml          |   4 +
 .../DurableNodeValueNGPrintTest.java            | 226 +++++++++++++++++++
 .../service/computingservice/Person.java        |  95 ++++++++
 .../src/test/resources/testng.xml               |  34 +++
 mnemonic-computing-services/pom.xml             |  19 ++
 5 files changed, 378 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/7dfa60b4/mnemonic-computing-services/mnemonic-utilities-service/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/pom.xml b/mnemonic-computing-services/mnemonic-utilities-service/pom.xml
index 6ce9d08..60deed0 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/pom.xml
+++ b/mnemonic-computing-services/mnemonic-utilities-service/pom.xml
@@ -97,6 +97,10 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
       </plugin>
+      <plugin>
+        <groupId>org.bsc.maven</groupId>
+        <artifactId>maven-processor-plugin</artifactId>
+      </plugin>
     </plugins>
   </build>
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/7dfa60b4/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
new file mode 100644
index 0000000..810656b
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
@@ -0,0 +1,226 @@
+/*
+ * 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.service.computingservice;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import org.apache.mnemonic.NonVolatileMemAllocator;
+import org.apache.mnemonic.CommonDurableAllocator;
+import org.apache.mnemonic.Durable;
+import org.apache.mnemonic.EntityFactoryProxy;
+import org.apache.mnemonic.GenericField;
+import org.apache.mnemonic.Utils;
+import org.apache.mnemonic.collections.DurableNodeValue;
+import org.apache.mnemonic.collections.DurableNodeValueFactory;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ *
+ *
+ */
+
+public class DurableNodeValueNGPrintTest {
+  public static String uri = "./pobj_NodeValue_print.dat";
+  private long cKEYCAPACITY;
+  private Random m_rand;
+  private NonVolatileMemAllocator m_act;
+
+  @BeforeClass
+  public void setUp() throws IOException {
+    m_rand = Utils.createRandom();
+    Files.deleteIfExists(Paths.get(uri));
+    m_act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
1024 * 1024 * 1024,
+        uri, true);
+    cKEYCAPACITY = m_act.handlerCapacity();
+    for (long i = 0; i < cKEYCAPACITY; ++i) {
+      m_act.setHandler(i, 0L);
+    }
+  }
+
+  @AfterClass
+  public void tearDown() {
+    m_act.close();
+  }
+
+  @Test(enabled = false)
+  public void testLinkedNodeValueWithPerson() {
+
+    int elem_count = 10;
+
+    GenericField.GType listgftypes[] = {GenericField.GType.DURABLE};
+    EntityFactoryProxy listefproxies[] = {new EntityFactoryProxy() {
+      @Override
+      public <A extends CommonDurableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
+          GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
+        return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
+      }
+    } };
+
+    DurableNodeValue<Person<Long>> firstnv = DurableNodeValueFactory.create(m_act,
listefproxies, listgftypes,
+        false);
+
+    DurableNodeValue<Person<Long>> nextnv = firstnv;
+
+    Person<Long> person = null;
+    long val;
+    DurableNodeValue<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 = DurableNodeValueFactory.create(m_act, listefproxies, listgftypes, false);
+      nextnv.setNext(newnv, false);
+      nextnv = newnv;
+    }
+
+    Person<Long> eval;
+    DurableNodeValue<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.getHandler();
+
+    DurableNodeValue<Person<Long>> firstnv2 = DurableNodeValueFactory.restore(m_act,
listefproxies, listgftypes,
+        handler, false);
+
+    for (Person<Long> eval2 : firstnv2) {
+      System.out.printf(" Stage 2 ---> \n");
+      if (null != eval2) {
+        eval2.testOutput();
+      }
+    }
+
+    GeneralComputingService gcsvr = Utils.getGeneralComputingService("print");
+    List<long[][]> objstack = new ArrayList<long[][]>();
+    objstack.add(firstnv.getNativeFieldInfo());
+    objstack.add(person.getNativeFieldInfo());
+    long[][] fidinfostack = {{2L, 1L}, {0L, 1L}};
+    long[][] npf = Utils.genNativeParamForm(objstack, fidinfostack);
+    gcsvr.perform(handler, npf);
+
+  }
+
+  @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 CommonDurableAllocator<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 DurableNodeValueFactory.restore(allocator, val_efproxies, val_gftypes, phandler,
autoreclaim);
+      }
+    } };
+
+    DurableNodeValue<DurableNodeValue<Double>> nextnv = null, pre_nextnv = null;
+    DurableNodeValue<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 = DurableNodeValueFactory.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 = DurableNodeValueFactory.create(m_act, linkedefproxies, linkedgftypes, false);
+      nextnv.setItem(first_elem, false);
+      if (null == pre_nextnv) {
+        linkhandler = nextnv.getHandler();
+      } 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);
+
+    DurableNodeValue<DurableNodeValue<Double>> linkedvals = DurableNodeValueFactory.restore(m_act,
+        linkedefproxies, linkedgftypes, handler, false);
+    Iterator<DurableNodeValue<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");
+    }
+
+    GeneralComputingService gcsvr = Utils.getGeneralComputingService("print");
+    List<long[][]> objstack = new ArrayList<long[][]>();
+    objstack.add(linkedvals.getNativeFieldInfo());
+    objstack.add(linkedvals.getNativeFieldInfo());
+    long[][] fidinfostack = {{2L, 1L}, {2L, 1L}};
+    long[][] npf = Utils.genNativeParamForm(objstack, fidinfostack);
+    gcsvr.perform(handler, npf);
+
+    // Assert.assert, expected);(plist, plist2);
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/7dfa60b4/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/Person.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/Person.java
b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/Person.java
new file mode 100644
index 0000000..f7d53d4
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/Person.java
@@ -0,0 +1,95 @@
+/*
+ * 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.service.computingservice;
+
+import org.apache.mnemonic.Durable;
+import org.apache.mnemonic.EntityFactoryProxy;
+import org.apache.mnemonic.GenericField;
+import org.apache.mnemonic.DurableEntity;
+import org.apache.mnemonic.DurableGetter;
+import org.apache.mnemonic.DurableSetter;
+import org.apache.mnemonic.OutOfHybridMemory;
+import org.apache.mnemonic.RetrieveDurableEntityError;
+import org.testng.annotations.Test;
+
+/**
+ *
+ *
+ */
+
+@DurableEntity
+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 RetrieveDurableEntityError {
+    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;
+  }
+
+  @DurableGetter(Id = 1L)
+  public abstract Short getAge();
+
+  @DurableSetter
+  public abstract void setAge(Short age);
+
+  @DurableGetter(Id = 2L)
+  public abstract String getName() throws RetrieveDurableEntityError;
+
+  @DurableSetter
+  public abstract void setName(String name, boolean destroy)
+      throws OutOfHybridMemory, RetrieveDurableEntityError;
+
+  @DurableGetter(Id = 3L)
+  public abstract Person<E> getMother() throws RetrieveDurableEntityError;
+
+  @DurableSetter
+  public abstract void setMother(Person<E> mother, boolean destroy) throws RetrieveDurableEntityError;
+
+  @DurableGetter(Id = 4L)
+  public abstract Person<E> getFather() throws RetrieveDurableEntityError;
+
+  @DurableSetter
+  public abstract void setFather(Person<E> mother, boolean destroy) throws RetrieveDurableEntityError;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/7dfa60b4/mnemonic-computing-services/mnemonic-utilities-service/src/test/resources/testng.xml
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/resources/testng.xml
b/mnemonic-computing-services/mnemonic-utilities-service/src/test/resources/testng.xml
new file mode 100644
index 0000000..e711968
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/resources/testng.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="Suite" verbose="1" parallel="tests" thread-count="1">
+  <test name="Test">
+    <classes>
+      <class name="org.apache.mnemonic.service.computingservice.DurableNodeValueNGPrintTest"/>

+    </classes>
+  </test> <!-- Test -->
+</suite> <!-- Suite -->
+
+
+<!--
+      <class name="org.apache.mnemonic.service.computingservice.DurableNodeValueNGPrintTest"/>

+ -->

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/7dfa60b4/mnemonic-computing-services/pom.xml
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/pom.xml b/mnemonic-computing-services/pom.xml
index 57d4fcb..300bfb0 100644
--- a/mnemonic-computing-services/pom.xml
+++ b/mnemonic-computing-services/pom.xml
@@ -99,6 +99,25 @@
             </execution>
           </executions>
         </plugin>
+        <plugin>
+          <groupId>org.bsc.maven</groupId>
+          <artifactId>maven-processor-plugin</artifactId>
+          <executions>
+            <execution>
+              <id>process-test</id>
+              <goals>
+                <goal>process-test</goal>
+              </goals>
+              <phase>generate-test-sources</phase>
+              <configuration>
+                <compilerArguments>-XDenableSunApiLintControl</compilerArguments>
+                <processors>
+                  <processor>${project.groupId}.DurableEntityProcessor</processor>
+                </processors>
+              </configuration>
+            </execution>
+          </executions>
+        </plugin>
       </plugins>
     </pluginManagement>
   </build>


Mime
View raw message