Skip to content

Commit

Permalink
Merge branch '3.3' into fix/aotUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHZM authored Feb 29, 2024
2 parents 85356dc + 0fa88a1 commit 31d7f48
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ private static final class ConsistentHashSelector<T> {
}

public Invoker<T> select(Invocation invocation) {
byte[] digest = Bytes.getMD5(RpcUtils.getMethodName(invocation));
return selectForKey(hash(digest, 0));
}
String key = toKey(RpcUtils.getArguments(invocation));

private String toKey(Object[] args, boolean isGeneric) {
return isGeneric ? toKey((Object[]) args[1]) : toKey(args);
byte[] digest = Bytes.getMD5(key);
return selectForKey(hash(digest, 0));
}

private String toKey(Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.rpc.cluster.loadbalance;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.cluster.LoadBalance;
import org.apache.dubbo.rpc.cluster.RouterChain;
Expand All @@ -25,11 +26,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;

@SuppressWarnings("rawtypes")
class ConsistentHashLoadBalanceTest extends LoadBalanceBaseTest {

Expand All @@ -45,6 +50,34 @@ void testConsistentHashLoadBalanceInGenericCall() {
Assertions.assertEquals(hitted, genericHitted, "hitted should equals to genericHitted");
}

@Test
void testArgumentMatchAll() {
Map<Invoker, AtomicLong> counter = new ConcurrentHashMap<Invoker, AtomicLong>();
LoadBalance lb = getLoadBalance(ConsistentHashLoadBalance.NAME);
for (Invoker invoker : invokers) {
counter.put(invoker, new AtomicLong(0));
}
URL url = invokers.get(0).getUrl();

for (int i = 0; i < 1000; i++) {
Invocation invocation = mock(Invocation.class);
String methodName = "method1";
given(invocation.getMethodName()).willReturn("$invoke");
String[] paraTypes = new String[] {String.class.getName(), String.class.getName(), String.class.getName()};
Object[] argsObject = new Object[] {"arg" + i, "arg2", "arg3"};
Object[] args = new Object[] {methodName, paraTypes, argsObject};
given(invocation.getArguments()).willReturn(args);

for (int j = 0; j < 5; j++) {
Invoker sinvoker = lb.select(invokers, url, invocation);
counter.get(sinvoker).incrementAndGet();
}
}
for (Invoker invoker : invokers) {
Assertions.assertTrue(counter.get(invoker).get() > 0);
}
}

private Invoker findHitted(Map<Invoker, AtomicLong> invokerCounter) {
Invoker invoker = null;

Expand Down
2 changes: 1 addition & 1 deletion dubbo-config/dubbo-config-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.4</version>
<version>1.19.5</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.28</version>
<version>0.10.0</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.28</version>
<version>0.10.0</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>
Expand Down
6 changes: 3 additions & 3 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<httpclient_version>4.5.14</httpclient_version>
<httpcore_version>4.4.16</httpcore_version>
<fastjson_version>1.2.83</fastjson_version>
<fastjson2_version>2.0.45</fastjson2_version>
<fastjson2_version>2.0.46</fastjson2_version>
<zookeeper_version>3.7.2</zookeeper_version>
<curator_version>5.1.0</curator_version>
<curator_test_version>2.12.0</curator_test_version>
Expand Down Expand Up @@ -137,7 +137,7 @@
<nacos_version>2.2.4</nacos_version>
<sentinel.version>1.8.6</sentinel.version>
<seata.version>1.6.1</seata.version>
<grpc.version>1.61.0</grpc.version>
<grpc.version>1.61.1</grpc.version>
<grpc_contrib_verdion>0.8.1</grpc_contrib_verdion>
<jprotoc_version>1.2.2</jprotoc_version>
<mustache_version>0.9.10</mustache_version>
Expand Down Expand Up @@ -166,7 +166,7 @@

<jaxb_version>2.2.7</jaxb_version>
<activation_version>1.2.0</activation_version>
<test_container_version>1.19.4</test_container_version>
<test_container_version>1.19.5</test_container_version>
<hessian_lite_version>3.2.13</hessian_lite_version>
<swagger_version>1.6.13</swagger_version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.ParameterMeta;
import org.apache.dubbo.rpc.protocol.tri.rest.util.DefaultRestToolKit;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;

final class JaxrsRestToolKit extends DefaultRestToolKit {

private final BeanArgumentBinder binder;
Expand All @@ -32,6 +35,17 @@ public JaxrsRestToolKit(FrameworkModel frameworkModel) {
binder = new BeanArgumentBinder(frameworkModel);
}

@Override
public Object convert(Object value, ParameterMeta parameter) {
if (MultivaluedMap.class.isAssignableFrom(parameter.getType())) {
if (value instanceof MultivaluedMap) {
return value;
}
return typeConverter.convert(value, MultivaluedHashMap.class);
}
return super.convert(value, parameter);
}

@Override
public int getDialect() {
return RestConstants.DIALECT_JAXRS;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.representer.Representer;

@SuppressWarnings({"unchecked", "rawtypes"})
public class YamlCodec implements HttpMessageCodec {

@Override
public Object decode(InputStream is, Class<?> targetType, Charset charset) throws DecodeException {
try (InputStreamReader reader = new InputStreamReader(is, charset)) {
return createYaml().loadAs(reader, targetType);
return createYaml().loadAs(reader, (Class) targetType);
} catch (Throwable t) {
throw new DecodeException("Error decoding yaml", t);
}
Expand All @@ -57,7 +58,7 @@ public Object[] decode(InputStream is, Class<?>[] targetTypes, Charset charset)
for (int i = 0; i < len; i++) {
if (iterator.hasNext()) {
Object result = iterator.next();
Class<?> targetType = targetTypes[i];
Class targetType = targetTypes[i];
if (targetType.isInstance(result)) {
results[i] = result;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.apache.dubbo.remoting.transport.netty4.api;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.remoting.api.ProtocolDetector;
import org.apache.dubbo.remoting.api.WireProtocol;
import org.apache.dubbo.remoting.api.pu.ChannelOperator;
import org.apache.dubbo.remoting.api.ssl.ContextOperator;

@Activate
public class EmptyWireProtocol implements WireProtocol {
@Override
public ProtocolDetector detector() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,11 @@ protected Object customConvert(Object source, Type targetType) {
}

protected Collection customCreateCollection(Class targetClass, int size) {
return null;
return converterUtil == null ? null : (Collection) converterUtil.convertIfPossible(size, targetClass);
}

private Map customCreateMap(Class targetClass, int size) {
return null;
protected Map customCreateMap(Class targetClass, int size) {
return converterUtil == null ? null : (Map) converterUtil.convertIfPossible(size, targetClass);
}

private Collection createCollection(Class targetClass, int size) {
Expand Down Expand Up @@ -792,10 +792,6 @@ private Collection createCollection(Class targetClass, int size) {
if (collection != null) {
return collection;
}
collection = (Collection) converterUtil.convertIfPossible(size, targetClass);
if (collection != null) {
return collection;
}
if (targetClass.isAssignableFrom(ArrayList.class)) {
return new ArrayList<>(size);
}
Expand Down Expand Up @@ -934,10 +930,6 @@ private Map createMap(Class targetClass, int size) {
if (map != null) {
return map;
}
map = (Map) converterUtil.convertIfPossible(size, targetClass);
if (map != null) {
return map;
}
if (targetClass.isAssignableFrom(LinkedHashMap.class)) {
return CollectionUtils.newLinkedHashMap(size);
}
Expand Down

0 comments on commit 31d7f48

Please sign in to comment.