Fix test failure in sentinel-grpc-adapter
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
parent
2682bd1aae
commit
e71d036794
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* 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 com.alibaba.csp.sentinel.adapter.grpc;
|
||||
|
||||
import com.alibaba.csp.sentinel.EntryType;
|
||||
|
|
@ -9,6 +24,7 @@ import com.alibaba.csp.sentinel.adapter.grpc.gen.FooRequest;
|
|||
import com.alibaba.csp.sentinel.adapter.grpc.gen.FooResponse;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot;
|
||||
|
||||
import io.grpc.StatusRuntimeException;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
|
@ -20,33 +36,24 @@ import static org.junit.Assert.*;
|
|||
|
||||
/**
|
||||
* @author zhengzechao
|
||||
* @date 2018/12/7
|
||||
* Email ooczzoo@gmail.com
|
||||
*/
|
||||
public class SentinelGrpcClientInterceptorDegradeTest {
|
||||
|
||||
private final String resourceName = "com.alibaba.sentinel.examples.FooService/helloWithEx";
|
||||
private final int threshold = 2;
|
||||
private final GrpcTestServer server = new GrpcTestServer();
|
||||
private final int timeWindow = 10;
|
||||
|
||||
|
||||
|
||||
|
||||
private void configureDegradeRule(int count) {
|
||||
DegradeRule rule = new DegradeRule()
|
||||
.setCount(count)
|
||||
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
||||
.setResource(resourceName)
|
||||
.setLimitApp("default")
|
||||
.as(DegradeRule.class)
|
||||
.setTimeWindow(timeWindow);
|
||||
.setCount(count)
|
||||
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
||||
.setResource(resourceName)
|
||||
.setLimitApp("default")
|
||||
.as(DegradeRule.class)
|
||||
.setTimeWindow(timeWindow);
|
||||
DegradeRuleManager.loadRules(Collections.singletonList(rule));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean sendRequest(FooServiceClient client) {
|
||||
try {
|
||||
FooResponse response = client.helloWithEx(FooRequest.newBuilder().setName("Sentinel").setId(666).build());
|
||||
|
|
@ -58,7 +65,6 @@ public class SentinelGrpcClientInterceptorDegradeTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGrpcClientInterceptor_degrade() throws IOException {
|
||||
final int port = 19316;
|
||||
|
|
@ -71,7 +77,7 @@ public class SentinelGrpcClientInterceptorDegradeTest {
|
|||
assertFalse(sendErrorRequest(client));
|
||||
ClusterNode clusterNode = ClusterBuilderSlot.getClusterNode(resourceName, EntryType.OUT);
|
||||
assertNotNull(clusterNode);
|
||||
assertEquals(1, clusterNode.exceptionQps());
|
||||
assertEquals(1, clusterNode.exceptionQps(), 0.01);
|
||||
// The second request will be blocked.
|
||||
assertFalse(sendRequest(client));
|
||||
assertEquals(1, clusterNode.blockRequest());
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* 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 com.alibaba.csp.sentinel.adapter.grpc;
|
||||
|
||||
import com.alibaba.csp.sentinel.EntryType;
|
||||
|
|
@ -9,6 +24,7 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
|||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot;
|
||||
|
||||
import io.grpc.StatusRuntimeException;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
|
@ -21,36 +37,29 @@ import static org.junit.Assert.*;
|
|||
|
||||
/**
|
||||
* @author zhengzechao
|
||||
* @date 2018/12/7
|
||||
* Email ooczzoo@gmail.com
|
||||
*/
|
||||
public class SentinelGrpcServerInterceptorDegradeTest {
|
||||
|
||||
private final String resourceName = "com.alibaba.sentinel.examples.FooService/anotherHelloWithEx";
|
||||
private final int threshold = 4;
|
||||
private final GrpcTestServer server = new GrpcTestServer();
|
||||
private final int timeWindow = 10;
|
||||
private FooServiceClient client;
|
||||
|
||||
|
||||
|
||||
private void configureDegradeRule(int count) {
|
||||
DegradeRule rule = new DegradeRule()
|
||||
.setCount(count)
|
||||
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
||||
.setResource(resourceName)
|
||||
.setLimitApp("default")
|
||||
.as(DegradeRule.class)
|
||||
.setTimeWindow(timeWindow);
|
||||
.setCount(count)
|
||||
.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
|
||||
.setResource(resourceName)
|
||||
.setLimitApp("default")
|
||||
.as(DegradeRule.class)
|
||||
.setTimeWindow(timeWindow);
|
||||
DegradeRuleManager.loadRules(Collections.singletonList(rule));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean sendRequest() {
|
||||
try {
|
||||
FooResponse response = client.anotherHelloWithEx(FooRequest.newBuilder().setName("Sentinel").setId(666).build());
|
||||
FooResponse response = client.anotherHelloWithEx(FooRequest.newBuilder().setName("Sentinel").setId(666)
|
||||
.build());
|
||||
System.out.println("Response: " + response);
|
||||
return true;
|
||||
} catch (StatusRuntimeException ex) {
|
||||
|
|
@ -59,10 +68,6 @@ public class SentinelGrpcServerInterceptorDegradeTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testGrpcServerInterceptor_degrade_fail_threads() throws IOException, InterruptedException {
|
||||
final int port = 19349;
|
||||
|
|
@ -91,7 +96,8 @@ public class SentinelGrpcServerInterceptorDegradeTest {
|
|||
|
||||
private boolean sendErrorRequest() {
|
||||
try {
|
||||
FooResponse response = client.anotherHelloWithEx(FooRequest.newBuilder().setName("Sentinel").setId(-1).build());
|
||||
FooResponse response = client.anotherHelloWithEx(FooRequest.newBuilder().setName("Sentinel").setId(-1)
|
||||
.build());
|
||||
System.out.println("Response: " + response);
|
||||
return true;
|
||||
} catch (StatusRuntimeException ex) {
|
||||
|
|
@ -100,7 +106,6 @@ public class SentinelGrpcServerInterceptorDegradeTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
FlowRuleManager.loadRules(null);
|
||||
|
|
|
|||
Loading…
Reference in New Issue