Skip to content

Commit

Permalink
Merge pull request ReactiveX#111 from drmaas/master
Browse files Browse the repository at this point in the history
  • Loading branch information
storozhukBM authored Apr 21, 2017
2 parents ceddbc7 + c339049 commit b5358af
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 51 deletions.
4 changes: 4 additions & 0 deletions resilience4j-ratpack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ dependencies {
compile project(':resilience4j-retry')
testCompile ( libraries.ratpack_test )
testCompile ( libraries.spock )
}

test {
maxParallelForks = 16
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,64 @@ package io.github.resilience4j.ratpack

import io.github.resilience4j.ratelimiter.RateLimiter
import io.github.resilience4j.ratelimiter.RateLimiterConfig
import ratpack.exec.Blocking
import ratpack.exec.Promise
import ratpack.test.exec.ExecHarness
import spock.lang.Ignore
import spock.lang.Specification

import java.time.Duration

class RatelimiterTransformerSpec extends Specification {

@Ignore
def "can ratelimit promise then throw exception when limit is exceeded"() {
given:
RateLimiter rateLimiter = buildRatelimiter()
RateLimiterTransformer<Integer> transformer = RateLimiterTransformer.of(rateLimiter)
Set<Integer> values = [].toSet()
Set<Integer> expected = (0..9).toSet()
def "can ratelimit promise then throw exception when limit is exceeded"() {
given:
RateLimiter rateLimiter = buildRatelimiter()
RateLimiterTransformer<Integer> transformer = RateLimiterTransformer.of(rateLimiter)
Set<Integer> values = [].toSet()
Set<Integer> expected = (0..9).toSet()

when:
for (int i = 0 ; i <= 10; i++) {
def r = ExecHarness.yieldSingle {
Blocking.<Integer> get {
i
}.transform(transformer)
}
if (r.success) values << r.value
when:
for (int i = 0; i <= 10; i++) {
def r = ExecHarness.yieldSingle {
Promise.async {
it.success(i)
}.transform(transformer)
}
if (r.success) values << r.value
}

then:
values == expected
}

then:
values == expected
}
def "can ratelimit promise then throw exception when limit is exceeded then call recover"() {
given:
String failure = "failure"
RateLimiter rateLimiter = buildRatelimiter()
RateLimiterTransformer<Integer> transformer = RateLimiterTransformer.of(rateLimiter).recover { t -> failure }
Set<Integer> values = [].toSet()
Set<Integer> expected = (0..9).toSet()

@Ignore
def "can ratelimit promise then throw exception when limit is exceeded then call recover"() {
given:
String failure = "failure"
RateLimiter rateLimiter = buildRatelimiter()
RateLimiterTransformer<Integer> transformer = RateLimiterTransformer.of(rateLimiter).recover { t -> failure }
Set<Integer> values = [].toSet()
Set<Integer> expected = (0..9).toSet()
when:
for (int i = 0; i <= 10; i++) {
def r = ExecHarness.yieldSingle {
Promise.async {
it.success(i)
}.transform(transformer)
}
if (r.success) values << r.value
}

when:
for (int i = 0 ; i <= 10; i++) {
def r = ExecHarness.yieldSingle {
Blocking.<Integer> get {
i
}.transform(transformer)
}
if (r.success) values << r.value
then:
values == expected << failure
}

then:
values == expected << failure
}

// 10 events / 10 s
def buildRatelimiter() {
RateLimiterConfig config = RateLimiterConfig.custom()
.limitRefreshPeriod(Duration.ofSeconds(10))
.limitForPeriod(10)
.timeoutDuration(Duration.ofMillis(100))
.build()
RateLimiter.of("test", config)
}
// 10 events / 1 minute
def buildRatelimiter() {
RateLimiterConfig config = RateLimiterConfig.custom()
.limitRefreshPeriod(Duration.ofSeconds(60))
.limitForPeriod(10)
.timeoutDuration(Duration.ofMillis(100))
.build()
RateLimiter.of("test", config)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ class RateLimiterSpec extends Specification {
'normal' | 'test'
}

// 10 events / 10 s
// 10 events / 1 minute
def buildConfig() {
RateLimiterConfig.custom()
.limitRefreshPeriod(Duration.ofSeconds(10))
.limitRefreshPeriod(Duration.ofSeconds(60))
.limitForPeriod(10)
.timeoutDuration(Duration.ofMillis(100))
.build()
Expand Down

0 comments on commit b5358af

Please sign in to comment.