Skip to content
Permalink
Browse files
ACCUMULO-1166 improved instamo example unit test
  • Loading branch information
keith-turner committed May 30, 2013
1 parent a48490e commit 75dbbd63f055e99e69d0e46b15d8777dc98ac351
Showing 6 changed files with 70 additions and 71 deletions.
@@ -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)
@@ -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>

@@ -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
----------
@@ -86,7 +86,7 @@
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>instamo.example.ShellExample</argument>
<argument>${package}.ShellExample</argument>
</arguments>
</configuration>
</plugin>

This file was deleted.

@@ -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,13 +60,59 @@ public static void setupMiniCluster() throws Exception {

@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
public static void tearDownMiniCluster() throws Exception {
accumulo.stop();
folder.delete();
}

}

0 comments on commit 75dbbd6

Please sign in to comment.