Skip to content

Commit

Permalink
Merge pull request #26 from matthughes/213upgrade
Browse files Browse the repository at this point in the history
Upgrade to support 2.13 and ScalaJS 1.0
  • Loading branch information
matthughes committed May 29, 2020
2 parents 7e1f9f5 + 4448498 commit 5a45cfe
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -17,3 +17,7 @@ target
*.log
*.swp
*~
.metals
project/.bloop
project/metals.sbt
.bloop
6 changes: 3 additions & 3 deletions .travis.yml
@@ -1,11 +1,11 @@
language: scala

scala:
- 2.11.8
- 2.12.1
- 2.12.10
- 2.13.1

jdk:
- oraclejdk8
- oraclejdk11

sudo: false

Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Expand Up @@ -12,9 +12,9 @@ lazy val core = project.in(file("core")).enablePlugins(SbtOsgi).
settings(
name := "circuitbreaker",
libraryDependencies ++= Seq(
"com.ccadllc.cedi" %% "config" % "1.1.0",
"co.fs2" %% "fs2-core" % "1.0.2",
"org.scalatest" %% "scalatest" % "3.0.5" % "test"
"com.ccadllc.cedi" %% "config" % "1.2.0",
"co.fs2" %% "fs2-core" % "2.2.2",
"org.scalatest" %% "scalatest" % "3.1.1" % "test"
),
buildOsgiBundle("com.ccadllc.cedi.circuitbreaker"),
scalacOptions ++= (if (scalaBinaryVersion.value startsWith "2.11") List("-Xexperimental") else Nil) // 2.11 needs -Xexperimental to enable SAM conversion
Expand Down
Expand Up @@ -17,16 +17,15 @@ package com.ccadllc.cedi.circuitbreaker

import cats.effect.IO

import org.scalatest.WordSpec

import scala.concurrent.duration._
import org.scalatest.wordspec.AnyWordSpec

class CircuitBreakerRegistryTest extends WordSpec with TestSupport {
class CircuitBreakerRegistryTest extends AnyWordSpec with TestSupport {
"The circuit breaker registry" should {
"register a new failure circuit breaker when an existing one with the given identifier does not exist" in {
val id = CircuitBreaker.Identifier("test")
val registry = CircuitBreakerRegistry.create[IO](testRegistryConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync shouldBe 'empty
registry.circuitBreakers.unsafeRunSync shouldBe Symbol("empty")
val cb = registry.forFailure(id, testFailureConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe Some(cb)
}
Expand All @@ -44,12 +43,12 @@ class CircuitBreakerRegistryTest extends WordSpec with TestSupport {
val cb = registry.forFailure(id, testFailureConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe Some(cb)
registry.removeCircuitBreaker(id).unsafeRunSync
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe 'empty
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe Symbol("empty")
}
"register a new flow control circuit breaker when an existing one with the given identifier does not exist" in {
val id = CircuitBreaker.Identifier("test")
val registry = CircuitBreakerRegistry.create[IO](testRegistryConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync shouldBe 'empty
registry.circuitBreakers.unsafeRunSync shouldBe Symbol("empty")
val cb = registry.forFlowControl(id, testFlowControlConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe Some(cb)
}
Expand All @@ -67,14 +66,14 @@ class CircuitBreakerRegistryTest extends WordSpec with TestSupport {
val cb = registry.forFlowControl(id, testFlowControlConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe Some(cb)
registry.removeCircuitBreaker(id).unsafeRunSync
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe 'empty
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe Symbol("empty")
}
"ignore removal of a non-existent circuit breaker" in {
val id = CircuitBreaker.Identifier("test")
val registry = CircuitBreakerRegistry.create[IO](testRegistryConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe 'empty
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe Symbol("empty")
registry.removeCircuitBreaker(id).unsafeRunSync
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe 'empty
registry.circuitBreakers.unsafeRunSync.get(id) shouldBe Symbol("empty")
}
"request a stream of events (when events are available)" in {
val id = CircuitBreaker.Identifier("test")
Expand Down Expand Up @@ -102,13 +101,13 @@ class CircuitBreakerRegistryTest extends WordSpec with TestSupport {
val gcSettings = RegistrySettings.GarbageCollection(gcCheckInterval, inactivityCutoff)
val registry = CircuitBreakerRegistry.create[IO](testRegistryConfig.copy(garbageCollection = gcSettings)).unsafeRunSync
registry.forFailure(id, testFailureConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync should not be 'empty
registry.circuitBreakers.unsafeRunSync should not be Symbol("empty")
Thread.sleep(inactivityCutoff.toMillis + (gcCheckInterval.toMillis * 4L))
registry.circuitBreakers.unsafeRunSync shouldBe 'empty
registry.circuitBreakers.unsafeRunSync shouldBe Symbol("empty")
registry.forFailure(id, testFailureConfig).unsafeRunSync
registry.circuitBreakers.unsafeRunSync should not be 'empty
registry.circuitBreakers.unsafeRunSync should not be Symbol("empty")
Thread.sleep(inactivityCutoff.toMillis + (gcCheckInterval.toMillis * 4L))
registry.circuitBreakers.unsafeRunSync shouldBe 'empty
registry.circuitBreakers.unsafeRunSync shouldBe Symbol("empty")
}
}
}
Expand Up @@ -17,11 +17,10 @@ package com.ccadllc.cedi.circuitbreaker

import cats.effect.IO

import org.scalatest.WordSpec

import scala.concurrent.duration._
import org.scalatest.wordspec.AnyWordSpec

class FailureCircuitBreakerTest extends WordSpec with TestSupport {
class FailureCircuitBreakerTest extends AnyWordSpec with TestSupport {
"The failure circuit breaker" should {
"switch to the open position when the failure rate of the services it is protecting exceeds the configured threshold" in {
val id = CircuitBreaker.Identifier("test")
Expand Down
Expand Up @@ -18,11 +18,11 @@ package com.ccadllc.cedi.circuitbreaker
import cats.effect.IO

import org.scalatest.OptionValues._
import org.scalatest.WordSpec

import scala.concurrent.duration._
import org.scalatest.wordspec.AnyWordSpec

class FlowControlCircuitBreakerTest extends WordSpec with TestSupport {
class FlowControlCircuitBreakerTest extends AnyWordSpec with TestSupport {
"The flow control circuitbreaker" should {
"throttle down the request rate when the inbound rate continue to exceed the max acceptable rate" in {
val id = CircuitBreaker.Identifier("test")
Expand Down
Expand Up @@ -22,11 +22,13 @@ import scala.collection.immutable.Vector
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.util.Random
import org.scalatest.{ BeforeAndAfterAll, Matchers, Suite, WordSpecLike }
import org.scalatest.{ BeforeAndAfterAll, Suite }
import CircuitBreaker._
import statistics._
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

trait TestSupport extends WordSpecLike with Matchers with BeforeAndAfterAll {
trait TestSupport extends AnyWordSpecLike with Matchers with BeforeAndAfterAll {
self: Suite =>

private val GroupTasksBy = 10
Expand Down Expand Up @@ -163,7 +165,7 @@ trait TestSupport extends WordSpecLike with Matchers with BeforeAndAfterAll {
Random.shuffle(successfulTasks ++ failedTasks).grouped(groupedTasks).toVector.traverse[IO, Vector[Option[Throwable]]] {
def protectInParallel(taskGroup: Vector[IO[Unit]]) = {
def attemptProtect(t: IO[Unit]): IO[Option[Throwable]] = cb.protect(t).attempt map { _.left.toOption }
taskGroup.map(attemptProtect).parTraverse[IO, IO.Par, Option[Throwable]](identity)
taskGroup.map(attemptProtect).parTraverse[IO, Option[Throwable]](identity)
}
protectInParallel(_) map { r =>
Thread.sleep(50L)
Expand Down Expand Up @@ -201,7 +203,7 @@ trait TestSupport extends WordSpecLike with Matchers with BeforeAndAfterAll {
ec.tasks.grouped(groupedTasks).toVector.traverse[IO, Vector[IO[Either[Throwable, Unit]]]] {
def protectInParallel(taskGroup: Vector[IO[Unit]]) = {
def attemptProtect(t: IO[Unit]): IO[IO[Either[Throwable, Unit]]] = Concurrent[IO].start(cb.protect(t).attempt).map(_.join)
taskGroup.map(attemptProtect).parTraverse[IO, IO.Par, IO[Either[Throwable, Unit]]](identity)
taskGroup.map(attemptProtect).parTraverse[IO, IO[Either[Throwable, Unit]]](identity)
}
protectInParallel(_) map { r =>
Thread.sleep(pauseBetweenTaskGroups.toMillis)
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
@@ -1 +1 @@
sbt.version=1.2.0
sbt.version=1.3.8

0 comments on commit 5a45cfe

Please sign in to comment.