aboutsummaryrefslogtreecommitdiff
path: root/circuit-breaker/hystrix-backend/src/test/scala/com/softwaremill/sttp/hystrix/HystrixBackendTest.scala
diff options
context:
space:
mode:
Diffstat (limited to 'circuit-breaker/hystrix-backend/src/test/scala/com/softwaremill/sttp/hystrix/HystrixBackendTest.scala')
-rw-r--r--circuit-breaker/hystrix-backend/src/test/scala/com/softwaremill/sttp/hystrix/HystrixBackendTest.scala40
1 files changed, 39 insertions, 1 deletions
diff --git a/circuit-breaker/hystrix-backend/src/test/scala/com/softwaremill/sttp/hystrix/HystrixBackendTest.scala b/circuit-breaker/hystrix-backend/src/test/scala/com/softwaremill/sttp/hystrix/HystrixBackendTest.scala
index 8772d45..f97e7da 100644
--- a/circuit-breaker/hystrix-backend/src/test/scala/com/softwaremill/sttp/hystrix/HystrixBackendTest.scala
+++ b/circuit-breaker/hystrix-backend/src/test/scala/com/softwaremill/sttp/hystrix/HystrixBackendTest.scala
@@ -1,6 +1,6 @@
package com.softwaremill.sttp.hystrix
-import com.netflix.hystrix.{HystrixCommandKey, HystrixCommandMetrics, HystrixCommandProperties}
+import com.netflix.hystrix._
import com.softwaremill.sttp.testing.SttpBackendStub
import com.softwaremill.sttp.{sttp, _}
import org.scalatest.concurrent.{Eventually, IntegrationPatience, ScalaFutures}
@@ -59,4 +59,42 @@ class HystrixBackendTest
metrics.getHealthCounts.getTotalRequests shouldBe 10
}
+ it should "open circuit when server is throwing errors" in {
+ // given
+ val backendStub = SttpBackendStub.synchronous.whenAnyRequest.thenRespondServerError()
+
+ val backend = HystrixBackend[Id, Nothing](backendStub)("TestSyncCircuitCMD")
+ val requestsNumber = 1000
+
+ val commandName = "SyncCircuitSttpCMD"
+
+ // when
+ import HystrixBackend._
+
+ (0 until requestsNumber).map(
+ _ =>
+ backend.send(
+ sttp
+ .get(uri"http://localhost:8080/get")
+ .configureSyncHystrix(
+ HystrixCommand.Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestSyncCircuitCMD"))
+ .andCommandKey(HystrixCommandKey.Factory.asKey(commandName))
+ .andCommandPropertiesDefaults(
+ HystrixCommandProperties
+ .Setter()
+ .withMetricsHealthSnapshotIntervalInMilliseconds(10)
+ .withCircuitBreakerEnabled(true)
+ ))))
+
+ // then
+ val metrics = HystrixCommandMetrics.getInstance(HystrixCommandKey.Factory.asKey(commandName))
+
+ Thread.sleep(100) // wait for the health metrics
+ metrics.getHealthCounts.getErrorPercentage shouldBe 100
+ metrics.getProperties.circuitBreakerEnabled().get() shouldBe true
+
+ HystrixCircuitBreaker.Factory.getInstance(HystrixCommandKey.Factory.asKey(commandName)).isOpen shouldBe true
+ }
+
}