Skip to content
Permalink
Browse files
ACCUMULO-1166 improved instamo example unit test
  • Loading branch information
keith-turner committed May 30, 2013
1 parent 264f6c4 commit f7bbe5efb91e45ce7ee1a51b7ba09ef95d3ea035
Showing 6 changed files with 68 additions and 69 deletions.
@@ -15,7 +15,7 @@ to your local repository.

Then, change to a new directory and run

`mvn archetype:generate -DarchetypeGroupId=org.apache.accumulo -DarchetypeArtifactId=instamo-archetype`
`mvn archetype:generate -DarchetypeGroupId=org.apache.accumulo -DarchetypeArtifactId=instamo-archetype -DinteractiveMode=false`

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

This file was deleted.

@@ -19,8 +19,21 @@
*/
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.BatchWriterConfig;
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.client.security.tokens.PasswordToken;
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;
@@ -49,13 +62,59 @@ public static void setupMiniCluster() throws Exception {

@Test(timeout = 30000)
public void test() throws Exception {
AccumuloApp.run(accumulo.getInstanceName(), accumulo.getZooKeepers(), new PasswordToken("superSecret"), new String[0]);
// edit this method to play with Accumulo

Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());

Connector conn = instance.getConnector("root", new PasswordToken("superSecret"));

conn.tableOperations().create("foo");

BatchWriter bw = conn.createBatchWriter("foo", new BatchWriterConfig());
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 f7bbe5e

Please sign in to comment.