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 557f070 KUDU-3085: Create Scala/SBT integration test example.
557f070 is described below
commit 557f0703e0a98d3d38b00f9416bfbcbc742478c1
Author: Brian McDevitt <[email protected]>
AuthorDate: Mon Mar 23 14:19:47 2020 -0500
KUDU-3085: Create Scala/SBT integration test example.
This example demonstrates the SBT configuration needed to use the
kudu-binary JAR for
integration testing.
Change-Id: Ia0ac7abef89c70c5989bd6cb894c8989ed167ec8
Reviewed-on: http://gerrit.cloudera.org:8080/15535
Reviewed-by: Grant Henke <[email protected]>
Tested-by: Grant Henke <[email protected]>
---
examples/scala/sbt-int-test-example/README.adoc | 100 +++++++++++++++++++++
examples/scala/sbt-int-test-example/build.sbt | 37 ++++++++
.../sbt-int-test-example/project/build.properties | 19 ++++
.../scala/sbt-int-test-example/project/plugins.sbt | 21 +++++
.../src/it/resources/logback.xml | 31 +++++++
.../kudu/scala/examples/KuduExampleITest.scala | 47 ++++++++++
.../apache/kudu/scala/examples/KuduExample.scala | 45 ++++++++++
7 files changed, 300 insertions(+)
diff --git a/examples/scala/sbt-int-test-example/README.adoc
b/examples/scala/sbt-int-test-example/README.adoc
new file mode 100644
index 0000000..435abab
--- /dev/null
+++ b/examples/scala/sbt-int-test-example/README.adoc
@@ -0,0 +1,100 @@
+// 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.
+
+= SBT Integration Test example README
+
+This is an example program that uses the Kudu test utilities to demonstrate
integration testing
+in a Scala/SBT application:
+
+- Create a table
+
+To run the example integration tests, ensure SBT is installed and execute
+the following from the 'sbt-int-test-example' directory. This will execute all
Scalatest test classes
+in the 'src/it/scala' directory:
+
+[source,bash]
+----
+$ sbt it:test
+----
+
+
+== Configuration
+To configure SBT for retrieving the correct kudu testing binary jar, there is
a required SBT plugin:
+
+[source,sbt]
+.project/plugins.sbt
+----
+resolvers += "phData Releases" at
"https://repository.phdata.io/artifactory/libs-release" //<1>
+classpathTypes += "maven-plugin"
//<2>
+addSbtPlugin("io.phdata" % "sbt-os-detector" % "0.2.0")
//<3>
+----
+<1> Include an additional repository for plugin resolution
+<2> Include dependencies that are of type 'maven-plugin' which is required to
resolve https://github.com/trustin/os-maven-plugin[OS Maven Plugin]
+<3> The https://github.com/phdata/sbt-os-detector[SBT OS Detector] plugin
+
+In the `build.sbt`, include the dependencies for kudu-test-utils and
kudu-binary:
+[source,sbt]
+----
+
+lazy val root = (project in file("."))
+ .configs(IntegrationTest)
+ .enablePlugins(OsDetectorPlugin) //<1>
+ .settings(
+ Defaults.itSettings,
+ name := "sbt-int-test-example",
+ libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" %
"it,test",
+ libraryDependencies += "org.apache.kudu" % "kudu-client" % "1.11.1",
+ libraryDependencies += "org.apache.kudu" % "kudu-test-utils" % "1.11.1" %
"it", //<2>
+ libraryDependencies += "org.apache.kudu" % "kudu-binary" % "1.11.1" % "it"
classifier osDetectorClassifier.value, //<3>
+ libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3",
+ )
+----
+<1> Enable the SBT OS Detector plugin
+<2> Provides utilities for working with the Kudu test cluster
+<3> `kudu-binary` dependency that matches the current operating system. Note:
Linux and MacOS are
+the only compile targets for Kudu.
+
+Once dependencies are resolved, creating integration tests are straightforward:
+[source,scala]
+----
+class KuduExampleITest extends FunSuite with BeforeAndAfter {
+
+ private val harness = new KuduTestHarness() //<1>
+
+ before {
+ harness.before() //<3>
+ }
+
+ after {
+ harness.after() //<3>
+ }
+
+ test("create table example") {
+ val kuduExample = new KuduExample(harness.getClient) //<2>
+ val tableName = "testMovies"
+ val testMovieTable = kuduExample.createMovieTable(tableName)
+ testMovieTable match {
+ case Failure(exception) => fail(exception)
+ case Success(table) => assertResult(tableName)(table.getName)
+ }
+ }
+}
+----
+<1> Create a new instance of the `KuduTestHarness` to use the default settings
of the `MiniKuduCluster`
+<2> Kudu clients (both sync and async) are provided automatically by the test
harness
+<3> Ensure your `MiniKuduCluster` is properly started and terminated after
testing.
+
diff --git a/examples/scala/sbt-int-test-example/build.sbt
b/examples/scala/sbt-int-test-example/build.sbt
new file mode 100644
index 0000000..4624981
--- /dev/null
+++ b/examples/scala/sbt-int-test-example/build.sbt
@@ -0,0 +1,37 @@
+//
+// 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.
+
+import sbt._
+
+ThisBuild / scalaVersion := "2.12.10"
+ThisBuild / version := "0.1.0-SNAPSHOT"
+ThisBuild / organization := "org.apache.kudu"
+ThisBuild / organizationName := "Apache Kudu"
+
+lazy val root = (project in file("."))
+ .configs(IntegrationTest)
+ .enablePlugins(OsDetectorPlugin)
+ .settings(
+ Defaults.itSettings,
+ name := "sbt-int-test-example",
+ libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" %
"it,test",
+ libraryDependencies += "org.apache.kudu" % "kudu-client" % "1.11.1",
+ libraryDependencies += "org.apache.kudu" % "kudu-test-utils" % "1.11.1" %
"it",
+ libraryDependencies += "org.apache.kudu" % "kudu-binary" % "1.11.1" % "it"
classifier osDetectorClassifier.value,
+ libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3",
+ )
diff --git a/examples/scala/sbt-int-test-example/project/build.properties
b/examples/scala/sbt-int-test-example/project/build.properties
new file mode 100644
index 0000000..ea5b0ac
--- /dev/null
+++ b/examples/scala/sbt-int-test-example/project/build.properties
@@ -0,0 +1,19 @@
+#
+# 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.
+
+sbt.version=1.3.8
diff --git a/examples/scala/sbt-int-test-example/project/plugins.sbt
b/examples/scala/sbt-int-test-example/project/plugins.sbt
new file mode 100644
index 0000000..0ad21fc
--- /dev/null
+++ b/examples/scala/sbt-int-test-example/project/plugins.sbt
@@ -0,0 +1,21 @@
+//
+// 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.
+
+resolvers += "phData Releases" at
"https://repository.phdata.io/artifactory/libs-release"
+classpathTypes += "maven-plugin"
+addSbtPlugin("io.phdata" % "sbt-os-detector" % "0.2.0")
diff --git a/examples/scala/sbt-int-test-example/src/it/resources/logback.xml
b/examples/scala/sbt-int-test-example/src/it/resources/logback.xml
new file mode 100644
index 0000000..9dde0c3
--- /dev/null
+++ b/examples/scala/sbt-int-test-example/src/it/resources/logback.xml
@@ -0,0 +1,31 @@
+<configuration>
+ <!--
+ //
+ // 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.
+ -->
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
%msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="STDOUT"/>
+ </root>
+</configuration>
\ No newline at end of file
diff --git
a/examples/scala/sbt-int-test-example/src/it/scala/org/apache/kudu/scala/examples/KuduExampleITest.scala
b/examples/scala/sbt-int-test-example/src/it/scala/org/apache/kudu/scala/examples/KuduExampleITest.scala
new file mode 100644
index 0000000..cd333ee
--- /dev/null
+++
b/examples/scala/sbt-int-test-example/src/it/scala/org/apache/kudu/scala/examples/KuduExampleITest.scala
@@ -0,0 +1,47 @@
+//
+// 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.scala.examples
+
+import org.apache.kudu.test.KuduTestHarness
+import org.scalatest.{BeforeAndAfter, FunSuite}
+
+import scala.util.{Failure, Success}
+
+class KuduExampleITest extends FunSuite with BeforeAndAfter {
+
+ private val harness = new KuduTestHarness()
+
+ before {
+ harness.before()
+ }
+
+ after {
+ harness.after()
+ }
+
+ test("create table example") {
+ val kuduExample = new KuduExample(harness.getClient)
+ val tableName = "testMovies"
+ val testMovieTable = kuduExample.createMovieTable(tableName)
+ testMovieTable match {
+ case Failure(exception) => fail(exception)
+ case Success(table) => assertResult(tableName)(table.getName)
+ }
+ }
+}
diff --git
a/examples/scala/sbt-int-test-example/src/main/scala/org/apache/kudu/scala/examples/KuduExample.scala
b/examples/scala/sbt-int-test-example/src/main/scala/org/apache/kudu/scala/examples/KuduExample.scala
new file mode 100644
index 0000000..b8d9175
--- /dev/null
+++
b/examples/scala/sbt-int-test-example/src/main/scala/org/apache/kudu/scala/examples/KuduExample.scala
@@ -0,0 +1,45 @@
+//
+// 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.scala.examples
+
+import org.apache.kudu.ColumnSchema.ColumnSchemaBuilder
+import org.apache.kudu.client.{CreateTableOptions, KuduClient, KuduTable}
+import org.apache.kudu.{Schema, Type}
+
+import scala.collection.JavaConverters._
+import scala.util.Try
+
+class KuduExample(client: KuduClient) {
+
+ private val cols = Seq(
+ new ColumnSchemaBuilder("id", Type.INT64).key(true).build(),
+ new ColumnSchemaBuilder("title", Type.STRING).build(),
+ new ColumnSchemaBuilder("subtitle", Type.STRING).nullable(true).build(),
+ new ColumnSchemaBuilder("releaseDate", Type.STRING).build(),
+ new ColumnSchemaBuilder("director", Type.STRING).build()
+ )
+
+ def createMovieTable(name: String): Try[KuduTable] = {
+
+ val schema = new Schema(cols.asJava)
+ val options = new CreateTableOptions
+ options.addHashPartitions(List("id").asJava, 2)
+ Try(client.createTable(name, schema, options))
+ }
+}