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 2020/03/31 10:58:40 UTC

[servicecomb-java-chassis] branch master updated (50b8b08 -> f79d90e)

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git.


    from 50b8b08  [SCB-1154]invocation related log must invoke with marker
     new 284b3dd  [SCB-1824]jacskon convertValue will convert all objects start for 2.10.*, java-chassis need not convert RestTemplate arguments
     new f79d90e  [SCB-1824] fix unit test random fail due to MockClasses.getMock throw NPE

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../foundation/common/utils/RestObjectMapper.java  |  15 +++
 ...cker.java => TestInstanceCacheCheckerMock.java} |  64 ++----------
 .../TestInstanceCacheCheckerWithoutMock.java       | 116 +++++++++++++++++++++
 3 files changed, 140 insertions(+), 55 deletions(-)
 rename service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/{TestInstanceCacheChecker.java => TestInstanceCacheCheckerMock.java} (83%)
 create mode 100644 service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheCheckerWithoutMock.java


[servicecomb-java-chassis] 01/02: [SCB-1824]jacskon convertValue will convert all objects start for 2.10.*, java-chassis need not convert RestTemplate arguments

Posted by li...@apache.org.
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

commit 284b3dd64bf92243169395e3df8d2c11e29f176b
Author: liubao <bi...@qq.com>
AuthorDate: Mon Mar 30 17:37:33 2020 +0800

    [SCB-1824]jacskon convertValue will convert all objects start for 2.10.*, java-chassis need not convert RestTemplate arguments
---
 .../foundation/common/utils/RestObjectMapper.java         | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/RestObjectMapper.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/RestObjectMapper.java
index cd2ceb2..7a57691 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/RestObjectMapper.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/RestObjectMapper.java
@@ -84,7 +84,22 @@ public class RestObjectMapper extends AbstractRestObjectMapper {
   }
 
   @Override
+  @SuppressWarnings("unchecked")
   public <T> T convertValue(Object fromValue, JavaType toValueType) throws IllegalArgumentException {
+    // After jackson 2.10.*, will by pass the following check when convert value. But this is useful
+    // for java chassis applications and do not need to convert. So add the check here.(conversion is
+    // not necessary and will cause some trouble in some user applications that depend on this)
+    if (fromValue == null) {
+      return null;
+    } else {
+      Class<?> targetType = toValueType.getRawClass();
+      if (targetType != Object.class
+          && !toValueType.hasGenericTypes()
+          && targetType.isAssignableFrom(fromValue.getClass())) {
+        return (T) fromValue;
+      }
+    }
+
     return super.convertValue(fromValue, toValueType);
   }
 }


[servicecomb-java-chassis] 02/02: [SCB-1824] fix unit test random fail due to MockClasses.getMock throw NPE

Posted by li...@apache.org.
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

commit f79d90e11021b7bd154a20c448e3773a9dd7f439
Author: liubao <bi...@qq.com>
AuthorDate: Tue Mar 31 11:11:16 2020 +0800

    [SCB-1824] fix unit test random fail due to MockClasses.getMock throw NPE
---
 ...cker.java => TestInstanceCacheCheckerMock.java} |  64 ++----------
 .../TestInstanceCacheCheckerWithoutMock.java       | 116 +++++++++++++++++++++
 2 files changed, 125 insertions(+), 55 deletions(-)

diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheChecker.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheCheckerMock.java
similarity index 83%
rename from service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheChecker.java
rename to service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheCheckerMock.java
index 01d7cca..8df0ebb 100644
--- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheChecker.java
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheCheckerMock.java
@@ -16,10 +16,7 @@
  */
 package org.apache.servicecomb.serviceregistry.diagnosis.instance;
 
-import io.vertx.core.json.Json;
-import mockit.Deencapsulation;
-import mockit.Mock;
-import mockit.MockUp;
+import java.util.ArrayList;
 
 import org.apache.servicecomb.foundation.common.Holder;
 import org.apache.servicecomb.foundation.common.testing.MockClock;
@@ -30,7 +27,6 @@ import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
 import org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse;
 import org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances;
 import org.apache.servicecomb.serviceregistry.consumer.AppManager;
-import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule;
 import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersions;
 import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
 import org.apache.servicecomb.serviceregistry.diagnosis.Status;
@@ -42,12 +38,13 @@ import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
+import io.vertx.core.json.Json;
+import mockit.Deencapsulation;
+import mockit.Mock;
+import mockit.MockUp;
 
