JooKS-me commented on a change in pull request #2985:
URL: https://github.com/apache/incubator-shenyu/pull/2985#discussion_r825889234



##########
File path: 
shenyu-examples/shenyu-examples-http/src/main/java/org/apache/shenyu/examples/http/controller/HttpTestController.java
##########
@@ -367,4 +367,30 @@ private UserDTO buildUser(final String id, final String 
name) {
         userDTO.setUserName(name);
         return userDTO;
     }
+
+    /**
+     * the waf pass.
+     *
+     * @return response. result bean
+     */
+    @GetMapping ("/hystrix/pass")
+    public ResultBean hystrixPass() {

Review comment:
       IMO, we can reuse existing endpoint, no need to add new ones, WDYT?

##########
File path: 
shenyu-web/src/main/java/org/apache/shenyu/web/fallback/DefaultFallbackController.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.web.fallback;
+
+import org.apache.shenyu.plugin.api.result.ShenyuResultEnum;
+import org.apache.shenyu.plugin.api.result.ShenyuResultWrap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * The default fallback for hystrix plugin and resilience4j plugin.
+ */
+@RestController
+@RequestMapping("/fallback")
+public class DefaultFallbackController {

Review comment:
       Is this a duplicate of #3028?

##########
File path: 
shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/HystrixPluginTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.integrated.test.http.combination;
+
+import com.google.gson.reflect.TypeToken;
+import org.apache.shenyu.common.dto.ConditionData;
+import org.apache.shenyu.common.dto.convert.rule.HystrixHandle;
+import org.apache.shenyu.common.enums.HystrixIsolationModeEnum;
+import org.apache.shenyu.common.enums.OperatorEnum;
+import org.apache.shenyu.common.enums.ParamTypeEnum;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
+import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
+import org.apache.shenyu.integratedtest.common.result.ResultBean;
+import org.apache.shenyu.web.controller.LocalPluginController.RuleLocalData;
+import org.hamcrest.CoreMatchers;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.lang.reflect.Type;
+
+import java.util.HashSet;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.stream.Stream;
+import java.util.Map;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public final class HystrixPluginTest extends AbstractPluginDataInit {
+
+    private static final String TEST_HYSTRIX_PATH = "/http/test/hystrix/pass";
+
+    private static final String TEST_HYSTRIX_BAD_REQUEST_PATH = 
"/http/test/hystrix/fallback";
+
+    @BeforeEach
+    public void setup() throws IOException {
+        String pluginResult = initPlugin(PluginEnum.HYSTRIX.getName(), "");
+        assertThat(pluginResult, is("success"));
+    }
+
+    @Test
+    public void testPass() throws IOException, ExecutionException, 
InterruptedException {
+        String selectorAndRulesResult =
+                initSelectorAndRules(PluginEnum.HYSTRIX.getName(), "", 
buildSelectorConditionList(), buildRuleLocalDataList(TEST_HYSTRIX_PATH));
+        assertThat(selectorAndRulesResult, is("success"));
+        Future<ResultBean> resp = this.getService().submit(() -> 
HttpHelper.INSTANCE.getFromGateway(TEST_HYSTRIX_PATH, ResultBean.class));
+        assertEquals(200, resp.get().getCode());
+    }
+
+    @Test
+    public void testFallbackBySmeaphore() throws IOException, 
ExecutionException, InterruptedException {

Review comment:
       typo(`Smeaphore`) :)

##########
File path: 
shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/HystrixPluginTest.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.integrated.test.http.combination;
+
+import com.google.gson.reflect.TypeToken;
+import org.apache.shenyu.common.dto.ConditionData;
+import org.apache.shenyu.common.dto.convert.rule.HystrixHandle;
+import org.apache.shenyu.common.enums.HystrixIsolationModeEnum;
+import org.apache.shenyu.common.enums.OperatorEnum;
+import org.apache.shenyu.common.enums.ParamTypeEnum;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
+import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
+import org.apache.shenyu.integratedtest.common.result.ResultBean;
+import org.apache.shenyu.web.controller.LocalPluginController.RuleLocalData;
+import org.hamcrest.CoreMatchers;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.lang.reflect.Type;
+
+import java.util.HashSet;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.stream.Stream;
+import java.util.Map;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public final class HystrixPluginTest extends AbstractPluginDataInit {
+
+    private static final String TEST_HYSTRIX_PATH = "/http/test/hystrix/pass";
+
+    private static final String TEST_HYSTRIX_BAD_REQUEST_PATH = 
"/http/test/hystrix/fallback";
+
+    @BeforeEach
+    public void setup() throws IOException {
+        String pluginResult = initPlugin(PluginEnum.HYSTRIX.getName(), "");
+        assertThat(pluginResult, is("success"));
+    }
+
+    @Test
+    public void testPass() throws IOException, ExecutionException, 
InterruptedException {
+        String selectorAndRulesResult =
+                initSelectorAndRules(PluginEnum.HYSTRIX.getName(), "", 
buildSelectorConditionList(), buildRuleLocalDataList(TEST_HYSTRIX_PATH));
+        assertThat(selectorAndRulesResult, is("success"));
+        Future<ResultBean> resp = this.getService().submit(() -> 
HttpHelper.INSTANCE.getFromGateway(TEST_HYSTRIX_PATH, ResultBean.class));
+        assertEquals(200, resp.get().getCode());
+    }
+
+    @Test
+    public void testFallbackBySmeaphore() throws IOException, 
ExecutionException, InterruptedException {
+        String selectorAndRulesResult =
+                initSelectorAndRules(PluginEnum.HYSTRIX.getName(), "", 
buildSelectorConditionList(), 
buildRuleLocalDataList(TEST_HYSTRIX_BAD_REQUEST_PATH));
+        assertThat(selectorAndRulesResult, CoreMatchers.is("success"));
+        Set<String> resultSet = new HashSet<>();
+        Type returnType = new TypeToken<Map<String, Object>>() {
+        }.getType();
+        Future<Map<String, Object>> resp = this.getService().submit(() -> 
HttpHelper.INSTANCE.getFromGateway(TEST_HYSTRIX_BAD_REQUEST_PATH, returnType));

Review comment:
       It would be better to change the variable name to `resp0`~




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to