Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hubgeter committed Dec 31, 2024
1 parent 0e7ed4c commit 0107863
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class RestBaseController extends BaseController {
protected static final String TXN_ID_KEY = "txn_id";
protected static final String TXN_OPERATION_KEY = "txn_operation";
protected static final String SINGLE_REPLICA_KEY = "single_replica";
protected static final String FORBID_FORWARD_UT_TEST = "forbid_forward_ut_test";
protected static final String FORWARD_MASTER_UT_TEST = "forward_master_ut_test";
private static final Logger LOG = LogManager.getLogger(RestBaseController.class);

public ActionAuthorizationInfo executeCheckPassword(HttpServletRequest request,
Expand Down Expand Up @@ -224,11 +224,10 @@ public Object forwardToMaster(HttpServletRequest request) {

public boolean checkForwardToMaster(HttpServletRequest request) {
if (FeConstants.runningUnitTest) {
String forbidForward = request.getHeader(FORBID_FORWARD_UT_TEST);
String forbidForward = request.getHeader(FORWARD_MASTER_UT_TEST);
if (forbidForward != null) {
return !"true".equals(forbidForward);
return "true".equals(forbidForward);
}
return true;
}
return !Env.getCurrentEnv().isMaster();
}
Expand Down Expand Up @@ -258,8 +257,8 @@ public Object forwardToMaster(HttpServletRequest request, @Nullable Object body)
}

if (FeConstants.runningUnitTest) {
//Add a header to avoid forward.
headers.add(FORBID_FORWARD_UT_TEST, "true");
//remove header to avoid forward.
headers.remove(FORWARD_MASTER_UT_TEST);
}

HttpEntity<Object> entity = new HttpEntity<>(body, headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void testAddBeDropBe() throws Exception {
Request request = new Request.Builder()
.get()
.addHeader("Authorization", rootAuth)
.addHeader("forward_master_ut_test", "true")
.url(url)
.build();
Response response = networkClient.newCall(request).execute();
Expand Down Expand Up @@ -76,6 +77,7 @@ public void testAddBeDropBe() throws Exception {
.url(url)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", rootAuth)
.addHeader("forward_master_ut_test", "true")
.post(RequestBody.create(jsonBody, MediaType.parse("application/json")))
.build();
Response response = networkClient.newCall(request).execute();
Expand All @@ -88,6 +90,7 @@ public void testAddBeDropBe() throws Exception {
Request request = new Request.Builder()
.get()
.addHeader("Authorization", rootAuth)
.addHeader("forward_master_ut_test", "true")
.url(url)
.build();
Response response = networkClient.newCall(request).execute();
Expand Down Expand Up @@ -125,6 +128,7 @@ public void testAddBeDropBe() throws Exception {
.url(url)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", rootAuth)
.addHeader("forward_master_ut_test", "true")
.post(RequestBody.create(jsonBody, MediaType.parse("application/json")))
.build();
Response response = networkClient.newCall(request).execute();
Expand All @@ -136,6 +140,7 @@ public void testAddBeDropBe() throws Exception {
String url = "http://localhost:" + HTTP_PORT + "/rest/v2/manager/node/backends";
Request request = new Request.Builder()
.get()
.addHeader("forward_master_ut_test", "true")
.addHeader("Authorization", rootAuth)
.url(url)
.build();
Expand Down Expand Up @@ -168,6 +173,7 @@ public void testPost1() throws Exception {
Request request = new Request.Builder()
.url(url)
.addHeader("Authorization", rootAuth)
.addHeader("forward_master_ut_test", "true")
.post(emptyBody)
.build();
Response response = networkClient.newCall(request).execute();
Expand All @@ -192,6 +198,7 @@ public void testPost2() throws Exception {
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.addHeader("forward_master_ut_test", "true")
.addHeader("Authorization", rootAuth)
.build();
Response response = networkClient.newCall(request).execute();
Expand All @@ -211,6 +218,7 @@ public void testGet1() throws Exception {
Request request = new Request.Builder()
.get()
.addHeader("Authorization", rootAuth)
.addHeader("forward_master_ut_test", "true")
.url(url)
.build();
Response response = networkClient.newCall(request).execute();
Expand Down

0 comments on commit 0107863

Please sign in to comment.