This is an automated email from the ASF dual-hosted git repository.
granthenke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new dc56ca5 KUDU-2411: Example integration test using KuduMiniCluster
dc56ca5 is described below
commit dc56ca54c3b838c0d15fb26969a6db3b8123007b
Author: Brian McDevitt <[email protected]>
AuthorDate: Wed Jan 30 16:11:31 2019 -0600
KUDU-2411: Example integration test using KuduMiniCluster
Adds an example of using the Kudu binary Jar to execute integration tests
against a KuduMiniCluster.
Change-Id: Ife9103557b30b4105ef57ed36a34f3c93ba2dc6d
Reviewed-on: http://gerrit.cloudera.org:8080/12318
Reviewed-by: Grant Henke <[email protected]>
Tested-by: Grant Henke <[email protected]>
---
examples/java/java-example/pom.xml | 36 +++++++++++++++-
.../java/org/apache/kudu/examples/Example.java | 6 +--
.../java/org/apache/kudu/examples/ExampleTest.java | 49 ++++++++++++++++++++++
3 files changed, 87 insertions(+), 4 deletions(-)
diff --git a/examples/java/java-example/pom.xml
b/examples/java/java-example/pom.xml
index 67b0754..f6254d4 100644
--- a/examples/java/java-example/pom.xml
+++ b/examples/java/java-example/pom.xml
@@ -27,6 +27,10 @@
<version>1.0-SNAPSHOT</version>
<name>Kudu Java Client Examples</name>
+ <properties>
+ <kudu-version>1.9.0</kudu-version>
+ </properties>
+
<build>
<plugins>
<plugin>
@@ -59,13 +63,21 @@
</executions>
</plugin>
</plugins>
+ <extensions>
+ <!-- Used to find the right kudu-binary artifact with the property
os.detected.classifier -->
+ <extension>
+ <groupId>kr.motd.maven</groupId>
+ <artifactId>os-maven-plugin</artifactId>
+ <version>1.6.1</version>
+ </extension>
+ </extensions>
</build>
<dependencies>
<dependency>
<groupId>org.apache.kudu</groupId>
<artifactId>kudu-client</artifactId>
- <version>1.7.0</version>
+ <version>${kudu-version}</version>
</dependency>
<!-- For logging messages. -->
@@ -74,5 +86,27 @@
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.kudu</groupId>
+ <artifactId>kudu-test-utils</artifactId>
+ <version>${kudu-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kudu</groupId>
+ <artifactId>kudu-binary</artifactId>
+ <version>${kudu-version}</version>
+ <scope>test</scope>
+ <classifier>${os.detected.classifier}</classifier>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/examples/java/java-example/src/main/java/org/apache/kudu/examples/Example.java
b/examples/java/java-example/src/main/java/org/apache/kudu/examples/Example.java
index 0805c12..9d6e2a1 100644
---
a/examples/java/java-example/src/main/java/org/apache/kudu/examples/Example.java
+++
b/examples/java/java-example/src/main/java/org/apache/kudu/examples/Example.java
@@ -49,7 +49,7 @@ public class Example {
private static final Double DEFAULT_DOUBLE = 12.345;
private static final String KUDU_MASTERS = System.getProperty("kuduMasters",
"localhost:7051");
- private static void createExampleTable(KuduClient client, String tableName)
throws KuduException {
+ static void createExampleTable(KuduClient client, String tableName) throws
KuduException {
// Set up a simple schema.
List<ColumnSchema> columns = new ArrayList<>(2);
columns.add(new ColumnSchema.ColumnSchemaBuilder("key", Type.INT32)
@@ -73,7 +73,7 @@ public class Example {
System.out.println("Created table " + tableName);
}
- private static void insertRows(KuduClient client, String tableName, int
numRows) throws KuduException {
+ static void insertRows(KuduClient client, String tableName, int numRows)
throws KuduException {
// Open the newly-created table and create a KuduSession.
KuduTable table = client.openTable(tableName);
KuduSession session = client.newSession();
@@ -115,7 +115,7 @@ public class Example {
System.out.println("Inserted " + numRows + " rows");
}
- private static void scanTableAndCheckResults(KuduClient client, String
tableName, int numRows) throws KuduException {
+ static void scanTableAndCheckResults(KuduClient client, String tableName,
int numRows) throws KuduException {
KuduTable table = client.openTable(tableName);
Schema schema = table.getSchema();
diff --git
a/examples/java/java-example/src/test/java/org/apache/kudu/examples/ExampleTest.java
b/examples/java/java-example/src/test/java/org/apache/kudu/examples/ExampleTest.java
new file mode 100644
index 0000000..c1a88f1
--- /dev/null
+++
b/examples/java/java-example/src/test/java/org/apache/kudu/examples/ExampleTest.java
@@ -0,0 +1,49 @@
+// 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.kudu.examples;
+
+import static org.junit.Assert.assertTrue;
+
+import org.apache.kudu.client.KuduException;
+import org.apache.kudu.test.KuduTestHarness;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * An example integration test class that spins up a local Kudu cluster.<br/>
+ * <br/>
+ * See the <a
href="https://kudu.apache.org/docs/developing.html#_jvm_based_integration_testing">JVM
Testing Docs</a>
+ * for more details.
+ */
+public class ExampleTest {
+
+ /**
+ * A Junit Rule that manages a Kudu cluster and clients for testing.
+ * This rule also includes utility methods for the cluster
+ * and clients.
+ */
+ @Rule
+ public KuduTestHarness harness = new KuduTestHarness();
+
+ @Test
+ public void testCreateExampleTable() throws KuduException {
+ String tableName = "test_create_example";
+ Example.createExampleTable(harness.getClient(), tableName);
+ assertTrue(harness.getClient().tableExists(tableName));
+ }
+}