Skip to content

Commit

Permalink
fix some comment
Browse files Browse the repository at this point in the history
  • Loading branch information
昱恒 committed Oct 18, 2021
1 parent c1a9bef commit 579d1f4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public class StopServerSwitch {
private boolean stopServer = false;

@JsonSetter(nulls = Nulls.SKIP)
private CauseEnum causeEnum;
private String cause;

public StopServerSwitch() {}

public StopServerSwitch(boolean stopServer) {
this.stopServer = stopServer;
}

public StopServerSwitch(boolean stopServer, CauseEnum causeEnum) {
public StopServerSwitch(boolean stopServer, String cause) {
this.stopServer = stopServer;
this.causeEnum = causeEnum;
this.cause = cause;
}

public static StopServerSwitch defaultSwitch() {
Expand All @@ -54,27 +54,28 @@ public boolean isStopServer() {
public void setStopServer(boolean stopServer) {
this.stopServer = stopServer;
}

/**
* Getter method for property <tt>causeEnum</tt>.
* Getter method for property <tt>cause</tt>.
*
* @return property value of causeEnum
* @return property value of cause
*/
public CauseEnum getCauseEnum() {
return causeEnum;
public String getCause() {
return cause;
}

/**
* Setter method for property <tt>causeEnum</tt>.
* Setter method for property <tt>cause</tt>.
*
* @param causeEnum value to be assigned to property causeEnum
* @param cause value to be assigned to property cause
*/
public void setCauseEnum(CauseEnum causeEnum) {
this.causeEnum = causeEnum;
public void setCause(String cause) {
this.cause = cause;
}

@Override
public String toString() {
return "StopServerSwitch{" + "stopServer=" + stopServer + ", causeEnum=" + causeEnum + '}';
return "StopServerSwitch{" + "stopServer=" + stopServer + ", cause=" + cause + '}';
}

public enum CauseEnum {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Alipay.com Inc.
* Copyright (c) 2004-2021 All Rights Reserved.
*/
package com.alipay.sofa.registry.server.meta.resource;

import org.apache.commons.lang.StringUtils;

/**
*
* @author xiaojian.xj
* @version : AuthChecker.java, v 0.1 2021年10月18日 14:22 xiaojian.xj Exp $
*/
public final class AuthChecker {

private static final String AUTH_TOKEN = "6c62lk8dmQoE5B8X";

public static boolean authCheck(String token) {
return StringUtils.equals(AUTH_TOKEN, token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ public class StopServerSwitchResource {
@POST
@Path("update")
@Produces(MediaType.APPLICATION_JSON)
public Result stop(@FormParam("stop") String stop) {
public Result stop(@FormParam("stop") String stop, @FormParam("token") String token) {

if (!AuthChecker.authCheck(token)) {
DB_LOGGER.error("update stopServerSwitch, stop={} auth check={} fail!", stop, token);
return Result.failed("auth check fail");
}
StopServerSwitch stopServerSwitch;
if (StringUtils.equalsIgnoreCase(stop, "true")) {
stopServerSwitch = new StopServerSwitch(true, CauseEnum.FORCE);
stopServerSwitch = new StopServerSwitch(true, CauseEnum.FORCE.getCause());
} else {
stopServerSwitch = new StopServerSwitch(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ public void beforeStopPushDataResourceTest() {
@Test
public void testStopServer() {

StopServerSwitch stopServerSwitch = new StopServerSwitch(true, CauseEnum.FORCE);
Result ret = stopPushDataResource.stop("true");
String token = "6c62lk8dmQoE5B8X";
StopServerSwitch stopServerSwitch = new StopServerSwitch(true, CauseEnum.FORCE.getCause());
Result ret = stopPushDataResource.stop("true", token);
Assert.assertTrue(ret.isSuccess());

Map<String, String> query = stopPushDataResource.query();

Assert.assertEquals(query.get("switch"), JsonUtils.writeValueAsString(stopServerSwitch));

ret = stopPushDataResource.stop("false");
ret = stopPushDataResource.stop("false", token);
Assert.assertTrue(ret.isSuccess());

stopServerSwitch = new StopServerSwitch(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void start() {
/** Destroy. */
public void destroy() {
doStop();
System.exit(0);
Runtime.getRuntime().halt(0);
}

private void doStop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void beforeFetchStopServerServiceTest() {
public void test() {
Assert.assertFalse(isStopServer());

StopServerSwitch stopServerSwitch = new StopServerSwitch(true, CauseEnum.FORCE);
StopServerSwitch stopServerSwitch = new StopServerSwitch(true, CauseEnum.FORCE.getCause());

when(fetchStopPushService.isStopPushSwitch()).thenReturn(false);
Assert.assertFalse(
Expand Down

0 comments on commit 579d1f4

Please sign in to comment.