Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String name() {
}

@Override
public Response getFallbackResponse(Invocation invocation) {
public Response getFallbackResponse(Invocation invocation, Throwable error) {
return Response.succResp("mockedreslut");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public interface FallbackPolicy {
String name();

Response getFallbackResponse(Invocation invocation);
Response getFallbackResponse(Invocation invocation, Throwable error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems not compatible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change is fine. Users can change their implementations easily.


default void record(Invocation invocation, Response response, boolean isSuccess) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void record(String type, Invocation invocation, Response response,
public static Response getFallbackResponse(String type, Throwable error, Invocation invocation) {
FallbackPolicy policy = getPolicy(type, invocation);
if (policy != null) {
return policy.getFallbackResponse(invocation);
return policy.getFallbackResponse(invocation, error);
} else {
return Response.failResp(invocation.getInvocationType(),
BizkeeperExceptionUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String name() {
}

@Override
public Response getFallbackResponse(Invocation invocation) {
public Response getFallbackResponse(Invocation invocation, Throwable error) {
if (cachedResponse.get(invocation.getInvocationQualifiedName()) != null) {
return cachedResponse.get(invocation.getInvocationQualifiedName());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String name() {
}

@Override
public Response getFallbackResponse(Invocation invocation) {
public Response getFallbackResponse(Invocation invocation, Throwable error) {
return Response.succResp(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public String name() {
}

@Override
public Response getFallbackResponse(Invocation invocation) {
public Response getFallbackResponse(Invocation invocation, Throwable error) {
Copy link
Contributor

@wujimin wujimin Jun 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need change second parameter from null to error of createBizkeeperException, or not?

if need, then need add UT and IT for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use error as the parameter, I think

return Response.failResp(invocation.getInvocationType(),
BizkeeperExceptionUtils
.createBizkeeperException(BizkeeperExceptionUtils.SERVICECOMB_BIZKEEPER_FALLBACK,
null,
error,
invocation.getOperationMeta().getMicroserviceQualifiedName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public void testHandleInError() throws Exception {
.thenReturn("testHandleInError");
FallbackPolicy policy = Mockito.mock(FallbackPolicy.class);
Mockito.when(policy.name()).thenReturn("throwException");
Mockito.when(policy.getFallbackResponse(Mockito.any(Invocation.class))).thenThrow(new RuntimeException());
Mockito.when(policy.getFallbackResponse(Mockito.any(Invocation.class), Mockito.any(null)))
.thenThrow(new RuntimeException());
FallbackPolicyManager.addPolicy(policy);
System.setProperty("servicecomb.fallbackpolicy.groupname.testHandleInError.policy", "throwException");
Mockito.doAnswer(new Answer<Void>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.servicecomb.core.definition.OperationMeta;
import org.apache.servicecomb.core.exception.CseException;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -33,6 +34,42 @@ public void testFallbackPolicyManager(final @Mocked Configuration config, final
FallbackPolicyManager.addPolicy(new ReturnNullFallbackPolicy());
FallbackPolicyManager.addPolicy(new ThrowExceptionFallbackPolicy());
FallbackPolicyManager.addPolicy(new FromCacheFallbackPolicy());
FallbackPolicyManager.addPolicy(new FallbackPolicy() {
private static final String CUSTOM = "custom";

@Override
public String name() {
return CUSTOM;
}

@Override
public Response getFallbackResponse(Invocation invocation, Throwable error) {
if (error instanceof InvocationException) {
return Response.succResp("test");
}
if (error instanceof RuntimeException) {
return Response.succResp("runtime");
}
return null;
}
});

new Expectations() {
{
invocation.getMicroserviceName();
result = "testservice";
invocation.getOperationMeta();
result = operation;
operation.getMicroserviceQualifiedName();
result = "testservice.schema.custom";
config.getFallbackPolicyPolicy("Consumer", "testservice", "testservice.schema.custom");
result = "custom";
}
};

Assert.assertEquals("runtime",
FallbackPolicyManager.getFallbackResponse("Consumer", new RuntimeException(), invocation)
.getResult());

new Expectations() {
{
Expand Down