1
0
mirror of https://github.com/apache/dubbo.git synced 2024-10-23 07:04:37 +08:00

Change some test-related error code to a separate series. (#11219)

* Revert changes in FailsafeLoggerTest.

* COMMON_FAILED_REFLECT -> COMMON_REFLECTIVE_OPERATION_FAILED. Add 81-1.

* 1-25 -> 81-2.

* 1-23 / 5-19 -> 81-3 / 81-4.
This commit is contained in:
Andy Cheung 2022-12-30 15:50:42 +08:00 committed by GitHub
parent e86e6e3209
commit 2c6a933d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 64 additions and 44 deletions

View File

@ -37,7 +37,7 @@ public interface LoggerCodeConstants {
String COMMON_CLASS_NOT_FOUND = "0-7";
String COMMON_FAILED_REFLECT = "0-8";
String COMMON_REFLECTIVE_OPERATION_FAILED = "0-8";
String COMMON_FAILED_NOTIFY_EVENT = "0-9";
@ -124,10 +124,19 @@ public interface LoggerCodeConstants {
String REGISTRY_UNABLE_ACCESS_KUBERNETES = "1-22";
/**
* Absent. Original '1-23' is changed to '81-3'.
*/
String REGISTRY_FAILED_DOWNLOAD_FILE = "1-23";
/**
* Absent. Original '1-24' is changed to '81-1'.
*/
String REGISTRY_FAILED_START_ZOOKEEPER = "1-24";
/**
* Absent. Original '1-25' is changed to '81-2'.
*/
String REGISTRY_FAILED_STOP_ZOOKEEPER = "1-25";
String REGISTRY_FAILED_GENERATE_CERT_ISTIO = "1-26";
@ -161,7 +170,7 @@ public interface LoggerCodeConstants {
String REGISTRY_FAILED_LOAD_METADATA = "1-39";
// cluster module
// Cluster module
String CLUSTER_FAILED_SITE_SELECTION = "2-1";
String CLUSTER_NO_VALID_PROVIDER = "2-2";
@ -258,7 +267,7 @@ public interface LoggerCodeConstants {
String PROTOCOL_FAILED_DECODE = "4-20";
// config module
// Config module
String CONFIG_FAILED_CONNECT_REGISTRY = "5-1";
String CONFIG_FAILED_SHUTDOWN_HOOK = "5-2";
@ -295,6 +304,9 @@ public interface LoggerCodeConstants {
String CONFIG_FAILED_NOTIFY_EVENT = "5-18";
/**
* Absent. Changed to 81-4.
*/
String CONFIG_ZOOKEEPER_SERVER_ERROR = "5-19";
String CONFIG_STOP_DUBBO_ERROR = "5-20";
@ -339,7 +351,7 @@ public interface LoggerCodeConstants {
String CONFIG_DUBBO_BEAN_NOT_FOUND = "5-40";
// transport module
// Transport module
String TRANSPORT_FAILED_CONNECT_PROVIDER = "6-1";
String TRANSPORT_CLIENT_CONNECT_TIMEOUT = "6-2";
@ -385,6 +397,15 @@ public interface LoggerCodeConstants {
String QOS_UNEXPECTED_EXCEPTION = "7-6";
// Testing module (8[X], where [X] is number of the module to be tested.)
String TESTING_REGISTRY_FAILED_TO_START_ZOOKEEPER = "81-1";
String TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER = "81-2";
String TESTING_REGISTRY_FAILED_TO_DOWNLOAD_ZK_FILE = "81-3";
String TESTING_INIT_ZOOKEEPER_SERVER_ERROR = "81-4";
// Internal unknown error.
/**

View File

@ -58,7 +58,7 @@ import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_REFLECT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_REFLECTIVE_OPERATION_FAILED;
import static org.apache.dubbo.common.utils.ClassUtils.isAssignableFrom;
/**
@ -526,7 +526,7 @@ public class PojoUtils {
} catch (Exception e) {
String exceptionDescription = "Failed to set pojo " + dest.getClass().getSimpleName() + " property " + name
+ " value " + value.getClass() + ", cause: " + e.getMessage();
logger.error(COMMON_FAILED_REFLECT, "", "", exceptionDescription, e);
logger.error(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", exceptionDescription, e);
throw new RuntimeException(exceptionDescription, e);
}
} else if (field != null) {

View File

@ -61,7 +61,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_OVERRIDE_FIELD;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_REFLECT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_REFLECTIVE_OPERATION_FAILED;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.utils.ClassUtils.isSimpleType;
import static org.apache.dubbo.common.utils.ReflectUtils.findMethodByMethodSignature;
@ -507,7 +507,7 @@ public abstract class AbstractConfig implements Serializable {
}
}
} catch (Throwable e) {
logger.error(COMMON_FAILED_REFLECT, "", "", e.getMessage(), e);
logger.error(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", e.getMessage(), e);
}
}
}

View File

@ -32,7 +32,7 @@ import java.util.stream.Stream;
import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE;
import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE_ASYNC;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_REFLECT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_REFLECTIVE_OPERATION_FAILED;
public class ReflectionMethodDescriptor implements MethodDescriptor {
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(ReflectionMethodDescriptor.class);
@ -58,7 +58,7 @@ public class ReflectionMethodDescriptor implements MethodDescriptor {
try {
returnTypesResult = ReflectUtils.getReturnTypes(method);
} catch (Throwable throwable) {
logger.error(COMMON_FAILED_REFLECT, "", "",
logger.error(COMMON_REFLECTIVE_OPERATION_FAILED, "", "",
"fail to get return types. Method name: " + methodName + " Declaring class:" + method.getDeclaringClass()
.getName(), throwable);
returnTypesResult = new Type[]{returnClass, returnClass};

View File

@ -21,7 +21,6 @@ import org.apache.dubbo.common.logger.Logger;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
@ -32,7 +31,7 @@ class FailsafeLoggerTest {
@Test
void testFailSafeForLoggingMethod() {
Logger failLogger = mock(Logger.class);
FailsafeErrorTypeAwareLogger failsafeLogger = new FailsafeErrorTypeAwareLogger(failLogger);
FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger);
doThrow(new RuntimeException()).when(failLogger).error(anyString());
doThrow(new RuntimeException()).when(failLogger).warn(anyString());
@ -40,8 +39,8 @@ class FailsafeLoggerTest {
doThrow(new RuntimeException()).when(failLogger).debug(anyString());
doThrow(new RuntimeException()).when(failLogger).trace(anyString());
failsafeLogger.error(COMMON_UNEXPECTED_EXCEPTION, "", "", "error");
failsafeLogger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "warn");
failsafeLogger.error("error");
failsafeLogger.warn("warn");
failsafeLogger.info("info");
failsafeLogger.debug("debug");
failsafeLogger.trace("info");
@ -52,14 +51,14 @@ class FailsafeLoggerTest {
doThrow(new RuntimeException()).when(failLogger).debug(any(Throwable.class));
doThrow(new RuntimeException()).when(failLogger).trace(any(Throwable.class));
failsafeLogger.error(COMMON_UNEXPECTED_EXCEPTION, "", "", "error", new Exception("error"));
failsafeLogger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "warn", new Exception("warn"));
failsafeLogger.error(new Exception("error"));
failsafeLogger.warn(new Exception("warn"));
failsafeLogger.info(new Exception("info"));
failsafeLogger.debug(new Exception("debug"));
failsafeLogger.trace(new Exception("trace"));
failsafeLogger.error(COMMON_UNEXPECTED_EXCEPTION, "", "", "error", new Exception("error"));
failsafeLogger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "warn", new Exception("warn"));
failsafeLogger.error("error", new Exception("error"));
failsafeLogger.warn("warn", new Exception("warn"));
failsafeLogger.info("info", new Exception("info"));
failsafeLogger.debug("debug", new Exception("debug"));
failsafeLogger.trace("trace", new Exception("trace"));
@ -68,9 +67,9 @@ class FailsafeLoggerTest {
@Test
void testSuccessLogger() {
Logger successLogger = mock(Logger.class);
FailsafeErrorTypeAwareLogger failsafeLogger = new FailsafeErrorTypeAwareLogger(successLogger);
failsafeLogger.error(COMMON_UNEXPECTED_EXCEPTION, "", "", "error");
failsafeLogger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "warn");
FailsafeLogger failsafeLogger = new FailsafeLogger(successLogger);
failsafeLogger.error("error");
failsafeLogger.warn("warn");
failsafeLogger.info("info");
failsafeLogger.debug("debug");
failsafeLogger.trace("info");
@ -81,14 +80,14 @@ class FailsafeLoggerTest {
verify(successLogger).debug(anyString());
verify(successLogger).trace(anyString());
failsafeLogger.error(COMMON_UNEXPECTED_EXCEPTION, "", "", "error", new Exception("error"));
failsafeLogger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "warn", new Exception("warn"));
failsafeLogger.error(new Exception("error"));
failsafeLogger.warn(new Exception("warn"));
failsafeLogger.info(new Exception("info"));
failsafeLogger.debug(new Exception("debug"));
failsafeLogger.trace(new Exception("trace"));
failsafeLogger.error(COMMON_UNEXPECTED_EXCEPTION, "", "", "error", new Exception("error"));
failsafeLogger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "warn", new Exception("warn"));
failsafeLogger.error("error", new Exception("error"));
failsafeLogger.warn("warn", new Exception("warn"));
failsafeLogger.info("info", new Exception("info"));
failsafeLogger.debug("debug", new Exception("debug"));
failsafeLogger.trace("trace", new Exception("trace"));
@ -98,10 +97,10 @@ class FailsafeLoggerTest {
void testGetLogger() {
Assertions.assertThrows(RuntimeException.class, () -> {
Logger failLogger = mock(Logger.class);
FailsafeErrorTypeAwareLogger failsafeLogger = new FailsafeErrorTypeAwareLogger(failLogger);
FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger);
doThrow(new RuntimeException()).when(failLogger).error(anyString());
failsafeLogger.getLogger().error("should get error");
});
}
}
}

View File

@ -29,8 +29,8 @@ import java.lang.reflect.Method;
import java.util.Properties;
import java.util.UUID;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_ZOOKEEPER_SERVER_ERROR;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_STOP_ZOOKEEPER;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_INIT_ZOOKEEPER_SERVER_ERROR;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER;
/**
* from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
@ -187,7 +187,7 @@ public class EmbeddedZooKeeper implements SmartLifecycle {
zkServerThread = null;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.warn(REGISTRY_FAILED_STOP_ZOOKEEPER, "", "", "Interrupted while waiting for embedded ZooKeeper to exit");
logger.warn(TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER, "", "", "Interrupted while waiting for embedded ZooKeeper to exit");
// abandoning zk thread
zkServerThread = null;
}
@ -240,7 +240,7 @@ public class EmbeddedZooKeeper implements SmartLifecycle {
if (errorHandler != null) {
errorHandler.handleError(e);
} else {
logger.error(CONFIG_ZOOKEEPER_SERVER_ERROR, "ZooKeeper server error", "", "Exception running embedded ZooKeeper.", e);
logger.error(TESTING_INIT_ZOOKEEPER_SERVER_ERROR, "ZooKeeper server error", "", "Exception running embedded ZooKeeper.", e);
}
}
}

View File

@ -44,7 +44,7 @@ import java.lang.reflect.Type;
import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE;
import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE_ASYNC;
import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_PARAMETER_DESC;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_REFLECT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_REFLECTIVE_OPERATION_FAILED;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
/**
@ -196,7 +196,7 @@ public class GenericImplFilter implements Filter, Filter.Listener {
}
field.set(targetException, exception.getExceptionMessage());
} catch (Throwable e) {
logger.warn(COMMON_FAILED_REFLECT, "", "", e.getMessage(), e);
logger.warn(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", e.getMessage(), e);
}
appResponse.setException(targetException);
} else if (lastException != null) {

View File

@ -38,7 +38,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_PARAMETE
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_ATTACHMENT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_ATTACHMENT_KEY_LOWER;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_REFLECT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_REFLECTIVE_OPERATION_FAILED;
import static org.apache.dubbo.rpc.Constants.$ECHO;
import static org.apache.dubbo.rpc.Constants.$ECHO_PARAMETER_DESC;
import static org.apache.dubbo.rpc.Constants.ASYNC_KEY;
@ -67,7 +67,7 @@ public class RpcUtils {
}
}
} catch (Throwable t) {
logger.warn(COMMON_FAILED_REFLECT, "", "", t.getMessage(), t);
logger.warn(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", t.getMessage(), t);
}
return null;
}
@ -97,7 +97,7 @@ public class RpcUtils {
}
}
} catch (Throwable t) {
logger.warn(COMMON_FAILED_REFLECT, "", "", t.getMessage(), t);
logger.warn(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", t.getMessage(), t);
}
return null;
}

View File

@ -52,7 +52,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.concurrent.Executor;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_FAILED_REFLECT;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_REFLECTIVE_OPERATION_FAILED;
/**
@ -215,7 +215,7 @@ public class TripleClientStream extends AbstractStream implements ClientStream {
}
});
} else {
LOGGER.error(COMMON_FAILED_REFLECT, "", "", "Triple convertNoLowerCaseHeader error, obj is not String");
LOGGER.error(COMMON_REFLECTIVE_OPERATION_FAILED, "", "", "Triple convertNoLowerCaseHeader error, obj is not String");
}
return attachments;
}

View File

@ -37,7 +37,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DOWNLOAD_FILE;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_DOWNLOAD_ZK_FILE;
/**
* Download zookeeper binary archive.
@ -169,7 +169,7 @@ public class DownloadZookeeperInitializer extends ZookeeperInitializer {
@Override
public void onThrowable(Throwable t) {
logger.warn(REGISTRY_FAILED_DOWNLOAD_FILE, "", "", "Failed to download the file, download url: " + url);
logger.warn(TESTING_REGISTRY_FAILED_TO_DOWNLOAD_ZK_FILE, "", "", "Failed to download the file, download url: " + url);
super.onThrowable(t);
}
});

View File

@ -29,8 +29,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_START_ZOOKEEPER;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_STOP_ZOOKEEPER;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_START_ZOOKEEPER;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER;
/**
* The abstract implementation of {@link Processor} is to provide some common methods on Unix OS.
@ -50,7 +50,7 @@ public abstract class ZookeeperUnixProcessor implements Processor {
try {
process.destroy();
} catch (Throwable cause) {
logger.warn(REGISTRY_FAILED_STOP_ZOOKEEPER, "", "", String.format("Failed to kill the process, with client port %s !", clientPort), cause);
logger.warn(TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER, "", "", String.format("Failed to kill the process, with client port %s !", clientPort), cause);
}
}
}
@ -64,7 +64,7 @@ public abstract class ZookeeperUnixProcessor implements Processor {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(errorStream))) {
String line;
while ((line = reader.readLine()) != null) {
logger.error(REGISTRY_FAILED_START_ZOOKEEPER,"","",line);
logger.error(TESTING_REGISTRY_FAILED_TO_START_ZOOKEEPER,"","",line);
}
} catch (IOException e) {
/* eat quietly */