Skip to content

Commit

Permalink
Issue #560: Fixed bug when using a lamda as a Feign fallback (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexmind authored and RobWin committed Aug 19, 2019
1 parent 89cb7f1 commit 5977f40
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
Expand Up @@ -40,6 +40,7 @@ public CheckedFunction1<Object[], Object> decorate(CheckedFunction1<Object[], Ob
Predicate<Exception> filter) {
validateFallback(fallback, method);
Method fallbackMethod = getFallbackMethod(fallback, method);
fallbackMethod.setAccessible(true);
return args -> {
try {
return invocationCall.apply(args);
Expand Down
@@ -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!")));
}
}
@@ -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";
}
}

0 comments on commit 5977f40

Please sign in to comment.