Updated Branches: refs/heads/master eb4abac2a -> 07f705921
ACCUMULO-1166 improved instamo example unit test git-svn-id: https://svn.apache.org/repos/asf/accumulo/contrib/instamo-archetype/branches/1.4@1488037 13f79535-47bb-0310-9956-ffa450edef68 Project: http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/commit/75dbbd63 Tree: http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/tree/75dbbd63 Diff: http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/diff/75dbbd63 Branch: refs/heads/master Commit: 75dbbd63f055e99e69d0e46b15d8777dc98ac351 Parents: a48490e Author: Keith Turner <[email protected]> Authored: Thu May 30 22:11:41 2013 +0000 Committer: Keith Turner <[email protected]> Committed: Thu May 30 22:11:41 2013 +0000 ---------------------------------------------------------------------- README.md | 6 +- .../META-INF/maven/archetype-metadata.xml | 4 +- .../resources/archetype-resources/README.md | 5 +- src/main/resources/archetype-resources/pom.xml | 2 +- .../src/main/java/AccumuloApp.java | 62 -------------------- .../src/test/java/ExampleAccumuloUnitTest.java | 62 +++++++++++++++++++- 6 files changed, 70 insertions(+), 71 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/blob/75dbbd63/README.md ---------------------------------------------------------------------- diff --git a/README.md b/README.md index 71a0302..69688f4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,9 @@ Usage Checkout this project and run a `mvn install`. This will install the archetype to your local repository. -Then, change to a new directory and run `mvn archetype:generate --DarchetypeGroupId=org.apache.accumulo -DarchetypeArtifactId=instamo-archetype` +Then, change to a new directory and run + +`mvn archetype:generate -DarchetypeGroupId=org.apache.accumulo -DarchetypeArtifactId=instamo-archetype -DinteractiveMode=false` + and Maven will prompt you to enter the rest of the necessary configuration parameters (e.g. groupId, artifactId, version and Java package) http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/blob/75dbbd63/src/main/resources/META-INF/maven/archetype-metadata.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/src/main/resources/META-INF/maven/archetype-metadata.xml index 594bd9f..6f37215 100644 --- a/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -24,13 +24,13 @@ <defaultValue>org.apache.accumulo.instamo</defaultValue> </requiredProperty> <requiredProperty key="artifactId"> - <defaultValue>instamo-example</defaultValue> + <defaultValue>instamo</defaultValue> </requiredProperty> <requiredProperty key="version"> <defaultValue>1.0-SNAPSHOT</defaultValue> </requiredProperty> <requiredProperty key="package"> - <defaultValue>instamo.example</defaultValue> + <defaultValue>instamo</defaultValue> </requiredProperty> </requiredProperties> http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/blob/75dbbd63/src/main/resources/archetype-resources/README.md ---------------------------------------------------------------------- diff --git a/src/main/resources/archetype-resources/README.md b/src/main/resources/archetype-resources/README.md index 686203b..929c382 100644 --- a/src/main/resources/archetype-resources/README.md +++ b/src/main/resources/archetype-resources/README.md @@ -10,11 +10,12 @@ installation is required. This is possible if Java and Maven are already installed by following the steps below. ``` -vim src/main/java/${package}/AccumuloApp.java +vim src/test/java/${package}/ExampleAccumuloUnitTest.java mvn package ``` -After packing the code, you can run one of the below applications. +The maven package command will run the unit test. After packing the code, you +can also run one of the below applications. Map Reduce ---------- http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/blob/75dbbd63/src/main/resources/archetype-resources/pom.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/archetype-resources/pom.xml b/src/main/resources/archetype-resources/pom.xml index 7db8b8e..a42f616 100644 --- a/src/main/resources/archetype-resources/pom.xml +++ b/src/main/resources/archetype-resources/pom.xml @@ -86,7 +86,7 @@ <arguments> <argument>-classpath</argument> <classpath /> - <argument>instamo.example.ShellExample</argument> + <argument>${package}.ShellExample</argument> </arguments> </configuration> </plugin> http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/blob/75dbbd63/src/main/resources/archetype-resources/src/main/java/AccumuloApp.java ---------------------------------------------------------------------- diff --git a/src/main/resources/archetype-resources/src/main/java/AccumuloApp.java b/src/main/resources/archetype-resources/src/main/java/AccumuloApp.java deleted file mode 100644 index bb99aa5..0000000 --- a/src/main/resources/archetype-resources/src/main/java/AccumuloApp.java +++ /dev/null @@ -1,62 +0,0 @@ -#set( $symbol_pound = '#' ) -#set( $symbol_dollar = '$' ) -#set( $symbol_escape = '\' ) -/* - * 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 ${package}; - -import java.util.Map.Entry; - -import org.apache.accumulo.core.Constants; -import org.apache.accumulo.core.client.BatchWriter; -import org.apache.accumulo.core.client.Connector; -import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.Scanner; -import org.apache.accumulo.core.client.ZooKeeperInstance; -import org.apache.accumulo.core.data.Key; -import org.apache.accumulo.core.data.Mutation; -import org.apache.accumulo.core.data.Value; - -public class AccumuloApp { - private static final Long MAX_MEMORY = 50 * 1024 * 1024l; - private static final Long MAX_LATENCY = 2 * 60 * 1000l; - private static final Integer MAX_WRITE_THREADS = 3; - - public static void run(String instanceName, String zookeepers, byte[] password, String args[]) throws Exception { - // edit this method to play with Accumulo - - Instance instance = new ZooKeeperInstance(instanceName, zookeepers); - - Connector conn = instance.getConnector("root", password); - - conn.tableOperations().create("foo"); - - BatchWriter bw = conn.createBatchWriter("foo", MAX_MEMORY, MAX_LATENCY, MAX_WRITE_THREADS); - Mutation m = new Mutation("r1"); - m.put("cf1", "cq1", "v1"); - m.put("cf1", "cq2", "v3"); - bw.addMutation(m); - bw.close(); - - Scanner scanner = conn.createScanner("foo", Constants.NO_AUTHS); - for (Entry<Key,Value> entry : scanner) { - System.out.println(entry.getKey() + " " + entry.getValue()); - } - - conn.tableOperations().delete("foo"); - } -} http://git-wip-us.apache.org/repos/asf/accumulo-instamo-archetype/blob/75dbbd63/src/main/resources/archetype-resources/src/test/java/ExampleAccumuloUnitTest.java ---------------------------------------------------------------------- diff --git a/src/main/resources/archetype-resources/src/test/java/ExampleAccumuloUnitTest.java b/src/main/resources/archetype-resources/src/test/java/ExampleAccumuloUnitTest.java index a59c5ac..e3c6d90 100644 --- a/src/main/resources/archetype-resources/src/test/java/ExampleAccumuloUnitTest.java +++ b/src/main/resources/archetype-resources/src/test/java/ExampleAccumuloUnitTest.java @@ -19,7 +19,19 @@ */ package ${package}; +import java.util.Map.Entry; + +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.core.client.BatchWriter; +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.Scanner; +import org.apache.accumulo.core.client.ZooKeeperInstance; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Value; import org.apache.accumulo.minicluster.MiniAccumuloCluster; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -48,7 +60,54 @@ public class ExampleAccumuloUnitTest { @Test(timeout = 30000) public void test() throws Exception { - AccumuloApp.run(accumulo.getInstanceName(), accumulo.getZooKeepers(), "superSecret".getBytes(), new String[0]); + // edit this method to play with Accumulo + + Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers()); + + Connector conn = instance.getConnector("root", "superSecret"); + + conn.tableOperations().create("foo"); + + BatchWriter bw = conn.createBatchWriter("foo", 10000000, 60000, 3); + Mutation m = new Mutation("1234"); + m.put("name", "first", "Alice"); + m.put("friend", "5678", ""); + m.put("enemy", "5555", ""); + m.put("enemy", "9999", ""); + bw.addMutation(m); + + m = new Mutation("5678"); + m.put("name", "first", "Bob"); + m.put("friend", "1234", ""); + m.put("enemy", "5555", ""); + m.put("enemy", "9999", ""); + bw.addMutation(m); + + m = new Mutation("9999"); + m.put("name", "first", "Eve"); + m.put("friend", "5555", ""); + m.put("enemy", "1234", ""); + m.put("enemy", "5678", ""); + bw.addMutation(m); + + m = new Mutation("5555"); + m.put("name", "first", "Mallory"); + m.put("friend", "9999", ""); + m.put("enemy", "1234", ""); + m.put("enemy", "5678", ""); + bw.addMutation(m); + + bw.close(); + + Scanner scanner = conn.createScanner("foo", Constants.NO_AUTHS); + for (Entry<Key,Value> entry : scanner) { + System.out.println(entry.getKey() + " " + entry.getValue()); + } + + //TODO use scanner to find common enemie ids between Alice and Bob, then + //use BatchScanner to look up their names + + conn.tableOperations().delete("foo"); } @AfterClass @@ -56,5 +115,4 @@ public class ExampleAccumuloUnitTest { accumulo.stop(); folder.delete(); } - }
