You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by sh...@apache.org on 2022/12/26 11:26:34 UTC
[servicecomb-java-chassis] branch master updated: Bump vertx.version from 4.3.4 to 4.3.7 (#3545)
This is an automated email from the ASF dual-hosted git repository.
shoothzj 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 56549ec60 Bump vertx.version from 4.3.4 to 4.3.7 (#3545)
56549ec60 is described below
commit 56549ec6049de06fd2ed09857cb4e1e4abcfc8f3
Author: liubao68 <bi...@qq.com>
AuthorDate: Mon Dec 26 19:26:28 2022 +0800
Bump vertx.version from 4.3.4 to 4.3.7 (#3545)
---
dependencies/default/pom.xml | 2 +-
.../vertx/stream/BufferOutputStream.java | 27 ++++------------------
.../servicecomb/foundation/vertx/TestStream.java | 14 +++++++----
.../metrics/core/TestVertxMetersInitializer.java | 6 ++---
.../transport/rest/vertx/RestServerVerticle.java | 4 ++--
5 files changed, 21 insertions(+), 32 deletions(-)
diff --git a/dependencies/default/pom.xml b/dependencies/default/pom.xml
index 16c36dd10..dd12c5c64 100644
--- a/dependencies/default/pom.xml
+++ b/dependencies/default/pom.xml
@@ -98,7 +98,7 @@
<spring-boot.version>2.7.7</spring-boot.version>
<swagger.version>1.6.9</swagger.version>
<swagger2markup.version>1.3.3</swagger2markup.version>
- <vertx.version>4.3.4</vertx.version>
+ <vertx.version>4.3.7</vertx.version>
<zipkin.version>2.23.19</zipkin.version>
<zipkin-reporter.version>2.16.3</zipkin-reporter.version>
<!-- Base dir of main -->
diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/BufferOutputStream.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/BufferOutputStream.java
index da0433c01..f063d5d06 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/BufferOutputStream.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/BufferOutputStream.java
@@ -22,37 +22,22 @@ import java.nio.charset.StandardCharsets;
import io.netty.buffer.ByteBuf;
import io.vertx.core.buffer.Buffer;
+import io.vertx.core.buffer.impl.VertxByteBufAllocator;
/**
- * BufferOutputStream
- *
+ * BufferOutputStream.
*
+ * Notice: will not release the underlining ByteBuffer, the user is responsible to release it.
*/
public class BufferOutputStream extends OutputStream {
private static final int DIRECT_BUFFER_SIZE = 1024;
protected ByteBuf byteBuf;
- private boolean needReleaseBuffer;
-
public BufferOutputStream() {
- // TODO:默认大小加配置项
- // TODO:如何与pool配合起来,vertx中默认都是unpool的,我们的阻塞模式下,申请与释放也不在一个线程,估计更用不上?
- // 后续通道没问题了,再来验证这个问题
- // this(PooledByteBufAllocator.DEFAULT.directBuffer());
-
- // this(PooledByteBufAllocator.DEFAULT.directBuffer(DIRECT_BUFFER_SIZE));
-
- // this(UnpooledByteBufAllocator.DEFAULT.directBuffer(DIRECT_BUFFER_SIZE));
- // needReleaseBuffer = false;
-
- // this(UnpooledByteBufAllocator.DEFAULT.heapBuffer(DIRECT_BUFFER_SIZE));
-
- this(Buffer.buffer(DIRECT_BUFFER_SIZE).getByteBuf());
- needReleaseBuffer = false;
+ this(VertxByteBufAllocator.DEFAULT.heapBuffer(DIRECT_BUFFER_SIZE, Integer.MAX_VALUE));
}
-
public BufferOutputStream(ByteBuf buffer) {
this.byteBuf = buffer;
}
@@ -116,9 +101,7 @@ public class BufferOutputStream extends OutputStream {
@Override
public void close() {
- if (needReleaseBuffer && byteBuf != null) {
- byteBuf.release();
- }
+ // Do no release byteBuf, the target BufferedInputStream will release it.
}
public int writerIndex() {
diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestStream.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestStream.java
index bb4081ead..2c9fdc895 100644
--- a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestStream.java
+++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestStream.java
@@ -19,19 +19,19 @@ package org.apache.servicecomb.foundation.vertx;
import org.apache.servicecomb.foundation.vertx.stream.BufferInputStream;
import org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream;
-
-import io.netty.buffer.ByteBuf;
-import io.vertx.core.buffer.Buffer;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import io.netty.buffer.ByteBuf;
+import io.vertx.core.buffer.impl.VertxByteBufAllocator;
+
public class TestStream {
private static final int DIRECT_BUFFER_SIZE = 1024;
@Test
public void testBufferInputStream() {
- ByteBuf obuf = Buffer.buffer(DIRECT_BUFFER_SIZE).getByteBuf();
+ ByteBuf obuf = VertxByteBufAllocator.DEFAULT.heapBuffer(DIRECT_BUFFER_SIZE, Integer.MAX_VALUE);
obuf.writeBytes(("testss").getBytes());
@SuppressWarnings("resource")
BufferInputStream oBufferInputStream = new BufferInputStream(obuf);
@@ -51,5 +51,11 @@ public class TestStream {
oBufferOutputStream.write(1);
oBufferOutputStream.write(true);
Assertions.assertTrue((1 < oBufferOutputStream.length()));
+
+ @SuppressWarnings("resource")
+ BufferInputStream oBufferInputStream = new BufferInputStream(oBufferOutputStream.getByteBuf());
+ Assertions.assertEquals("test", oBufferInputStream.readString());
+ Assertions.assertEquals(1, oBufferInputStream.readByte());
+ Assertions.assertEquals(true, oBufferInputStream.readBoolean());
}
}
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestVertxMetersInitializer.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestVertxMetersInitializer.java
index 4dca3a9f4..6d814a350 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestVertxMetersInitializer.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestVertxMetersInitializer.java
@@ -68,7 +68,7 @@ public class TestVertxMetersInitializer {
@Override
public void start(Promise<Void> startPromise) {
Router mainRouter = Router.router(vertx);
- mainRouter.route("/").handler(context -> context.response().end(context.body().buffer()));
+ mainRouter.route("/").handler(context -> context.response().end(body));
HttpServer server = vertx.createHttpServer();
server.requestHandler(mainRouter);
@@ -171,13 +171,13 @@ public class TestVertxMetersInitializer {
expect = expect + " client.endpoints:\n"
+ " connectCount disconnectCount queue connections requests latency send(Bps) receive(Bps) remote\n";
expect +=
- " 1 0 0 1 1 %-7s 4 21 http://127.0.0.1:%-"
+ " 1 0 0 1 1 %-7s 4 4 http://127.0.0.1:%-"
+ portSize + "s\n";
}
expect += ""
+ " server.endpoints:\n"
+ " connectCount disconnectCount rejectByLimit connections requests latency send(Bps) receive(Bps) listen\n"
- + " 1 0 0 1 1 %-7s 21 4 0.0.0.0:0\n\n";
+ + " 1 0 0 1 1 %-7s 4 4 0.0.0.0:0\n\n";
if (printDetail) {
expect = String
diff --git a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
index 1c2bf6e36..304aa491c 100644
--- a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
+++ b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
@@ -24,7 +24,6 @@ import java.util.Set;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
-import com.google.common.annotations.VisibleForTesting;
import org.apache.servicecomb.common.accessLog.AccessLogConfig;
import org.apache.servicecomb.common.accessLog.core.element.impl.LocalHostAccessItem;
import org.apache.servicecomb.common.rest.codec.RestObjectMapperFactory;
@@ -46,6 +45,7 @@ import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.VisibleForTesting;
import com.netflix.config.DynamicPropertyFactory;
import io.vertx.core.AbstractVerticle;
@@ -212,7 +212,7 @@ public class RestServerVerticle extends AbstractVerticle {
}
private CorsHandler getCorsHandler(String corsAllowedOrigin) {
- return CorsHandler.create(corsAllowedOrigin);
+ return CorsHandler.create().addOrigin(corsAllowedOrigin);
}
private void initDispatcher(Router mainRouter) {