Skip to content

Commit

Permalink
KUDU-2411: Example integration test using KuduMiniCluster
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bpmcd authored and granthenke committed Mar 14, 2019
1 parent 5735f07 commit dc56ca5
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
36 changes: 35 additions & 1 deletion examples/java/java-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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. -->
Expand All @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -73,7 +73,7 @@ private static void createExampleTable(KuduClient client, String tableName) thr
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();
Expand Down Expand Up @@ -115,7 +115,7 @@ private static void insertRows(KuduClient client, String tableName, int numRows)
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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit dc56ca5

Please sign in to comment.