diff options
author | Luciano Resende <lresende@apache.org> | 2017-01-17 22:11:21 -0800 |
---|---|---|
committer | Luciano Resende <lresende@apache.org> | 2017-01-17 22:11:21 -0800 |
commit | 87fe76dcd9c92c336f65cff3b9511d01f73e7421 (patch) | |
tree | 0a24619b983df4e6a90921da64e5fde3b7832f75 /src/test/scala/com/ibm/ToreeGatewaySpec.scala | |
parent | eff52a90bc2f14dffbca9881d637c3ff8c478085 (diff) | |
download | toree-gateway-87fe76dcd9c92c336f65cff3b9511d01f73e7421.tar.gz toree-gateway-87fe76dcd9c92c336f65cff3b9511d01f73e7421.tar.bz2 toree-gateway-87fe76dcd9c92c336f65cff3b9511d01f73e7421.zip |
Use consistent naming pattern around the project
Diffstat (limited to 'src/test/scala/com/ibm/ToreeGatewaySpec.scala')
-rw-r--r-- | src/test/scala/com/ibm/ToreeGatewaySpec.scala | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/test/scala/com/ibm/ToreeGatewaySpec.scala b/src/test/scala/com/ibm/ToreeGatewaySpec.scala new file mode 100644 index 0000000..4ea0ada --- /dev/null +++ b/src/test/scala/com/ibm/ToreeGatewaySpec.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 ToreeGatewaySpec 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")) + } + + +} |