This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 4b13bb768 Increase the test coverage of package: plugin-resilienct4j 
to more than 80% (#3373)
4b13bb768 is described below

commit 4b13bb768fd986c86509fe9f59fd038895a83155
Author: qinghai777 <[email protected]>
AuthorDate: Tue May 3 12:11:57 2022 +0800

    Increase the test coverage of package: plugin-resilienct4j to more than 80% 
(#3373)
    
    * test_plugin_resilienct4j01
    
    * test_plugin_resilienct4j02
---
 .../build/Resilience4JBuilderTest.java             | 37 +++++++++
 .../resilience4j/conf/Resilience4JConfTest.java    | 91 ++++++++++++++++++++++
 .../handler/Resilience4JHandlerTest.java           | 64 +++++++++++++++
 3 files changed, 192 insertions(+)

diff --git 
a/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/build/Resilience4JBuilderTest.java
 
b/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/build/Resilience4JBuilderTest.java
new file mode 100644
index 000000000..33110256a
--- /dev/null
+++ 
b/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/build/Resilience4JBuilderTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shenyu.plugin.resilience4j.build;
+
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.plugin.resilience4j.conf.Resilience4JConf;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * The Test Case For Resilience4JConf.
+ */
+public final class Resilience4JBuilderTest {
+
+    @Test
+    public void testBuild() {
+        RuleData ruleData = new RuleData();
+        ruleData.setHandle("{\"circuitEnable\":\"1\"}");
+        Resilience4JConf resilience4JConf = 
Resilience4JBuilder.build(ruleData);
+        Assertions.assertNotNull(resilience4JConf.getCircuitBreakerConfig());
+    }
+}
diff --git 
a/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/conf/Resilience4JConfTest.java
 
b/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/conf/Resilience4JConfTest.java
new file mode 100644
index 000000000..4b12bb16b
--- /dev/null
+++ 
b/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/conf/Resilience4JConfTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shenyu.plugin.resilience4j.conf;
+
+import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
+import io.github.resilience4j.core.IntervalFunction;
+import io.github.resilience4j.ratelimiter.RateLimiterConfig;
+import io.github.resilience4j.timelimiter.TimeLimiterConfig;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.time.Duration;
+
+/**
+ * The Test Case For Resilience4JConf.
+ */
+public final class Resilience4JConfTest {
+
+    private Resilience4JConf resilience4JConf;
+
+    private RateLimiterConfig rateLimiterConfig;
+
+    private TimeLimiterConfig timeLimiterConfig;
+
+    private CircuitBreakerConfig circuitBreakerConfig;
+
+    @BeforeEach
+    public void setUp() {
+        this.resilience4JConf = new Resilience4JConf("1", "test", null, null, 
null);
+    }
+
+    @Test
+    public void testId() {
+        resilience4JConf.setId("2");
+        Assertions.assertEquals(resilience4JConf.getId(), "2");
+    }
+
+    @Test
+    public void testFallBackUri() {
+        resilience4JConf.setFallBackUri("test");
+        Assertions.assertEquals(resilience4JConf.getFallBackUri(), "test");
+    }
+
+    @Test
+    public void testTimeLimiterConfig() {
+        timeLimiterConfig = TimeLimiterConfig.custom()
+                .timeoutDuration(Duration.ofMillis(30000)).build();
+        resilience4JConf.setTimeLimiterConfig(timeLimiterConfig);
+        
Assertions.assertEquals(resilience4JConf.getTimeLimiterConfig().getClass(), 
TimeLimiterConfig.class);
+    }
+
+    @Test
+    public void testCircuitBreakerConfig() {
+        circuitBreakerConfig = CircuitBreakerConfig.custom()
+                .recordExceptions(Throwable.class, Exception.class)
+                .failureRateThreshold(50)
+                .automaticTransitionFromOpenToHalfOpenEnabled(false)
+                .slidingWindow(100, 100,
+                        0 == 0
+                                ? 
CircuitBreakerConfig.SlidingWindowType.COUNT_BASED
+                                : 
CircuitBreakerConfig.SlidingWindowType.TIME_BASED).waitIntervalFunctionInOpenState(IntervalFunction
+                        .of(Duration.ofMillis(60000)))
+                .permittedNumberOfCallsInHalfOpenState(10).build();
+        resilience4JConf.setCircuitBreakerConfig(circuitBreakerConfig);
+        
Assertions.assertEquals(resilience4JConf.getCircuitBreakerConfig().getClass(), 
CircuitBreakerConfig.class);
+    }
+
+    @Test
+    public void testRateLimiterConfig() {
+        rateLimiterConfig = RateLimiterConfig.custom()
+                .timeoutDuration(Duration.ofMillis(30000)).build();
+        resilience4JConf.setRateLimiterConfig(rateLimiterConfig);
+        
Assertions.assertEquals(resilience4JConf.getRateLimiterConfig().getClass(), 
RateLimiterConfig.class);
+    }
+}
diff --git 
a/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/handler/Resilience4JHandlerTest.java
 
b/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/handler/Resilience4JHandlerTest.java
new file mode 100644
index 000000000..bdb26a749
--- /dev/null
+++ 
b/shenyu-plugin/shenyu-plugin-resilience4j/src/test/java/org/apache/shenyu/plugin/resilience4j/handler/Resilience4JHandlerTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shenyu.plugin.resilience4j.handler;
+
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.convert.rule.Resilience4JHandle;
+import org.apache.shenyu.plugin.base.cache.CommonHandleCache;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.function.Supplier;
+
+/**
+ * The Test Case For Resilience4JHandler.
+ */
+public final class Resilience4JHandlerTest {
+
+    private Resilience4JHandler resilience4JHandler = new 
Resilience4JHandler();
+
+    private RuleData ruleData = new RuleData();
+
+    @Test
+    public void testHandlerRule() {
+        ruleData.setSelectorId("1");
+        ruleData.setHandle("{\"urlPath\":\"test\"}");
+        ruleData.setName("test");
+        resilience4JHandler.handlerRule(ruleData);
+        Supplier<CommonHandleCache<String, Resilience4JHandle>> cache = 
resilience4JHandler.CACHED_HANDLE;
+        Assertions.assertNotNull(cache.get().obtainHandle("1_test"));
+    }
+
+    @Test
+    public void testRemoveRule() {
+        ruleData.setSelectorId("1");
+        ruleData.setHandle("{\"urlPath\":\"test\"}");
+        ruleData.setName("test");
+        Supplier<CommonHandleCache<String, Resilience4JHandle>> cache = 
resilience4JHandler.CACHED_HANDLE;
+        cache.get().cachedHandle("1_test", new Resilience4JHandle());
+        Assertions.assertNotNull(cache.get().obtainHandle("1_test"));
+        resilience4JHandler.removeRule(ruleData);
+        Assertions.assertNull(cache.get().obtainHandle("1_test"));
+    }
+
+    @Test
+    public void testPluginNamed() {
+        Assertions.assertEquals(resilience4JHandler.pluginNamed(), 
"resilience4j");
+    }
+
+}

Reply via email to