Merge branch 'master' into lazy_logging

This commit is contained in:
Francisco Arámburo
2019-12-06 14:54:46 +01:00
committed by GitHub
14 changed files with 72 additions and 85 deletions

View File

@@ -1,24 +1,24 @@
package com.ing.baker.types.modules
import com.ing.baker.types
import com.ing.baker.types.{Converters, Int64}
import com.ing.baker.types.Converters
import org.joda.time.{DateTime, LocalDate, LocalDateTime}
import org.scalacheck.Gen
import org.scalacheck.Test.Parameters.defaultVerbose
import org.scalatest.prop.Checkers
import org.scalatest.{Matchers, WordSpecLike}
import org.scalatestplus.scalacheck.Checkers
class JodaTimeModuleSpec extends WordSpecLike with Matchers with Checkers {
val minSuccessfulTests = 100
private val minSuccessfulTests = 100
// Long.MaxValue is not supported by joda time for local dates, resulting in a integer overflow
// This shifts the long max value 1 bit to the right (divides by 2)
// This translates to the date: Fri Apr 24 17:36:27 CEST 146140482
val maxMillis = Long.MaxValue >> 1
private val maxMillis = Long.MaxValue >> 1
val numGen: Gen[Long] = Gen.chooseNum[Long](
private val numGen: Gen[Long] = Gen.chooseNum[Long](
0L, maxMillis, 0, maxMillis
)

View File

@@ -9,7 +9,7 @@ import com.ing.baker.types.modules.PrimitiveModuleSpec._
import org.scalacheck.Gen
import org.scalacheck.Prop.{BooleanOperators, forAll}
import org.scalacheck.Test.Parameters.defaultVerbose
import org.scalatest.prop.Checkers
import org.scalatestplus.scalacheck.Checkers
import org.scalatest.{Matchers, WordSpecLike}
import scala.reflect.runtime.universe.TypeTag
@@ -17,15 +17,15 @@ import scala.reflect.runtime.universe.TypeTag
object PrimitiveModuleSpec {
val intGen: Gen[Int] = Gen.chooseNum[Int](Integer.MIN_VALUE, Integer.MAX_VALUE)
val langIntegerGen: Gen[lang.Integer] = intGen.map(Int.box(_))
val langIntegerGen: Gen[lang.Integer] = intGen.map(Int.box)
val longGen: Gen[Long] = Gen.chooseNum[Long](Long.MinValue, Long.MaxValue)
val langLongGen: Gen[lang.Long] = Gen.chooseNum[Long](Long.MinValue, Long.MaxValue).map(Long.box(_))
val langLongGen: Gen[lang.Long] = Gen.chooseNum[Long](Long.MinValue, Long.MaxValue).map(Long.box)
val shortGen: Gen[Short] = Gen.chooseNum[Short](Short.MinValue, Short.MaxValue)
val langShortGen: Gen[lang.Short] = shortGen.map(Short.box(_))
val langShortGen: Gen[lang.Short] = shortGen.map(Short.box)
val floatGen: Gen[Float] = Gen.chooseNum(Float.MinValue, Float.MaxValue)
val langFloatGen: Gen[lang.Float] = floatGen.map(Float.box(_))
val langFloatGen: Gen[lang.Float] = floatGen.map(Float.box)
val doubleGen: Gen[Double] = Gen.chooseNum[Double](Double.MinValue, Double.MaxValue)
val langDoubleGen: Gen[lang.Double] = doubleGen.map(Double.box(_))
val langDoubleGen: Gen[lang.Double] = doubleGen.map(Double.box)
val stringGen: Gen[String] = Gen.alphaStr
val bigIntGen: Gen[BigInt] = longGen.map(BigInt(_))
val javaBigIntGen: Gen[java.math.BigInteger] = bigIntGen.map(_.bigInteger)

View File

@@ -3,22 +3,22 @@ package com.ing.baker.types.modules
import com.ing.baker.types
import com.ing.baker.types.Converters.{readJavaType, toJava, toValue}
import com.ing.baker.types._
import org.scalatest.prop.Checkers
import org.scalatest.{Matchers, WordSpecLike}
import org.scalatestplus.scalacheck.Checkers
class ScalaModulesSpec extends WordSpecLike with Matchers with Checkers {
val listValue123 = ListValue(List(PrimitiveValue(1), PrimitiveValue(2), PrimitiveValue(3)))
private val listValue123 = ListValue(List(PrimitiveValue(1), PrimitiveValue(2), PrimitiveValue(3)))
val recordPerson = RecordValue(Map("name" -> PrimitiveValue("john"), "age" -> PrimitiveValue(42)))
private val recordPerson = RecordValue(Map("name" -> PrimitiveValue("john"), "age" -> PrimitiveValue(42)))
val valueMap = RecordValue(Map(
private val valueMap = RecordValue(Map(
"a" -> PrimitiveValue(1),
"b" -> PrimitiveValue(2),
"c" -> PrimitiveValue(3)
))
val scalaMap = Map(
private val scalaMap = Map(
"a" -> 1,
"b" -> 2,
"c" -> 3
@@ -35,24 +35,20 @@ class ScalaModulesSpec extends WordSpecLike with Matchers with Checkers {
}
"correctly parse set types" in {
readJavaType[Set[String]] shouldBe ListType(types.CharArray)
readJavaType[java.util.Set[String]] shouldBe ListType(types.CharArray)
}
"correctly parse map types" in {
readJavaType[Map[String, Int]] shouldBe MapType(types.Int32)
readJavaType[java.util.Map[String, Int]] shouldBe MapType(types.Int32)
}
"be able to autobox null values to scala Options" in {
toJava[Option[Int]](NullValue) shouldBe None
}
"be able to autobox primitive values to scala Options" in {
toJava[Option[Int]](PrimitiveValue(42)) shouldBe Some(42)
}
@@ -61,42 +57,34 @@ class ScalaModulesSpec extends WordSpecLike with Matchers with Checkers {
}
"be able to parse scala.collection.immutable.List objects" in {
toValue(List(1, 2, 3)) shouldBe listValue123
}
"be able to create scala.collection.immutable.List objects" in {
toJava[List[Int]](listValue123) shouldBe List(1, 2, 3)
}
"be able to parse scala.collection.immutable.Set objects" in {
toValue(Set(1, 2, 3)) shouldBe listValue123
}
"be able to create scala.collection.immutable.Set objects" in {
toJava[Set[Int]](listValue123) shouldBe Set(1, 2, 3)
}
"be able to parse case class objects" in {
toValue(PersonCaseClass("john", 42)) shouldBe recordPerson
}
"be able to create case class objects" in {
toJava[PersonCaseClass](recordPerson) shouldBe PersonCaseClass("john", 42)
}
"be able to parse scala.collection.immutable.Map objects" in {
toValue(scalaMap) shouldBe valueMap
}
"be able to create scala.collection.immutable.Map objects" in {
toJava[Map[String, Int]](valueMap) shouldBe scalaMap
}
}

View File

@@ -2,13 +2,9 @@ package com.ing.baker.il
import org.scalacheck.{Gen, Prop, Test}
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import org.scalatestplus.scalacheck.Checkers
class HashcodeGenerationSpec extends FunSuite with Checkers {
// def hash(str: String): Long = str.hashCode // Test fails with this hash function
def hash(str: String): Long = sha256HashCode(str)
test("sha256 hash function") {
val prop = Prop.forAll(Gen.alphaNumStr, Gen.alphaNumStr) {
(s1: String, s2: String) => {
@@ -20,7 +16,5 @@ class HashcodeGenerationSpec extends FunSuite with Checkers {
check(prop, Test.Parameters.defaultVerbose.withMinSuccessfulTests(100 * 1000))
}
// test("test2") {
// assert("sr".hashCode != "u4".hashCode)
// }
private def hash(str: String): Long = sha256HashCode(str)
}

View File

@@ -16,7 +16,7 @@ object Dependencies {
.exclude("com.typesafe.akka", "akka-persistence-query")
.exclude("com.typesafe.akka", "akka-stream")
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5"
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.8"
val mockito = "org.mockito" % "mockito-all" % "1.10.19"
val junitInterface = "com.novocode" % "junit-interface" % "0.11"
val junitJupiter = "org.junit.jupiter" % "junit-jupiter-engine" % "5.5.2"

View File

@@ -7,7 +7,7 @@ import org.scalacheck.Prop.forAll
import org.scalacheck.Test.Parameters.defaultVerbose
import org.scalacheck.{Arbitrary, Gen, Test}
import org.scalatest.FunSuiteLike
import org.scalatest.prop.Checkers
import org.scalatestplus.scalacheck.Checkers
class HashingSpec extends FunSuiteLike with Checkers {
@@ -16,7 +16,7 @@ class HashingSpec extends FunSuiteLike with Checkers {
def hashingLaw[A: Arbitrary](): Unit = {
check(forAll { (x: A, y: A) =>
if(x == y) x.hashCode() == y.hashCode()
if (x == y) x.hashCode() == y.hashCode()
else x.hashCode() != y.hashCode()
}, config)
}
@@ -82,5 +82,4 @@ object HashingSpec {
def optionTypeGen: Gen[OptionType] =
primitiveTypeGen.map(OptionType)
}
}

View File

@@ -1,20 +1,22 @@
package com.ing.baker
import java.nio.file.Paths
import java.util.UUID
import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.ing.baker.compiler.RecipeCompiler
import com.ing.baker.il.CompiledRecipe
import com.ing.baker.recipe.TestRecipe.{ fireTwoEventsInteraction, _ }
import com.ing.baker.recipe.{ CaseClassIngredient, common }
import com.ing.baker.runtime.scaladsl.{ Baker, EventInstance, InteractionInstance }
import com.ing.baker.types.{ Converters, Value }
import com.typesafe.config.{ Config, ConfigFactory }
import java.nio.file.Paths
import java.util.UUID
import com.ing.baker.recipe.TestRecipe.{fireTwoEventsInteraction, _}
import com.ing.baker.recipe.{CaseClassIngredient, common}
import com.ing.baker.runtime.scaladsl.{Baker, EventInstance, InteractionInstance}
import com.ing.baker.types.{Converters, Value}
import com.typesafe.config.{Config, ConfigFactory}
import org.mockito.Matchers._
import org.mockito.Mockito._
import org.scalatest._
import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.mockito.MockitoSugar
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.language.postfixOps
@@ -103,7 +105,7 @@ trait BakerRuntimeTestBase
testProvidesNothingInteractionMock).map(InteractionInstance.unsafeFrom(_))
def writeRecipeToSVGFile(recipe: CompiledRecipe) = {
import guru.nidi.graphviz.engine.{ Format, Graphviz }
import guru.nidi.graphviz.engine.{Format, Graphviz}
import guru.nidi.graphviz.parse.Parser
val g = Parser.read(recipe.getRecipeVisualization)
Graphviz.fromGraph(g).render(Format.SVG).toFile(Paths.get(recipe.name).toFile)
@@ -163,9 +165,9 @@ trait BakerRuntimeTestBase
s"""
|akka {
|
| actor.provider = "akka.cluster.ClusterActorRefProvider"
| actor.provider = "akka.cluster.ClusterActorRefProvider"
|
| remote {
| remote {
| netty.tcp {
| hostname = localhost
| port = $port
@@ -173,7 +175,7 @@ trait BakerRuntimeTestBase
| }
|}
|
|baker {
|baker {
| actor.provider = "cluster-sharded"
| cluster.seed-nodes = ["akka.tcp://$actorSystemName@localhost:$port"]
|}
@@ -186,14 +188,14 @@ trait BakerRuntimeTestBase
}
/**
* Returns a Baker instance that contains a simple recipe that can be used in tests
* It als sets mocks that return happy flow responses for the interactions
*
* This recipe contains: See TestRecipe.png for a visualization
*
* @param recipeName A unique name that is needed for the recipe to insure that the tests do not interfere with each other
* @return
*/
* Returns a Baker instance that contains a simple recipe that can be used in tests
* It als sets mocks that return happy flow responses for the interactions
*
* This recipe contains: See TestRecipe.png for a visualization
*
* @param recipeName A unique name that is needed for the recipe to insure that the tests do not interfere with each other
* @return
*/
protected def setupBakerWithRecipe(recipeName: String, appendUUIDToTheRecipeName: Boolean = true)
(implicit actorSystem: ActorSystem): Future[(Baker, String)] = {
val newRecipeName = if (appendUUIDToTheRecipeName) s"$recipeName-${UUID.randomUUID().toString}" else recipeName

View File

@@ -10,7 +10,7 @@ import org.scalacheck.Prop.forAll
import org.scalacheck.Test.Parameters.defaultVerbose
import org.scalacheck._
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import org.scalatestplus.scalacheck.Checkers
import scala.annotation.tailrec
import scala.util.Random

View File

@@ -1,32 +1,34 @@
package com.ing.baker.runtime.akka.actor.process_index
import akka.actor.{ Actor, ActorRef, ActorSystem, Props }
import akka.testkit.{ ImplicitSender, TestKit, TestProbe }
import com.ing.baker.il.petrinet.{ EventTransition, Place, RecipePetriNet, Transition }
import com.ing.baker.il.{ CompiledRecipe, EventDescriptor, IngredientDescriptor }
import com.ing.baker.petrinet.api.{ Marking, PetriNet }
import java.util.UUID
import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import com.ing.baker.il.petrinet.{EventTransition, Place, RecipePetriNet, Transition}
import com.ing.baker.il.{CompiledRecipe, EventDescriptor, IngredientDescriptor}
import com.ing.baker.petrinet.api.{Marking, PetriNet}
import com.ing.baker.runtime.akka.actor.process_index.ProcessIndex.CheckForProcessesToBeDeleted
import com.ing.baker.runtime.akka.actor.process_index.ProcessIndexProtocol.FireSensoryEventReaction.NotifyWhenReceived
import com.ing.baker.runtime.akka.actor.process_index.ProcessIndexProtocol._
import com.ing.baker.runtime.akka.actor.process_instance.ProcessInstanceProtocol
import com.ing.baker.runtime.akka.actor.process_instance.ProcessInstanceProtocol._
import com.ing.baker.runtime.akka.actor.recipe_manager.RecipeManagerProtocol
import com.ing.baker.runtime.akka.actor.recipe_manager.RecipeManagerProtocol.{ AllRecipes, GetAllRecipes, RecipeInformation }
import com.ing.baker.runtime.akka.actor.recipe_manager.RecipeManagerProtocol.{AllRecipes, GetAllRecipes, RecipeInformation}
import com.ing.baker.runtime.akka.actor.serialization.Encryption
import com.ing.baker.runtime.akka.internal.InteractionManager
import com.ing.baker.runtime.scaladsl.{ EventInstance, RecipeInstanceState }
import com.ing.baker.runtime.scaladsl.{EventInstance, RecipeInstanceState}
import com.ing.baker.types
import com.ing.baker.types.Value
import com.typesafe.config.{ Config, ConfigFactory }
import java.util.UUID
import com.typesafe.config.{Config, ConfigFactory}
import org.mockito.Mockito
import org.mockito.Mockito.when
import org.scalatest.concurrent.Eventually
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{ BeforeAndAfter, BeforeAndAfterAll, Matchers, WordSpecLike }
import scala.concurrent.duration._
import org.scalatest.{BeforeAndAfter, BeforeAndAfterAll, Matchers, WordSpecLike}
import org.scalatestplus.mockito.MockitoSugar
import scalax.collection.immutable.Graph
import scala.concurrent.duration._
object ProcessIndexSpec {
val config: Config = ConfigFactory.parseString(
"""

View File

@@ -26,8 +26,8 @@ import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer
import org.scalatest.Matchers
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.mockito.MockitoSugar
import org.scalatest.time.{Milliseconds, Span}
import org.scalatestplus.mockito.MockitoSugar
import scala.concurrent.Promise
import scala.concurrent.duration._

View File

@@ -4,8 +4,8 @@ import org.scalacheck.Gen._
import org.scalacheck.Prop.forAll
import org.scalacheck._
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import com.ing.baker.runtime.akka.actor.serialization.Encryption._
import org.scalatestplus.scalacheck.Checkers
class EncryptionPropertiesSpec extends FunSuite with Checkers {

View File

@@ -28,7 +28,7 @@ import org.scalacheck.Prop.forAll
import org.scalacheck.Test.Parameters.defaultVerbose
import org.scalacheck._
import org.scalatest.FunSuiteLike
import org.scalatest.prop.Checkers
import org.scalatestplus.scalacheck.Checkers
import scala.concurrent.duration._
import scala.reflect.ClassTag
@@ -91,7 +91,7 @@ class SerializationSpec extends TestKit(ActorSystem("BakerProtobufSerializerSpec
val serialized = serializer.toBinary(m)
val deserialized = serializer.fromBinary(serialized, serializer.manifest(m))
deserialized === m &&
ctxFromProto(ctxToProto(m)) === Success(m)
ctxFromProto(ctxToProto(m)) === Success(m)
}
checkFor[ProcessIndexProtocol.Index].run
@@ -358,7 +358,9 @@ object SerializationSpec {
} yield CreateProcess(recipeId, recipeInstanceId)
class SimpleActor extends Actor {
override def receive: Receive = { case _ => () }
override def receive: Receive = {
case _ => ()
}
}
val waitForRetriesGen = Gen.oneOf(true, false)
@@ -400,7 +402,7 @@ object SerializationSpec {
} yield StopRetryingInteraction(recipeInstanceId, interactionName)
val sensoryEventStatusGen: Gen[SensoryEventStatus] = Gen.oneOf(
SensoryEventStatus.AlreadyReceived ,
SensoryEventStatus.AlreadyReceived,
SensoryEventStatus.Completed,
SensoryEventStatus.FiringLimitMet,
SensoryEventStatus.Received,
@@ -409,9 +411,9 @@ object SerializationSpec {
)
val eventResultGen: Gen[SensoryEventResult] = for {
status <- sensoryEventStatusGen
events <- Gen.listOf(Gen.alphaStr)
ingredients <- Gen.listOf(Runtime.ingredientsGen)
status <- sensoryEventStatusGen
events <- Gen.listOf(Gen.alphaStr)
ingredients <- Gen.listOf(Runtime.ingredientsGen)
} yield SensoryEventResult(status, events, ingredients.toMap)
implicit val processEventResponse: Gen[ProcessEventResponse] = for {

View File

@@ -6,8 +6,8 @@ import com.ing.baker.runtime.scaladsl.InteractionInstance
import com.ing.baker.types
import com.ing.baker.types.Type
import org.mockito.Mockito.when
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{Matchers, WordSpecLike}
import org.scalatestplus.mockito.MockitoSugar
class InteractionManagerSpec extends WordSpecLike with Matchers with MockitoSugar {
"getImplementation" should {

View File

@@ -8,8 +8,8 @@ import com.ing.baker.runtime.scaladsl.RecipeInstanceState
import com.ing.baker.types.Value
import com.ing.baker.{il, types}
import org.mockito.Mockito._
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{Matchers, WordSpecLike}
import org.scalatestplus.mockito.MockitoSugar
class RecipeRuntimeSpec extends WordSpecLike with Matchers with MockitoSugar {
"The recipe runtime" should {