Fix conflict
This commit is contained in:
parent
988768e589
commit
7a774d21a6
|
|
@ -17,11 +17,30 @@
|
|||
package org.apache.dubbo.common.json.impl;
|
||||
|
||||
import org.apache.dubbo.common.json.JSON;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractJSONImpl implements JSON {
|
||||
@Override
|
||||
public boolean isSupport() {
|
||||
try {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("json", "test");
|
||||
if (!CollectionUtils.mapEquals(map, toJavaObject(toJson(map), Map.class))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> list = new LinkedList<>();
|
||||
list.add("json");
|
||||
return CollectionUtils.equals(list, toJavaList(toJson(list), String.class));
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> getList(Map<String, ?> obj, String key) {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.json.impl;
|
||||
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
|
@ -25,16 +23,6 @@ import java.util.List;
|
|||
|
||||
public class FastJson2Impl extends AbstractJSONImpl {
|
||||
|
||||
@Override
|
||||
public boolean isSupport() {
|
||||
try {
|
||||
Class<?> aClass = ClassUtils.forName("com.alibaba.fastjson2.JSON");
|
||||
return aClass != null;
|
||||
} catch (Exception t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toJavaObject(String json, Type type) {
|
||||
return com.alibaba.fastjson2.JSON.parseObject(json, type);
|
||||
|
|
|
|||
|
|
@ -16,35 +16,13 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.json.impl;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
public class FastJsonImpl extends AbstractJSONImpl {
|
||||
|
||||
@Override
|
||||
public boolean isSupport() {
|
||||
try {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("fastjson", "test");
|
||||
if (!CollectionUtils.mapEquals(map, toJavaObject(toJson(map), Map.class))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> list = new LinkedList<>();
|
||||
list.add("fastjson");
|
||||
return CollectionUtils.equals(list, toJavaList(toJson(list), String.class));
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toJavaObject(String json, Type type) {
|
||||
return com.alibaba.fastjson.JSON.parseObject(json, type);
|
||||
|
|
|
|||
|
|
@ -16,38 +16,16 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.json.impl;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
public class GsonImpl extends AbstractJSONImpl {
|
||||
// weak reference of com.google.gson.Gson, prevent throw exception when init
|
||||
private volatile Object gsonCache = null;
|
||||
|
||||
@Override
|
||||
public boolean isSupport() {
|
||||
try {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("gson", "test");
|
||||
if (!CollectionUtils.mapEquals(map, toJavaObject(toJson(map), Map.class))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> list = new LinkedList<>();
|
||||
list.add("gson");
|
||||
return CollectionUtils.equals(list, toJavaList(toJson(list), String.class));
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toJavaObject(String json, Type type) {
|
||||
return getGson().fromJson(json, type);
|
||||
|
|
|
|||
|
|
@ -16,30 +16,18 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.json.impl;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
public class JacksonImpl extends AbstractJSONImpl {
|
||||
|
||||
private volatile Object jacksonCache = null;
|
||||
|
||||
@Override
|
||||
public boolean isSupport() {
|
||||
try {
|
||||
Class<?> aClass = ClassUtils.forName("com.fasterxml.jackson.databind.json.JsonMapper");
|
||||
return aClass != null;
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toJavaObject(String json, Type type) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -16,29 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.config;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.config.Environment;
|
||||
|
|
@ -63,6 +40,29 @@ import org.apache.dubbo.rpc.model.ModuleModel;
|
|||
import org.apache.dubbo.rpc.model.ScopeModel;
|
||||
import org.apache.dubbo.rpc.model.ScopeModelUtil;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.MethodDescriptor;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
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_REFLECTIVE_OPERATION_FAILED;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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.dubbo.common.json.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static org.mockito.Answers.CALLS_REAL_METHODS;
|
||||
|
||||
class FastJson2ImplTest {
|
||||
private static MockedStatic<JSON> fastjson2Mock;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
fastjson2Mock = Mockito.mockStatic(JSON.class, CALLS_REAL_METHODS);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void teardown() {
|
||||
fastjson2Mock.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSupported() {
|
||||
Assertions.assertTrue(new FastJson2Impl().isSupport());
|
||||
|
||||
fastjson2Mock.when(() -> JSON.toJSONString(Mockito.any(), (JSONWriter.Feature) Mockito.any())).thenThrow(new RuntimeException());
|
||||
Assertions.assertFalse(new FastJson2Impl().isSupport());
|
||||
fastjson2Mock.reset();
|
||||
|
||||
fastjson2Mock.when(() -> JSON.toJSONString(Mockito.any(), (JSONWriter.Feature) Mockito.any())).thenReturn(null);
|
||||
Assertions.assertFalse(new FastJson2Impl().isSupport());
|
||||
fastjson2Mock.reset();
|
||||
|
||||
fastjson2Mock.when(() -> JSON.parseObject((String) Mockito.any(), (Type) Mockito.any())).thenReturn(null);
|
||||
Assertions.assertFalse(new FastJson2Impl().isSupport());
|
||||
fastjson2Mock.reset();
|
||||
|
||||
fastjson2Mock.when(() -> JSON.parseArray(Mockito.any(), (Class) Mockito.any())).thenReturn(null);
|
||||
Assertions.assertFalse(new FastJson2Impl().isSupport());
|
||||
fastjson2Mock.reset();
|
||||
}
|
||||
}
|
||||
|
|
@ -16,10 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.json.impl;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
|
@ -27,7 +24,9 @@ import org.junit.jupiter.api.Test;
|
|||
import org.mockito.MockedConstruction;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class GsonImplTest {
|
||||
|
||||
|
|
@ -75,7 +74,7 @@ public class GsonImplTest {
|
|||
Assertions.assertFalse(new GsonImpl().isSupport());
|
||||
gsonInit.set(null);
|
||||
|
||||
gsonInit.set(g -> Mockito.when(g.fromJson(Mockito.eq("[\"gson\"]"), (Type) Mockito.any())).thenReturn(null));
|
||||
gsonInit.set(g -> Mockito.when(g.fromJson(Mockito.eq("[\"json\"]"), (Type) Mockito.any())).thenReturn(null));
|
||||
Assertions.assertFalse(new GsonImpl().isSupport());
|
||||
gsonInit.set(null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,31 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.dubbo.common.json.impl.FastJsonImpl;
|
||||
import org.apache.dubbo.common.json.impl.GsonImpl;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedConstruction;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import static org.mockito.Answers.CALLS_REAL_METHODS;
|
||||
|
||||
|
||||
import org.apache.dubbo.common.json.impl.FastJson2Impl;
|
||||
import org.apache.dubbo.common.json.impl.FastJsonImpl;
|
||||
import org.apache.dubbo.common.json.impl.GsonImpl;
|
||||
|
|
@ -48,35 +23,44 @@ import org.apache.dubbo.common.json.impl.JacksonImpl;
|
|||
import org.apache.dubbo.common.utils.json.TestEnum;
|
||||
import org.apache.dubbo.common.utils.json.TestObjectA;
|
||||
import org.apache.dubbo.common.utils.json.TestObjectB;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedConstruction;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
class JsonUtilsTest {
|
||||
private static Gson gson = new Gson();
|
||||
private static MockedStatic<JSON> fastjsonMock;
|
||||
private static AtomicReference<Gson> gsonReference = new AtomicReference<>();
|
||||
private static MockedConstruction<Gson> gsonMock;
|
||||
private static AtomicReference<Consumer<Gson>> gsonInit = new AtomicReference<>();
|
||||
private AtomicBoolean allowFastjson2 = new AtomicBoolean(true);
|
||||
private AtomicBoolean allowFastjson = new AtomicBoolean(true);
|
||||
private AtomicBoolean allowGson = new AtomicBoolean(true);
|
||||
private AtomicBoolean allowJackson = new AtomicBoolean(true);
|
||||
private MockedConstruction<FastJson2Impl> fastjson2Mock;
|
||||
private MockedConstruction<FastJsonImpl> fastjsonMock;
|
||||
private MockedConstruction<GsonImpl> gsonMock;
|
||||
private MockedConstruction<JacksonImpl> jacksonMock;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
fastjsonMock = Mockito.mockStatic(JSON.class, CALLS_REAL_METHODS);
|
||||
gsonMock = Mockito.mockConstruction(Gson.class,
|
||||
(mock, context) -> {
|
||||
gsonReference.set(mock);
|
||||
Mockito.when(mock.toJson((Object) Mockito.any())).thenAnswer(invocation -> gson.toJson((Object) invocation.getArgument(0)));
|
||||
Mockito.when(mock.fromJson(Mockito.anyString(), (Type) Mockito.any())).thenAnswer(invocation -> gson.fromJson((String) invocation.getArgument(0), (Type) invocation.getArgument(1)));
|
||||
Consumer<Gson> gsonConsumer = gsonInit.get();
|
||||
if (gsonConsumer != null) {
|
||||
gsonConsumer.accept(mock);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void teardown() {
|
||||
fastjsonMock.close();
|
||||
gsonMock.close();
|
||||
@AfterEach
|
||||
void teardown() {
|
||||
if (fastjsonMock != null) {
|
||||
fastjsonMock.close();
|
||||
}
|
||||
if (fastjson2Mock != null) {
|
||||
fastjson2Mock.close();
|
||||
}
|
||||
if (gsonMock != null) {
|
||||
gsonMock.close();
|
||||
}
|
||||
if (jacksonMock != null) {
|
||||
jacksonMock.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -224,13 +208,23 @@ class JsonUtilsTest {
|
|||
|
||||
@Test
|
||||
void testGetJson2() {
|
||||
fastjson2Mock = Mockito.mockConstruction(FastJson2Impl.class,
|
||||
(mock, context) -> Mockito.when(mock.isSupport()).thenAnswer(invocation -> allowFastjson2.get()));
|
||||
fastjsonMock = Mockito.mockConstruction(FastJsonImpl.class,
|
||||
(mock, context) -> Mockito.when(mock.isSupport()).thenAnswer(invocation -> allowFastjson.get()));
|
||||
gsonMock = Mockito.mockConstruction(GsonImpl.class,
|
||||
(mock, context) -> Mockito.when(mock.isSupport()).thenAnswer(invocation -> allowGson.get()));
|
||||
jacksonMock = Mockito.mockConstruction(JacksonImpl.class,
|
||||
(mock, context) -> Mockito.when(mock.isSupport()).thenAnswer(invocation -> allowJackson.get()));
|
||||
|
||||
// default use fastjson2
|
||||
JsonUtils.setJson(null);
|
||||
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
|
||||
|
||||
// prefer use fastjson2
|
||||
JsonUtils.setJson(null);
|
||||
Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson());
|
||||
System.setProperty("dubbo.json-framework.prefer", "fastjson2");
|
||||
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
|
||||
|
||||
// prefer use fastjson
|
||||
JsonUtils.setJson(null);
|
||||
|
|
@ -252,43 +246,71 @@ class JsonUtilsTest {
|
|||
|
||||
JsonUtils.setJson(null);
|
||||
// TCCL not found fastjson2
|
||||
allowFastjson2.set(false);
|
||||
Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson());
|
||||
allowFastjson2.set(true);
|
||||
|
||||
JsonUtils.setJson(null);
|
||||
// TCCL not found fastjson
|
||||
fastjsonMock.when(() -> JSON.toJSONString(Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
|
||||
// TCCL not found fastjson2, fastjson
|
||||
allowFastjson2.set(false);
|
||||
allowFastjson.set(false);
|
||||
Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson());
|
||||
fastjsonMock.reset();
|
||||
allowFastjson.set(true);
|
||||
allowFastjson2.set(true);
|
||||
|
||||
JsonUtils.setJson(null);
|
||||
// TCCL not found gson
|
||||
gsonInit.set(mock -> Mockito.reset(mock));
|
||||
// TCCL not found fastjson2, fastjson, gson
|
||||
allowFastjson2.set(false);
|
||||
allowFastjson.set(false);
|
||||
allowGson.set(false);
|
||||
Assertions.assertInstanceOf(JacksonImpl.class, JsonUtils.getJson());
|
||||
allowGson.set(true);
|
||||
allowFastjson.set(true);
|
||||
allowFastjson2.set(true);
|
||||
|
||||
JsonUtils.setJson(null);
|
||||
// TCCL not found fastjson2, prefer use fastjson2
|
||||
allowFastjson2.set(false);
|
||||
System.setProperty("dubbo.json-framework.prefer", "fastjson2");
|
||||
Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson());
|
||||
gsonInit.set(null);
|
||||
System.clearProperty("dubbo.json-framework.prefer");
|
||||
allowFastjson2.set(true);
|
||||
|
||||
JsonUtils.setJson(null);
|
||||
// TCCL not found fastjson, prefer use fastjson
|
||||
fastjsonMock.when(() -> JSON.toJSONString(Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
|
||||
allowFastjson.set(false);
|
||||
System.setProperty("dubbo.json-framework.prefer", "fastjson");
|
||||
Assertions.assertInstanceOf(GsonImpl.class, JsonUtils.getJson());
|
||||
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
|
||||
System.clearProperty("dubbo.json-framework.prefer");
|
||||
fastjsonMock.reset();
|
||||
allowFastjson.set(true);
|
||||
|
||||
JsonUtils.setJson(null);
|
||||
// TCCL not found gson, prefer use gson
|
||||
gsonInit.set(mock -> Mockito.reset(mock));
|
||||
allowGson.set(false);
|
||||
System.setProperty("dubbo.json-framework.prefer", "gson");
|
||||
Assertions.assertInstanceOf(FastJsonImpl.class, JsonUtils.getJson());
|
||||
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
|
||||
System.clearProperty("dubbo.json-framework.prefer");
|
||||
gsonInit.set(null);
|
||||
allowGson.set(true);
|
||||
|
||||
JsonUtils.setJson(null);
|
||||
// TCCL not found jackson, prefer use jackson
|
||||
allowJackson.set(false);
|
||||
System.setProperty("dubbo.json-framework.prefer", "jackson");
|
||||
Assertions.assertInstanceOf(FastJson2Impl.class, JsonUtils.getJson());
|
||||
System.clearProperty("dubbo.json-framework.prefer");
|
||||
allowJackson.set(true);
|
||||
|
||||
JsonUtils.setJson(null);
|
||||
// TCCL not found fastjson, gson
|
||||
fastjsonMock.when(() -> JSON.toJSONString((Object) Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
|
||||
gsonInit.set(mock -> Mockito.reset(mock));
|
||||
allowFastjson2.set(false);
|
||||
allowFastjson.set(false);
|
||||
allowGson.set(false);
|
||||
allowJackson.set(false);
|
||||
Assertions.assertThrows(IllegalStateException.class, JsonUtils::getJson);
|
||||
gsonInit.set(null);
|
||||
fastjsonMock.reset();
|
||||
allowGson.set(true);
|
||||
allowFastjson.set(true);
|
||||
allowFastjson2.set(true);
|
||||
allowJackson.set(true);
|
||||
|
||||
JsonUtils.setJson(null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,18 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.config;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.URLBuilder;
|
||||
import org.apache.dubbo.common.Version;
|
||||
|
|
@ -62,6 +50,18 @@ import org.apache.dubbo.rpc.model.ScopeModel;
|
|||
import org.apache.dubbo.rpc.model.ServiceDescriptor;
|
||||
import org.apache.dubbo.rpc.service.GenericService;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
|
||||
|
|
|
|||
|
|
@ -639,11 +639,6 @@ class ServiceConfigTest {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initInterfaceAppMapping(URL subscribedURL) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAndListen(URL registryURL, URL subscribedURL, MappingListener listener) {
|
||||
return null;
|
||||
|
|
@ -660,12 +655,7 @@ class ServiceConfigTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCachedMapping(String mappingKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getCachedMapping(URL consumerURL) {
|
||||
public Set<String> getMapping(URL consumerURL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -674,11 +664,6 @@ class ServiceConfigTest {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Set<String>> getCachedMapping() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> removeCachedMapping(String serviceKey) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -16,11 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.RegistryConstants;
|
||||
import org.apache.dubbo.common.extension.SPI;
|
||||
|
|
@ -30,6 +25,10 @@ import org.apache.dubbo.rpc.model.ScopeModel;
|
|||
import org.apache.dubbo.rpc.model.ScopeModelUtil;
|
||||
import org.apache.dubbo.rpc.service.Destroyable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
|
||||
import static org.apache.dubbo.common.extension.ExtensionScope.APPLICATION;
|
||||
|
|
|
|||
|
|
@ -16,18 +16,19 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDED_BY;
|
||||
import static org.apache.dubbo.common.constants.RegistryConstants.SUBSCRIBED_SERVICE_NAMES_KEY;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.dubbo.common.profiler.ProfilerEntry;
|
|||
import org.apache.dubbo.common.profiler.ProfilerSwitch;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.rpc.BaseFilter;
|
||||
import org.apache.dubbo.rpc.Constants;
|
||||
import org.apache.dubbo.rpc.Filter;
|
||||
import org.apache.dubbo.rpc.Invocation;
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
|
|
@ -31,14 +32,14 @@ import org.apache.dubbo.rpc.Result;
|
|||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
import org.apache.dubbo.rpc.support.RpcUtils;
|
||||
import org.apache.dubbo.rpc.Constants;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SEPARATOR;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROXY_TIMEOUT_RESPONSE;
|
||||
|
||||
@Activate(group = PROVIDER, order = Integer.MIN_VALUE)
|
||||
|
|
|
|||
|
|
@ -17,13 +17,6 @@
|
|||
|
||||
package org.apache.dubbo.rpc.protocol.tri;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
|
|
@ -57,6 +50,13 @@ import org.apache.dubbo.rpc.support.RpcUtils;
|
|||
|
||||
import io.netty.util.AsciiString;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
|
|
|
|||
Loading…
Reference in New Issue