Skip to content

Commit

Permalink
Fixed SonarCloud findings.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobWin committed Apr 20, 2019
1 parent c744886 commit 7055444
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*/
package io.github.resilience4j.prometheus;

import org.junit.Test;

import java.util.function.Supplier;

import io.github.resilience4j.bulkhead.Bulkhead;
import io.github.resilience4j.bulkhead.BulkheadConfig;
import io.github.resilience4j.bulkhead.BulkheadRegistry;
Expand All @@ -31,6 +27,9 @@
import io.vavr.collection.HashMap;
import io.vavr.collection.HashSet;
import io.vavr.collection.Map;
import org.junit.Test;

import java.util.function.Supplier;

import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -67,13 +66,13 @@ public void testExportsCircuitBreakerStates() {
public void testConstructors() {
final BulkheadRegistry registry = new InMemoryBulkheadRegistry(BulkheadConfig.ofDefaults());

BulkheadExports.ofIterable("boo_bulkheads", singleton(Bulkhead.ofDefaults("foo")));
BulkheadExports.ofBulkheadRegistry("boo_bulkheads", registry);
BulkheadExports.ofSupplier("boo_bulkheads", () -> singleton(Bulkhead.ofDefaults("foo")));
assertThat(BulkheadExports.ofIterable("boo_bulkheads", singleton(Bulkhead.ofDefaults("foo")))).isNotNull();
assertThat(BulkheadExports.ofBulkheadRegistry("boo_bulkheads", registry)).isNotNull();
assertThat(BulkheadExports.ofSupplier("boo_bulkheads", () -> singleton(Bulkhead.ofDefaults("foo")))).isNotNull();

BulkheadExports.ofIterable(singleton(Bulkhead.ofDefaults("foo")));
BulkheadExports.ofBulkheadRegistry(registry);
BulkheadExports.ofSupplier(() -> singleton(Bulkhead.ofDefaults("foo")));
assertThat(BulkheadExports.ofIterable(singleton(Bulkhead.ofDefaults("foo")))).isNotNull();
assertThat(BulkheadExports.ofBulkheadRegistry(registry)).isNotNull();
assertThat(BulkheadExports.ofSupplier(() -> singleton(Bulkhead.ofDefaults("foo")))).isNotNull();
}

@Test(expected = NullPointerException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*/
package io.github.resilience4j.prometheus;

import org.junit.Test;

import java.util.function.Supplier;

import io.github.resilience4j.circuitbreaker.CircuitBreaker;
import io.github.resilience4j.circuitbreaker.CircuitBreakerOpenException;
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry;
Expand All @@ -31,6 +27,9 @@
import io.vavr.collection.HashMap;
import io.vavr.collection.HashSet;
import io.vavr.collection.Map;
import org.junit.Test;

import java.util.function.Supplier;

import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -176,13 +175,13 @@ public void testExportsCircuitBreakerMetrics() {
public void testConstructors() {
final CircuitBreakerRegistry registry = new InMemoryCircuitBreakerRegistry();

CircuitBreakerExports.ofIterable("boo_breakers", singleton(CircuitBreaker.ofDefaults("foo")));
CircuitBreakerExports.ofCircuitBreakerRegistry("boo_breakers", registry);
CircuitBreakerExports.ofSupplier("boo_breakers", () -> singleton(CircuitBreaker.ofDefaults("foo")));
assertThat(CircuitBreakerExports.ofIterable("boo_breakers", singleton(CircuitBreaker.ofDefaults("foo")))).isNotNull();
assertThat(CircuitBreakerExports.ofCircuitBreakerRegistry("boo_breakers", registry)).isNotNull();
assertThat(CircuitBreakerExports.ofSupplier("boo_breakers", () -> singleton(CircuitBreaker.ofDefaults("foo")))).isNotNull();

CircuitBreakerExports.ofIterable(singleton(CircuitBreaker.ofDefaults("foo")));
CircuitBreakerExports.ofCircuitBreakerRegistry(registry);
CircuitBreakerExports.ofSupplier(() -> singleton(CircuitBreaker.ofDefaults("foo")));
assertThat(CircuitBreakerExports.ofIterable(singleton(CircuitBreaker.ofDefaults("foo")))).isNotNull();
assertThat(CircuitBreakerExports.ofCircuitBreakerRegistry(registry)).isNotNull();
assertThat(CircuitBreakerExports.ofSupplier(() -> singleton(CircuitBreaker.ofDefaults("foo")))).isNotNull();
}

@Test(expected = NullPointerException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*/
package io.github.resilience4j.prometheus;

import org.junit.Test;

import java.util.function.Supplier;

import io.github.resilience4j.ratelimiter.RateLimiter;
import io.github.resilience4j.ratelimiter.RateLimiterConfig;
import io.github.resilience4j.ratelimiter.RateLimiterRegistry;
Expand All @@ -31,6 +27,9 @@
import io.vavr.collection.HashMap;
import io.vavr.collection.HashSet;
import io.vavr.collection.Map;
import org.junit.Test;

import java.util.function.Supplier;

import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -73,13 +72,13 @@ public void testExportsRateLimiterMetrics() {
public void testConstructors() {
final RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(RateLimiterConfig.ofDefaults());

RateLimiterExports.ofIterable("boo_limiters", singleton(RateLimiter.ofDefaults("foo")));
RateLimiterExports.ofRateLimiterRegistry("boo_limiters", registry);
RateLimiterExports.ofSupplier("boo_limiters", () -> singleton(RateLimiter.ofDefaults("foo")));
assertThat(RateLimiterExports.ofIterable("boo_limiters", singleton(RateLimiter.ofDefaults("foo")))).isNotNull();
assertThat(RateLimiterExports.ofRateLimiterRegistry("boo_limiters", registry)).isNotNull();
assertThat(RateLimiterExports.ofSupplier("boo_limiters", () -> singleton(RateLimiter.ofDefaults("foo")))).isNotNull();

RateLimiterExports.ofIterable(singleton(RateLimiter.ofDefaults("foo")));
RateLimiterExports.ofRateLimiterRegistry(registry);
RateLimiterExports.ofSupplier(() -> singleton(RateLimiter.ofDefaults("foo")));
assertThat(RateLimiterExports.ofIterable(singleton(RateLimiter.ofDefaults("foo")))).isNotNull();
assertThat(RateLimiterExports.ofRateLimiterRegistry(registry)).isNotNull();
assertThat(RateLimiterExports.ofSupplier(() -> singleton(RateLimiter.ofDefaults("foo")))).isNotNull();
}

@Test(expected = NullPointerException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public void shouldNotRetryWithThatResult(){
// Then the helloWorldService should be invoked 1 time
BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnHelloWorld();
Assertions.assertThat(result).isEqualTo("Hello world");
// for code quality scan , it does not not recognize assertJ do not why
Assert.assertEquals(result, "Hello world");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* A RxJava {@link CompletableObserver} to protect another observer by a CircuitBreaker.
*/
final class CircuitBreakerCompletableObserver extends DisposableCircuitBreaker implements CompletableObserver {
private final CompletableObserver childObserver;
private final transient CompletableObserver childObserver;

CircuitBreakerCompletableObserver(CircuitBreaker circuitBreaker, CompletableObserver childObserver) {
super(circuitBreaker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class CircuitBreakerSubscriber<T> extends AtomicReference<Subscription> im
private final transient Subscriber<? super T> childSubscriber;
private final AtomicReference<Permit> permitted = new AtomicReference<>(Permit.PENDING);
@Nullable
private StopWatch stopWatch;
private transient StopWatch stopWatch;

CircuitBreakerSubscriber(CircuitBreaker circuitBreaker, Subscriber<? super T> childSubscriber) {
this.circuitBreaker = requireNonNull(circuitBreaker);
Expand Down Expand Up @@ -100,13 +100,13 @@ private boolean notCancelled() {

private void markFailure(Throwable e) {
if (wasCallPermitted()) {
circuitBreaker.onError(stopWatch.stop().toNanos(), e);
circuitBreaker.onError(stopWatch != null ? stopWatch.stop().toNanos() : 0, e);
}
}

private void markSuccess() {
if (wasCallPermitted()) {
circuitBreaker.onSuccess(stopWatch.stop().toNanos());
circuitBreaker.onSuccess(stopWatch != null ? stopWatch.stop().toNanos() : 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
*/
package io.github.resilience4j.circuitbreaker;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerProperties;
import io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect;
import io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEndpointResponse;
import io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEventsEndpointResponse;
import io.github.resilience4j.service.test.DummyService;
import io.github.resilience4j.service.test.ReactiveDummyService;
import io.github.resilience4j.service.test.TestApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -32,13 +31,13 @@
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerProperties;
import io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect;
import io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEndpointResponse;
import io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEventsEndpointResponse;
import io.github.resilience4j.service.test.DummyService;
import io.github.resilience4j.service.test.ReactiveDummyService;
import io.github.resilience4j.service.test.TestApplication;
import java.io.IOException;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
Expand Down Expand Up @@ -140,7 +139,7 @@ public void testCircuitBreakerAutoConfigurationAsync() throws IOException, Execu
}
// The invocation is recorded by the CircuitBreaker as a success.
final CompletableFuture<String> stringCompletionStage = dummyService.doSomethingAsync(false);
assertThat(stringCompletionStage.get().equals("Test result"));
assertThat(stringCompletionStage.get()).isEqualTo("Test result");

CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker(DummyService.BACKEND);
assertThat(circuitBreaker).isNotNull();
Expand Down

0 comments on commit 7055444

Please sign in to comment.