Skip to content

Commit

Permalink
fix some tests error in demo (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 authored Jun 27, 2022
1 parent 5342745 commit d2ce1c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ public String retry(HttpServletResponse response, @RequestParam(name = "invocati
}

@RequestMapping("/circuitBreaker")
public String circuitBreaker() throws Exception {
public String circuitBreaker(HttpServletResponse response) throws Exception {
int index = count.getAndIncrement();
LOGGER.info("circuitBreaker index {}", index);
if (index % 3 != 0) {
return "ok";
}
throw new RuntimeException("test error");
response.setStatus(502);
return null;
}

@RequestMapping("/bulkhead")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,30 @@ spring:
uri: lb://basic-provider
predicates:
- Path=/gateway/**
- id: consumer
- id: consumer-governance-test
uri: lb://basic-consumer
filters:
- name: governance
predicates:
- Path=/**
order: 1
- id: consumer-retry-test
uri: lb://basic-consumer
filters:
- name: governance
- name: Retry
args:
retries: 3
series: SERVER_ERROR
predicates:
- Path=/govern/retry/**
order: 0
servicecomb:
matchGroup:
demo-rateLimiting: |
matches:
- apiPath:
exact: "/govern/rateLimiting"
demo-retry: |
matches:
- apiPath:
prefix: "/govern/retry"
demo-circuitBreaker: |
matches:
- apiPath:
Expand All @@ -56,11 +64,6 @@ servicecomb:
rateLimiting:
demo-rateLimiting: |
rate: 10
retry:
demo-retry: |
maxAttempts: 3
retryOnResponseStatus:
- 503
circuitBreaker:
demo-circuitBreaker: |
minimumNumberOfCalls: 10
Expand All @@ -70,12 +73,6 @@ servicecomb:
bulkhead:
demo-bulkhead: |
maxConcurrentCalls: 5
instanceIsolation:
default: |
minimumNumberOfCalls: 10
slidingWindowSize: 10
slidingWindowType: COUNT_BASED
failureRateThreshold: 20
# 灰度发布配置
routeRule:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void run() {
@Test
public void testCircuitBreaker() throws Exception {
CountDownLatch latch = new CountDownLatch(100);
AtomicBoolean expectedFailed503 = new AtomicBoolean(false);
AtomicBoolean expectedFailed502 = new AtomicBoolean(false);
AtomicBoolean expectedFailed500 = new AtomicBoolean(false);
AtomicBoolean notExpectedFailed = new AtomicBoolean(false);
AtomicLong successCount = new AtomicLong(0);
Expand All @@ -94,8 +94,8 @@ public void run() {
successCount.getAndIncrement();
}
} catch (Exception e) {
if (e instanceof HttpServerErrorException && ((HttpServerErrorException) e).getRawStatusCode() == 503) {
expectedFailed503.set(true);
if (e instanceof HttpServerErrorException && ((HttpServerErrorException) e).getRawStatusCode() == 502) {
expectedFailed502.set(true);
} else if (e instanceof HttpServerErrorException
&& ((HttpServerErrorException) e).getRawStatusCode() == 500) {
expectedFailed500.set(true);
Expand All @@ -111,7 +111,7 @@ public void run() {
}

latch.await(20, TimeUnit.SECONDS);
Assertions.assertTrue(expectedFailed503.get());
Assertions.assertTrue(expectedFailed502.get());
Assertions.assertTrue(expectedFailed500.get());
Assertions.assertFalse(notExpectedFailed.get());
Assertions.assertTrue(successCount.get() >= 8);
Expand Down

0 comments on commit d2ce1c3

Please sign in to comment.