diff options
author | Luciano Resende <lresende@apache.org> | 2017-01-17 10:04:45 -0800 |
---|---|---|
committer | Luciano Resende <lresende@apache.org> | 2017-01-17 10:06:24 -0800 |
commit | 98ea7907bdf11b6529390b9b78d5f2f16153cfee (patch) | |
tree | 1b967e226e6f2cc8f8dd4a673d1f252ff7761f15 | |
parent | da95fc343d926585abd33f5fb3e5b0c7a6cee9bb (diff) | |
download | toree-gateway-98ea7907bdf11b6529390b9b78d5f2f16153cfee.tar.gz toree-gateway-98ea7907bdf11b6529390b9b78d5f2f16153cfee.tar.bz2 toree-gateway-98ea7907bdf11b6529390b9b78d5f2f16153cfee.zip |
Initial test cases
Note that these tests are disabled, as it requires proper
instance of Apache Toree running and connected to Apache Spark.
-rw-r--r-- | pom.xml | 7 | ||||
-rw-r--r-- | src/test/scala/com/ibm/ToreeClientSpec.scala | 104 |
2 files changed, 111 insertions, 0 deletions
@@ -53,6 +53,13 @@ <artifactId>slf4j-jdk14</artifactId> <version>1.7.5</version> </dependency> + + <dependency> + <groupId>org.scalatest</groupId> + <artifactId>scalatest_2.11</artifactId> + <version>3.0.1</version> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/src/test/scala/com/ibm/ToreeClientSpec.scala b/src/test/scala/com/ibm/ToreeClientSpec.scala new file mode 100644 index 0000000..859f2f7 --- /dev/null +++ b/src/test/scala/com/ibm/ToreeClientSpec.scala @@ -0,0 +1,104 @@ +/* + * (C) Copyright IBM Corp. 2017 + * + * Licensed 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 com.ibm + +import com.typesafe.config.{Config, ConfigFactory} +import org.apache.toree.kernel.protocol.v5.client.boot.ClientBootstrap +import org.apache.toree.kernel.protocol.v5.client.boot.layers.{StandardHandlerInitialization, StandardSystemInitialization} +import org.scalatest.{FlatSpec, Ignore} +import org.slf4j.LoggerFactory + +@Ignore +class ToreeClientSpec extends FlatSpec { + + final val log = LoggerFactory.getLogger(this.getClass.getName.stripSuffix("$")) + + + val profileJSON: String = """ + { + "stdin_port": 48701, + "control_port": 48702, + "hb_port": 48705, + "shell_port": 48703, + "iopub_port": 48704, + "ip": "9.125.72.72", + "transport": "tcp", + "signature_scheme": "hmac-sha256", + "key": "" + } + """.stripMargin + + val toreeGateway = { + // Parse our configuration and create a client connecting to our kernel + val config: Config = ConfigFactory.parseString(profileJSON) + + val client = (new ClientBootstrap(config) + with StandardSystemInitialization + with StandardHandlerInitialization).createClient() + + val toreeGateway = new ToreeGateway(client) + + toreeGateway + + } + + "gateway" should "receive dataframe show results" in { + val result = toreeGateway.eval( + """ + import org.apache.commons.io.IOUtils + import java.net.URL + import java.nio.charset.Charset + + val sqc = spark.sqlContext + import sqc.implicits._ + + val bankText = sc.parallelize( + IOUtils.toString( + new URL("https://s3.amazonaws.com/apache-zeppelin/tutorial/bank/bank.csv"), + Charset.forName("utf8")).split("\n")) + + case class Bank(age: Integer, job: String, marital: String, education: String, balance: Integer) + + val bank = bankText.map(s => s.split(";")).filter(s => s(0) != "\"age\"").map( + s => Bank(s(0).toInt, + s(1).replaceAll("\"", ""), + s(2).replaceAll("\"", ""), + s(3).replaceAll("\"", ""), + s(5).replaceAll("\"", "").toInt + ) + ).toDF() + + bank.show(1) + """.stripMargin + ).toString.stripMargin + + assert(result.contains("only showing top 1 row")) + } + + "gateway" should "receive error messages when exception is thrown" in { + val result = toreeGateway.eval( + """ + println(1/0) + """.stripMargin + ).toString.stripMargin + + assert(result.contains("java.lang.ArithmeticException")) + } + + +} |