forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue ReactiveX#560: Fixed bug when using a lamda as a Feign fallback (…
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...feign/src/test/java/io/github/resilience4j/feign/Resilience4jFeignFallbackLambdaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* | ||
* Copyright 2019 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
* | ||
* | ||
*/ | ||
package io.github.resilience4j.feign; | ||
|
||
import io.github.resilience4j.feign.test.Issue560; | ||
import io.github.resilience4j.feign.test.TestService; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.verify; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests the integration of the {@link Resilience4jFeign} with the lambda as a fallback. | ||
*/ | ||
public class Resilience4jFeignFallbackLambdaTest { | ||
|
||
private static final String MOCK_URL = "http://localhost:8080/"; | ||
|
||
@Rule | ||
public WireMockRule wireMockRule = new WireMockRule(); | ||
|
||
private TestService testService; | ||
|
||
@Before | ||
public void setUp() { | ||
final FeignDecorators decorators = FeignDecorators.builder() | ||
.withFallback(Issue560.createLambdaFallback()) | ||
.build(); | ||
|
||
this.testService = Resilience4jFeign.builder(decorators) | ||
.target(TestService.class, MOCK_URL); | ||
} | ||
|
||
@Test | ||
public void testFallback() { | ||
setupStub(); | ||
|
||
final String result = testService.greeting(); | ||
|
||
assertThat(result).describedAs("Result").isEqualTo("fallback"); | ||
verify(1, getRequestedFor(urlPathEqualTo("/greeting"))); | ||
} | ||
|
||
private void setupStub() { | ||
stubFor(get(urlPathEqualTo("/greeting")) | ||
.willReturn(aResponse() | ||
.withStatus(400) | ||
.withHeader("Content-Type", "text/plain") | ||
.withBody("Hello, world!"))); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
resilience4j-feign/src/test/java/io/github/resilience4j/feign/test/Issue560.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.resilience4j.feign.test; | ||
|
||
/** | ||
* <pre> | ||
* Caused by: java.lang.IllegalAccessException: | ||
* class io.github.resilience4j.feign.DefaultFallbackHandler | ||
* cannot access a member of class | ||
* io.github.resilience4j.feign.test.Issue560$$Lambda$93/0x0000000840169440 with modifiers "public" | ||
* </pre> | ||
* https://github.com/resilience4j/resilience4j/issues/560 | ||
*/ | ||
public class Issue560 { | ||
|
||
public static TestService createLambdaFallback() { | ||
return () -> "fallback"; | ||
} | ||
} |