Skip to content

Commit

Permalink
Merge branch '3.3' into feat/FileTestSupportAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
Stellar1999 authored Mar 25, 2024
2 parents 58906da + b338e20 commit 19e8029
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dubbo-config/dubbo-config-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.21.1</version>
<version>1.9.21.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<curator5_version>5.1.0</curator5_version>
<zookeeper_version>3.8.3</zookeeper_version>
<zookeeper_version>3.8.4</zookeeper_version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<curator5_version>5.1.0</curator5_version>
<zookeeper_version>3.8.3</zookeeper_version>
<zookeeper_version>3.8.4</zookeeper_version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot.version>2.7.18</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.18</spring-boot-maven-plugin.version>
<micrometer-core.version>1.12.3</micrometer-core.version>
<micrometer-core.version>1.12.4</micrometer-core.version>
</properties>

<dependencyManagement>
Expand Down
8 changes: 4 additions & 4 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@
<snakeyaml_version>2.2</snakeyaml_version>
<commons_lang3_version>3.14.0</commons_lang3_version>
<envoy_api_version>0.1.35</envoy_api_version>
<micrometer.version>1.12.3</micrometer.version>
<micrometer.version>1.12.4</micrometer.version>
<opentelemetry.version>1.26.0</opentelemetry.version>
<zipkin-reporter.version>2.16.4</zipkin-reporter.version>
<micrometer-tracing.version>1.2.3</micrometer-tracing.version>
<micrometer-tracing.version>1.2.4</micrometer-tracing.version>
<t_digest.version>3.3</t_digest.version>
<prometheus_client.version>0.16.0</prometheus_client.version>
<reactive.version>1.0.4</reactive.version>
<reactor.version>3.6.2</reactor.version>
<reactor.version>3.6.4</reactor.version>
<rxjava.version>2.2.21</rxjava.version>
<okhttp_version>3.14.9</okhttp_version>

Expand Down Expand Up @@ -175,7 +175,7 @@
<sofa_registry_version>5.4.3</sofa_registry_version>
<metrics_version>2.0.6</metrics_version>
<gson_version>2.10.1</gson_version>
<jackson_version>2.16.2</jackson_version>
<jackson_version>2.17.0</jackson_version>
<mortbay_jetty_version>6.1.26</mortbay_jetty_version>
<portlet_version>2.0</portlet_version>
<maven_flatten_version>1.6.0</maven_flatten_version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<maven_flatten_version>1.6.0</maven_flatten_version>
<slf4j_version>1.7.36</slf4j_version>
<curator5_version>5.1.0</curator5_version>
<zookeeper_version>3.8.3</zookeeper_version>
<zookeeper_version>3.8.4</zookeeper_version>
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
<spotless.action>check</spotless.action>
<dubbo-shared-resources.version>1.0.0</dubbo-shared-resources.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.qos.server.handler;

import org.apache.dubbo.qos.common.QosConstants;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

