You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/03/19 02:33:08 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2221]add
customized executor at service level (#2300)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new c1e02e5 [SCB-2221]add customized executor at service level (#2300)
c1e02e5 is described below
commit c1e02e512e593333caefcc98621dbdfb3da3d316
Author: wxkwxkwxk1231 <ka...@protonmail.com>
AuthorDate: Fri Mar 19 10:32:57 2021 +0800
[SCB-2221]add customized executor at service level (#2300)
* modify ExecutorManager
* modify ExecutorManager test cases
* make it compatible to old version
---
.../servicecomb/core/executor/ExecutorManager.java | 23 ++++++++++++++++++++--
.../core/executor/TestExecutorManager.java | 23 ++++++++++++----------
2 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/core/src/main/java/org/apache/servicecomb/core/executor/ExecutorManager.java b/core/src/main/java/org/apache/servicecomb/core/executor/ExecutorManager.java
index 1df1a16..bfa38ef 100644
--- a/core/src/main/java/org/apache/servicecomb/core/executor/ExecutorManager.java
+++ b/core/src/main/java/org/apache/servicecomb/core/executor/ExecutorManager.java
@@ -58,7 +58,13 @@ public class ExecutorManager {
}
public Executor findExecutor(OperationMeta operationMeta, Executor defaultOperationExecutor) {
- Executor executor = findByKey(KEY_EXECUTORS_PREFIX + operationMeta.getSchemaQualifiedName());
+ // operation级别
+ Executor executor = findByKey(KEY_EXECUTORS_PREFIX + operationMeta.getMicroserviceQualifiedName());
+ if (executor != null) {
+ return executor;
+ }
+
+ executor = findByKey(KEY_EXECUTORS_PREFIX + operationMeta.getSchemaQualifiedName());
if (executor != null) {
return executor;
}
@@ -67,12 +73,25 @@ public class ExecutorManager {
return defaultOperationExecutor;
}
- // 尝试schema级别
+ // schema级别
+ executor = findByKey(
+ KEY_EXECUTORS_PREFIX + operationMeta.getMicroserviceName() + '.' + operationMeta.getSchemaId());
+ if (executor != null) {
+ return executor;
+ }
+
executor = findByKey(KEY_EXECUTORS_PREFIX + operationMeta.getSchemaId());
if (executor != null) {
return executor;
}
+ // microservice级别
+ executor = findByKey(KEY_EXECUTORS_PREFIX + operationMeta.getMicroserviceName());
+ if (executor != null) {
+ return executor;
+ }
+
+ // 寻找config-key指定的default
executor = findByKey(KEY_EXECUTORS_DEFAULT);
if (executor != null) {
return executor;
diff --git a/core/src/test/java/org/apache/servicecomb/core/executor/TestExecutorManager.java b/core/src/test/java/org/apache/servicecomb/core/executor/TestExecutorManager.java
index c6095d5..3165d45 100644
--- a/core/src/test/java/org/apache/servicecomb/core/executor/TestExecutorManager.java
+++ b/core/src/test/java/org/apache/servicecomb/core/executor/TestExecutorManager.java
@@ -59,13 +59,14 @@ public class TestExecutorManager {
@Test
public void findExecutor_twoParam_opCfg_withoutOpDef(@Mocked Executor executor,
@Mocked OperationMeta operationMeta) {
- String schemaQualifiedName = "schemaId.opId";
+ // String schemaQualifiedName = "schemaId.opId";
+ String microserviceQualifiedName = "microserviceName.schemaId.opId";
String opBeanId = "opBeanId";
- ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + schemaQualifiedName, opBeanId);
+ ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceQualifiedName, opBeanId);
new Expectations(BeanUtils.class) {
{
- operationMeta.getSchemaQualifiedName();
- result = schemaQualifiedName;
+ operationMeta.getMicroserviceQualifiedName();
+ result = microserviceQualifiedName;
BeanUtils.getBean(opBeanId);
result = executor;
}
@@ -78,13 +79,13 @@ public class TestExecutorManager {
public void findExecutor_twoParam_opCfg_withOpDef(@Mocked Executor executor,
@Mocked Executor defExecutor,
@Mocked OperationMeta operationMeta) {
- String schemaQualifiedName = "schemaId.opId";
+ String microserviceQualifiedName = "microserviceName.schemaId.opId";
String opBeanId = "opBeanId";
- ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + schemaQualifiedName, opBeanId);
+ ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceQualifiedName, opBeanId);
new Expectations(BeanUtils.class) {
{
- operationMeta.getSchemaQualifiedName();
- result = schemaQualifiedName;
+ operationMeta.getMicroserviceQualifiedName();
+ result = microserviceQualifiedName;
BeanUtils.getBean(opBeanId);
result = executor;
}
@@ -102,18 +103,20 @@ public class TestExecutorManager {
@Test
public void findExecutor_twoParam_schemaCfg_withoutOpDef(@Mocked Executor executor,
@Mocked OperationMeta operationMeta) {
+ String microserviceName = "serviceName";
String schemaName = "schemaId";
String opBeanId = "opBeanId";
- ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + schemaName, opBeanId);
+ ArchaiusUtils.setProperty(ExecutorManager.KEY_EXECUTORS_PREFIX + microserviceName + "." + schemaName, opBeanId);
new Expectations(BeanUtils.class) {
{
operationMeta.getSchemaId();
result = schemaName;
+ operationMeta.getMicroserviceName();
+ result = microserviceName;
BeanUtils.getBean(opBeanId);
result = executor;
}
};
-
Assert.assertSame(executor, new ExecutorManager().findExecutor(operationMeta, null));
}