-public class TestInstanceCacheChecker {
-  private static final Logger LOGGER = LoggerFactory.getLogger(TestInstanceCacheChecker.class);
+public class TestInstanceCacheCheckerMock {
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestInstanceCacheCheckerWithoutMock.class);
 
   AppManager originalAppManager = RegistryUtils.getAppManager();
 
@@ -80,27 +77,7 @@ public class TestInstanceCacheChecker {
     RegistryUtils.setServiceRegistry(null);
   }
 
-  @Test
-  public void check_appManager_empty() {
-    InstanceCacheSummary instanceCacheSummary = checker.check();
-
-    Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
-  }
-
-  @Test
-  public void check_microserviceManager_empty() {
-    try {
-      appId = "notExist";
-      RegistryUtils.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
-      InstanceCacheSummary instanceCacheSummary = checker.check();
-      Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
-    } catch (Exception e) {
-      LOGGER.error("", e);
-      Assert.fail();
-    }
-  }
-
-  protected Holder<MicroserviceInstances> createFindServiceInstancesResult() {
+  private Holder<MicroserviceInstances> createFindServiceInstancesResult() {
     MicroserviceInstances microserviceInstances = new MicroserviceInstances();
     microserviceInstances.setNeedRefresh(true);
     microserviceInstances.setRevision("first");
@@ -113,7 +90,7 @@ public class TestInstanceCacheChecker {
     return findHolder;
   }
 
-  protected void registerMicroservice(String appId, String microserviceName) {
+  private void registerMicroservice(String appId, String microserviceName) {
     Microservice microservice = new Microservice();
     microservice.setAppId(appId);
     microservice.setServiceName(microserviceName);
@@ -266,27 +243,4 @@ public class TestInstanceCacheChecker {
     Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
     Assert.assertNull(microserviceVersions.getRevision());
   }
-
-  @Test
-  public void check_StaticMicroservice() {
-    microserviceName = appId + ":" + microserviceName;
-    serviceRegistry.registerMicroserviceMappingByEndpoints(microserviceName,
-        "1",
-        Arrays.asList("rest://localhost:8080"),
-        ThirdPartyServiceForUT.class);
-
-    MicroserviceVersionRule microserviceVersionRule = RegistryUtils.getAppManager()
-        .getOrCreateMicroserviceVersionRule(appId, microserviceName, DefinitionConst.VERSION_RULE_ALL);
-    Assert.assertEquals(microserviceName, microserviceVersionRule.getLatestMicroserviceVersion().getMicroserviceName());
-
-    InstanceCacheSummary instanceCacheSummary = checker.check();
-
-    expectedSummary.setStatus(Status.NORMAL);
-
-    Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
-  }
-
-  private interface ThirdPartyServiceForUT {
-    String sayHello(String name);
-  }
 }
diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheCheckerWithoutMock.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheCheckerWithoutMock.java
new file mode 100644
index 0000000..6edc0b2
--- /dev/null
+++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/diagnosis/instance/TestInstanceCacheCheckerWithoutMock.java
@@ -0,0 +1,116 @@
+/*
+ * 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.servicecomb.serviceregistry.diagnosis.instance;
+
+import java.util.Arrays;
+
+import org.apache.servicecomb.foundation.common.Holder;
+import org.apache.servicecomb.foundation.common.testing.MockClock;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.apache.servicecomb.serviceregistry.ServiceRegistry;
+import org.apache.servicecomb.serviceregistry.consumer.AppManager;
+import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule;
+import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
+import org.apache.servicecomb.serviceregistry.diagnosis.Status;
+import org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.vertx.core.json.Json;
+import mockit.Deencapsulation;
+
+public class TestInstanceCacheCheckerWithoutMock {
+  private static final Logger LOGGER = LoggerFactory.getLogger(TestInstanceCacheCheckerWithoutMock.class);
+
+  AppManager originalAppManager = RegistryUtils.getAppManager();
+
+  ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
+
+  InstanceCacheChecker checker;
+
+  InstanceCacheSummary expectedSummary = new InstanceCacheSummary();
+
+  String appId = "appId";
+
+  String microserviceName = "msName";
+
+  @Before
+  public void setUp() throws Exception {
+    Deencapsulation.setField(RegistryUtils.class, "appManager", new AppManager());
+
+    serviceRegistry.init();
+    RegistryUtils.setServiceRegistry(serviceRegistry);
+
+    checker = new InstanceCacheChecker(RegistryUtils.getAppManager());
+    checker.clock = new MockClock(new Holder<>(1L));
+    expectedSummary.setStatus(Status.NORMAL);
+    expectedSummary.setTimestamp(1);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    Deencapsulation.setField(RegistryUtils.class, "appManager", originalAppManager);
+    RegistryUtils.setServiceRegistry(null);
+  }
+
+  @Test
+  public void check_appManager_empty() {
+    InstanceCacheSummary instanceCacheSummary = checker.check();
+
+    Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
+  }
+
+  @Test
+  public void check_microserviceManager_empty() {
+    try {
+      appId = "notExist";
+      RegistryUtils.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
+      InstanceCacheSummary instanceCacheSummary = checker.check();
+      Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
+    } catch (Exception e) {
+      LOGGER.error("", e);
+      Assert.fail();
+    }
+  }
+
+  @Test
+  public void check_StaticMicroservice() {
+    microserviceName = appId + ":" + microserviceName;
+    serviceRegistry.registerMicroserviceMappingByEndpoints(microserviceName,
+        "1",
+        Arrays.asList("rest://localhost:8080"),
+        ThirdPartyServiceForUT.class);
+
+    MicroserviceVersionRule microserviceVersionRule = RegistryUtils.getAppManager()
+        .getOrCreateMicroserviceVersionRule(appId, microserviceName, DefinitionConst.VERSION_RULE_ALL);
+    Assert.assertEquals(microserviceName, microserviceVersionRule.getLatestMicroserviceVersion().getMicroserviceName());
+
+    InstanceCacheSummary instanceCacheSummary = checker.check();
+
+    expectedSummary.setStatus(Status.NORMAL);
+
+    Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
+  }
+
+  private interface ThirdPartyServiceForUT {
+    String sayHello(String name);
+  }
+}