public class CtrlCHandler extends SimpleChannelInboundHandler<ByteBuf> {
/**
* When type 'Ctrl+C', telnet client will send the following sequence:
* 'FF F4 FF FD 06', it can be divided into two parts:
* <p>
* 1. 'FF F4' is telnet interrupt process command.
* <p>
* 2. 'FF FD 06' is to suppress the output of the process that is to be
* interrupted by the interrupt process command.
* <p>
* We need to response with 'FF FC 06' to ignore it and tell the client continue
* display output.
*/
private byte[] CTRLC_BYTES_SEQUENCE = new byte[] {(byte) 0xff, (byte) 0xf4, (byte) 0xff, (byte) 0xfd, (byte) 0x06};

private byte[] RESPONSE_SEQUENCE = new byte[] {(byte) 0xff, (byte) 0xfc, 0x06};

@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
// find ctrl+c
final int readerIndex = buffer.readerIndex();
for (int i = readerIndex; i < buffer.writerIndex(); i++) {
if (buffer.readableBytes() - i < CTRLC_BYTES_SEQUENCE.length) {
break;
}
boolean match = true;
for (int j = 0; j < CTRLC_BYTES_SEQUENCE.length; j++) {
if (CTRLC_BYTES_SEQUENCE[j] != buffer.getByte(i + j)) {
match = false;
break;
}
}

if (match) {
buffer.readerIndex(readerIndex + buffer.readableBytes());
ctx.writeAndFlush(Unpooled.wrappedBuffer(RESPONSE_SEQUENCE));
ctx.writeAndFlush(Unpooled.wrappedBuffer(
(QosConstants.BR_STR + QosProcessHandler.PROMPT).getBytes(CharsetUtil.UTF_8)));

return;
}
}
ctx.fireChannelRead(buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
p.addLast(new HttpProcessHandler(frameworkModel, qosConfiguration));
p.remove(this);
} else {
p.addLast(new CtrlCHandler());
p.addLast(new LineBasedFrameDecoder(2048));
p.addLast(new StringDecoder(CharsetUtil.UTF_8));
p.addLast(new StringEncoder(CharsetUtil.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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.qos.server.handler;

import org.apache.dubbo.qos.common.QosConstants;

import java.nio.charset.StandardCharsets;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.CharsetUtil;
import org.junit.jupiter.api.Test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

public class CtrlCHandlerTest {
private byte[] CTRLC_BYTES_SEQUENCE = new byte[] {(byte) 0xff, (byte) 0xf4, (byte) 0xff, (byte) 0xfd, (byte) 0x06};

private byte[] RESPONSE_SEQUENCE = new byte[] {(byte) 0xff, (byte) 0xfc, 0x06};

@Test
void testMatchedExactly() throws Exception {
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
CtrlCHandler ctrlCHandler = new CtrlCHandler();
ctrlCHandler.channelRead(context, Unpooled.wrappedBuffer(CTRLC_BYTES_SEQUENCE));
verify(context).writeAndFlush(Unpooled.wrappedBuffer(RESPONSE_SEQUENCE));
verify(context)
.writeAndFlush(Unpooled.wrappedBuffer(
(QosConstants.BR_STR + QosProcessHandler.PROMPT).getBytes(CharsetUtil.UTF_8)));
}

@Test
void testMatchedNotExactly() throws Exception {
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
CtrlCHandler ctrlCHandler = new CtrlCHandler();
// before 'ctrl c', user typed other command like 'help'
String arbitraryCommand = "help";
byte[] commandBytes = arbitraryCommand.getBytes(StandardCharsets.UTF_8);
ctrlCHandler.channelRead(context, Unpooled.wrappedBuffer(commandBytes, CTRLC_BYTES_SEQUENCE));
verify(context).writeAndFlush(Unpooled.wrappedBuffer(RESPONSE_SEQUENCE));
verify(context)
.writeAndFlush(Unpooled.wrappedBuffer(
(QosConstants.BR_STR + QosProcessHandler.PROMPT).getBytes(CharsetUtil.UTF_8)));
}

@Test
void testNotMatched() throws Exception {
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
CtrlCHandler ctrlCHandler = new CtrlCHandler();
String arbitraryCommand = "help" + QosConstants.BR_STR;
byte[] commandBytes = arbitraryCommand.getBytes(StandardCharsets.UTF_8);
ctrlCHandler.channelRead(context, Unpooled.wrappedBuffer(commandBytes));
verify(context, never()).writeAndFlush(Unpooled.wrappedBuffer(RESPONSE_SEQUENCE));
verify(context, never())
.writeAndFlush(Unpooled.wrappedBuffer(
(QosConstants.BR_STR + QosProcessHandler.PROMPT).getBytes(CharsetUtil.UTF_8)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,12 @@ public Result invoke(Invocation invocation) throws RpcException {
invocation instanceof RpcInvocation ? ((RpcInvocation) invocation).getInvokeMode() : null);
copiedInvocation.setObjectAttachment(CommonConstants.GROUP_KEY, protocolServiceKey.getGroup());
copiedInvocation.setObjectAttachment(CommonConstants.VERSION_KEY, protocolServiceKey.getVersion());
// When there are multiple MethodDescriptors with the same method name, the return type will be wrong
// same with org.apache.dubbo.rpc.stub.StubInvocationUtil.call
// fix https://github.com/apache/dubbo/issues/13931
if (invocation instanceof RpcInvocation) {
copiedInvocation.setReturnType(((RpcInvocation) invocation).getReturnType());
}
return originInvoker.invoke(copiedInvocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.dubbo.remoting.transport.netty4.ssl.SslContexts;
import org.apache.dubbo.remoting.utils.UrlUtils;

import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -337,7 +338,9 @@ public void destroy() {
@Override
public String toString() {
return super.toString() + " (Ref=" + this.getCounter() + ",local="
+ (getChannel() == null ? null : getChannel().getLocalAddress()) + ",remote=" + getRemoteAddress();
+ Optional.ofNullable(getChannel())
.map(Channel::getLocalAddress)
.orElse(null) + ",remote=" + getRemoteAddress();
}

class ConnectionListener implements ChannelFutureListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public String readUTF() throws IOException {

@Override
public byte[] readBytes() throws IOException {
int length = is.read();
int length = readLength();
byte[] bytes = new byte[length];
int read = is.read(bytes, 0, length);
if (read != length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public void writeUTF(String v) throws IOException {

@Override
public void writeBytes(byte[] b) throws IOException {
os.write(b.length);
writeLength(b.length);
os.write(b);
}

@Override
public void writeBytes(byte[] b, int off, int len) throws IOException {
os.write(len);
writeLength(len);
os.write(b, off, len);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<properties>
<curator5_version>5.1.0</curator5_version>
<zookeeper_version>3.8.3</zookeeper_version>
<zookeeper_version>3.8.4</zookeeper_version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
</modules>

<properties>
<micrometer.version>1.12.3</micrometer.version>
<micrometer-tracing.version>1.2.3</micrometer-tracing.version>
<micrometer.version>1.12.4</micrometer.version>
<micrometer-tracing.version>1.2.4</micrometer-tracing.version>
<opentelemetry.version>1.34.1</opentelemetry.version>
<zipkin-reporter.version>2.17.2</zipkin-reporter.version>
<prometheus-client.version>0.16.0</prometheus-client.version>
Expand Down

0 comments on commit 19e8029

Please sign in to comment.