From 6a308ad80078cbbe297ddbde6f8346c92cf9705c Mon Sep 17 00:00:00 2001 From: Matthew Tovbin Date: Wed, 15 Aug 2018 09:00:44 -0700 Subject: [PATCH] Some minor test corrections (#57) --- .../op/utils/numeric/NumberTest.scala | 19 ++++++++++++------- .../op/utils/spark/OpSparkListenerTest.scala | 19 +++++++++++++------ .../op/utils/tuples/RichTupleTest.scala | 5 +++-- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/utils/src/test/scala/com/salesforce/op/utils/numeric/NumberTest.scala b/utils/src/test/scala/com/salesforce/op/utils/numeric/NumberTest.scala index 54cfbdd8c2..9d455ce847 100644 --- a/utils/src/test/scala/com/salesforce/op/utils/numeric/NumberTest.scala +++ b/utils/src/test/scala/com/salesforce/op/utils/numeric/NumberTest.scala @@ -37,16 +37,21 @@ import org.scalatest.{Matchers, PropSpec} @RunWith(classOf[JUnitRunner]) class NumberTest extends PropSpec with PropertyChecks with Matchers { - val tests = Table( - "TestNumbers", - 0.0, - Double.MaxValue, - Double.NegativeInfinity, - Double.NaN + + val specials = Table("specials", + Double.MinValue, Double.MaxValue, + Double.MinPositiveValue, Double.NaN, + Double.PositiveInfinity, Double.NegativeInfinity ) property("validate numbers") { - forAll(tests) { d => + forAll { d: Double => + Number.isValid(d) should not be (d.isInfinity || d.isNaN) + } + } + + property("validate special numbers") { + forAll(specials) { d => Number.isValid(d) should not be (d.isInfinity || d.isNaN) } } diff --git a/utils/src/test/scala/com/salesforce/op/utils/spark/OpSparkListenerTest.scala b/utils/src/test/scala/com/salesforce/op/utils/spark/OpSparkListenerTest.scala index 127aed588f..d0504d5470 100644 --- a/utils/src/test/scala/com/salesforce/op/utils/spark/OpSparkListenerTest.scala +++ b/utils/src/test/scala/com/salesforce/op/utils/spark/OpSparkListenerTest.scala @@ -31,15 +31,17 @@ package com.salesforce.op.utils.spark import com.salesforce.op.test.TestSparkContext +import com.salesforce.op.utils.date.DateTimeUtils import org.junit.runner.RunWith import org.scalatest.FlatSpec import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) class OpSparkListenerTest extends FlatSpec with TestSparkContext { + val start = DateTimeUtils.now().getMillis val listener = new OpSparkListener(sc.appName, sc.applicationId, "testRun", Some("tag"), Some("tagValue"), true, true) sc.addSparkListener(listener) - spark.read.csv(s"$testDataDir/PassengerDataAll.csv") + val _ = spark.read.csv(s"$testDataDir/PassengerDataAll.csv").count() Spec[OpSparkListener] should "capture app metrics" in { val appMetrics: AppMetrics = listener.metrics @@ -48,14 +50,19 @@ class OpSparkListenerTest extends FlatSpec with TestSparkContext { appMetrics.runType shouldBe "testRun" appMetrics.customTagName shouldBe Some("tag") appMetrics.customTagValue shouldBe Some("tagValue") + appMetrics.appStartTime should be >= start + appMetrics.appEndTime should be >= appMetrics.appStartTime + appMetrics.appDuration shouldBe (appMetrics.appEndTime - appMetrics.appStartTime) + appMetrics.appDurationPretty.isEmpty shouldBe false } it should "capture app stage metrics" in { val stageMetrics = listener.metrics.stageMetrics - stageMetrics.size shouldBe 1 - stageMetrics.head.name startsWith "csv at OpSparkListenerTest.scala" - stageMetrics.head.stageId shouldBe 0 - stageMetrics.head.numTasks shouldBe 1 - stageMetrics.head.status shouldBe "succeeded" + stageMetrics.size should be > 0 + val firstStage = stageMetrics.head + firstStage.name should startWith("csv at OpSparkListenerTest.scala") + firstStage.stageId shouldBe 0 + firstStage.numTasks shouldBe 1 + firstStage.status shouldBe "succeeded" } } diff --git a/utils/src/test/scala/com/salesforce/op/utils/tuples/RichTupleTest.scala b/utils/src/test/scala/com/salesforce/op/utils/tuples/RichTupleTest.scala index fac31b43fb..cf8117a8bf 100644 --- a/utils/src/test/scala/com/salesforce/op/utils/tuples/RichTupleTest.scala +++ b/utils/src/test/scala/com/salesforce/op/utils/tuples/RichTupleTest.scala @@ -43,8 +43,9 @@ class RichTupleTest extends FlatSpec with TestCommon { res.get shouldBe 3 } - it should "not map empty tuples" in { - assertDoesNotCompile("(None, None).map((x, y) => x + y)") + it should "map on empty tuples" in { + val none: (Option[String], Option[String]) = None -> None + none.map((x, y) => x + y) shouldBe None } it should "map the function with no effect for left param alone" in {