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 45be436d442341d9b9e121dc41ecb8c67f69d762
Author: liubao <[email protected]>
AuthorDate: Mon Jun 24 20:15:04 2024 +0800

    [SCB-2885]refactoring to using vert.x Buffer instead of Netty ByteBuffer
---
 .../rest/codec/produce/ProduceProcessor.java       |  2 +-
 .../rest/filter/inner/RestServerCodecFilter.java   |  6 +--
 .../common/rest/codec/param/TestBodyProcessor.java | 12 +++--
 .../servicecomb/foundation/vertx/VertxUtils.java   |  5 ++-
 .../vertx/client/tcp/TcpClientConnection.java      |  2 +-
 .../vertx/http/HttpServletResponseEx.java          | 16 ++++++-
 .../vertx/http/StandardHttpServletRequestEx.java   |  6 +--
 .../VertxServerRequestToHttpServletRequest.java    |  2 +-
 .../foundation/vertx/stream/BufferInputStream.java | 51 ++++++++++++++--------
 .../vertx/stream/BufferOutputStream.java           | 36 +++++++--------
 .../foundation/vertx/tcp/TcpConnection.java        | 21 ++-------
 .../servicecomb/foundation/vertx/TestStream.java   | 28 +++++++-----
 .../foundation/vertx/TestVertxUtils.java           |  5 ++-
 .../vertx/client/tcp/TestTcpClientConnection.java  | 10 ++---
 .../http/TestStandardHttpServletRequestEx.java     |  2 +-
 .../vertx/stream/TestBufferInputStream.java        |  9 ++--
 .../highway/HighwayProducerInvocationFlow.java     |  2 +-
 17 files changed, 112 insertions(+), 103 deletions(-)

diff --git 
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceProcessor.java
 
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceProcessor.java
index bcf7cb74b..574c1e1b6 100644
--- 
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceProcessor.java
+++ 
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceProcessor.java
@@ -72,7 +72,7 @@ public interface ProduceProcessor {
       return null;
     }
 
-    try (BufferInputStream input = new BufferInputStream(buffer.getByteBuf())) 
{
+    try (BufferInputStream input = new BufferInputStream(buffer)) {
       return doDecodeResponse(input, type);
     }
   }
diff --git 
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
 
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
index 18a5d9d94..348ee7f19 100644
--- 
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
+++ 
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java
@@ -50,8 +50,8 @@ import 
org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import io.netty.buffer.Unpooled;
 import io.vertx.core.MultiMap;
+import io.vertx.core.buffer.Buffer;
 import jakarta.servlet.http.Part;
 import jakarta.ws.rs.core.HttpHeaders;
 
@@ -132,7 +132,7 @@ public class RestServerCodecFilter extends AbstractFilter 
implements ProviderFil
     }
 
     responseEx.setContentType(produceProcessor.getName());
-    try (BufferOutputStream output = new 
BufferOutputStream(Unpooled.compositeBuffer())) {
+    try (BufferOutputStream output = new BufferOutputStream(Buffer.buffer())) {
       if (failed) {
         produceProcessor.encodeResponse(output, ((InvocationException) 
response.getResult()).getErrorData());
       } else {
@@ -144,7 +144,7 @@ public class RestServerCodecFilter extends AbstractFilter 
implements ProviderFil
       return CompletableFuture.completedFuture(response);
     } catch (Throwable e) {
       LOGGER.error("internal service error must be fixed.", e);
-      try (BufferOutputStream output = new 
BufferOutputStream(Unpooled.compositeBuffer())) {
+      try (BufferOutputStream output = new 
BufferOutputStream(Buffer.buffer())) {
         responseEx.setStatus(500);
         produceProcessor.encodeResponse(output, new CommonExceptionData("500", 
"Internal Server Error"));
         responseEx.setBodyBuffer(output.getBuffer());
diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessor.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessor.java
index 3debd1645..784150324 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessor.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/codec/param/TestBodyProcessor.java
@@ -41,8 +41,6 @@ import org.springframework.core.env.Environment;
 
 import com.fasterxml.jackson.databind.type.TypeFactory;
 
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 import io.swagger.v3.oas.models.OpenAPI;
 import io.swagger.v3.oas.models.media.Content;
 import io.swagger.v3.oas.models.parameters.RequestBody;
@@ -66,7 +64,7 @@ public class TestBodyProcessor {
 
   ParamValueProcessor processor;
 
-  final ByteBuf inputBodyByteBuf = Unpooled.buffer();
+  final Buffer inputBodyByteBuf = Buffer.buffer();
 
   final BufferInputStream inputStream = new 
BufferInputStream(inputBodyByteBuf);
 
@@ -142,7 +140,7 @@ public class TestBodyProcessor {
   @Test
   public void testGetValueTextPlain() throws Exception {
     setupGetValue(String.class);
-    inputBodyByteBuf.writeCharSequence("abc", StandardCharsets.UTF_8);
+    inputBodyByteBuf.appendString("abc", StandardCharsets.UTF_8.toString());
 
     Mockito.when(request.getContentType()).thenReturn(MediaType.TEXT_PLAIN);
 
@@ -152,7 +150,7 @@ public class TestBodyProcessor {
   @Test
   public void testGetValueContextTypeJson() throws Exception {
     setupGetValue(Integer.class);
-    inputBodyByteBuf.writeCharSequence("\"1\"", StandardCharsets.UTF_8);
+    inputBodyByteBuf.appendString("\"1\"", StandardCharsets.UTF_8.toString());
 
     
Mockito.when(request.getContentType()).thenReturn(MediaType.APPLICATION_JSON);
 
@@ -162,7 +160,7 @@ public class TestBodyProcessor {
   @Test
   public void testGetValueDefaultJson() throws Exception {
     setupGetValue(Integer.class);
-    inputBodyByteBuf.writeCharSequence("\"1\"", StandardCharsets.UTF_8);
+    inputBodyByteBuf.appendString("\"1\"", StandardCharsets.UTF_8.toString());
 
     Assertions.assertEquals(1, processor.getValue(request));
   }
@@ -220,7 +218,7 @@ public class TestBodyProcessor {
   public void testGetValueRawJson() throws Exception {
     createRawJsonProcessor();
     initInputStream();
-    inputBodyByteBuf.writeCharSequence("\"1\"", StandardCharsets.UTF_8);
+    inputBodyByteBuf.appendString("\"1\"", StandardCharsets.UTF_8.toString());
 
     Assertions.assertEquals("\"1\"", processor.getValue(request));
   }
diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
index 331c502ff..43094de2a 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
@@ -153,8 +153,9 @@ public final class VertxUtils {
   }
 
   public static byte[] getBytesFast(Buffer buffer) {
-    ByteBuf byteBuf = buffer.getByteBuf();
-    return getBytesFast(byteBuf);
+    byte[] arr = new byte[buffer.length()];
+    buffer.getBytes(arr, 0);
+    return arr;
   }
 
   public static byte[] getBytesFast(ByteBuf byteBuf) {
diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/client/tcp/TcpClientConnection.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/client/tcp/TcpClientConnection.java
index 5d363e874..d8800800f 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/client/tcp/TcpClientConnection.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/client/tcp/TcpClientConnection.java
@@ -144,7 +144,7 @@ public class TcpClientConnection extends TcpConnection {
     if (Status.WORKING.equals(status)) {
       // encode in sender thread
       try (TcpOutputStream os = tcpClientPackage.createStream()) {
-        write(os.getByteBuf());
+        write(os.getBuffer());
         tcpClientPackage.finishWriteToBuffer();
       }
       return true;
diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/HttpServletResponseEx.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/HttpServletResponseEx.java
index 265ee658e..e6ec15dc0 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/HttpServletResponseEx.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/HttpServletResponseEx.java
@@ -17,14 +17,16 @@
 
 package org.apache.servicecomb.foundation.vertx.http;
 
+import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.concurrent.CompletableFuture;
 
+import io.vertx.core.http.HttpHeaders;
+import jakarta.servlet.ServletOutputStream;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.servlet.http.Part;
 import jakarta.ws.rs.core.Response.StatusType;
 
-import io.vertx.core.http.HttpHeaders;
-
 public interface HttpServletResponseEx extends HttpServletResponse, 
BodyBufferSupport {
   StatusType getStatusType();
 
@@ -37,4 +39,14 @@ public interface HttpServletResponseEx extends 
HttpServletResponse, BodyBufferSu
   default void setChunked(boolean chunked) {
     setHeader(HttpHeaders.TRANSFER_ENCODING.toString(), 
HttpHeaders.CHUNKED.toString());
   }
+
+  @Override
+  default ServletOutputStream getOutputStream() throws IOException {
+    throw new IOException("Not allowed");
+  }
+
+  @Override
+  default PrintWriter getWriter() throws IOException {
+    throw new IOException("Not allowed");
+  }
 }
diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/StandardHttpServletRequestEx.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/StandardHttpServletRequestEx.java
index 21fd45309..82b46b475 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/StandardHttpServletRequestEx.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/StandardHttpServletRequestEx.java
@@ -38,8 +38,6 @@ import 
org.apache.servicecomb.foundation.vertx.stream.BufferInputStream;
 
 import com.google.common.annotations.VisibleForTesting;
 
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 import io.vertx.core.buffer.Buffer;
 import jakarta.servlet.ServletInputStream;
 import jakarta.servlet.http.HttpServletRequest;
@@ -77,9 +75,9 @@ public class StandardHttpServletRequestEx extends 
HttpServletRequestWrapper impl
     if (this.inputStream == null) {
       if (cacheRequest) {
         byte[] inputBytes = IOUtils.toByteArray(getRequest().getInputStream());
-        ByteBuf byteBuf = Unpooled.wrappedBuffer(inputBytes);
+        Buffer byteBuf = Buffer.buffer(inputBytes);
         this.inputStream = new BufferInputStream(byteBuf);
-        setBodyBuffer(Buffer.buffer(Unpooled.wrappedBuffer(byteBuf)));
+        setBodyBuffer(byteBuf);
       } else {
         this.inputStream = getRequest().getInputStream();
       }
diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
index 737e400bd..da55f5ff6 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/VertxServerRequestToHttpServletRequest.java
@@ -268,7 +268,7 @@ public class VertxServerRequestToHttpServletRequest extends 
AbstractHttpServletR
     if (context.body().buffer() == null) {
       return null;
     }
-    inputStream = new BufferInputStream(context.body().buffer().getByteBuf());
+    inputStream = new BufferInputStream(context.body().buffer());
     return inputStream;
   }
 
diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/BufferInputStream.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/BufferInputStream.java
index 09840be11..af0d4acf1 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/BufferInputStream.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/BufferInputStream.java
@@ -20,57 +20,69 @@ package org.apache.servicecomb.foundation.vertx.stream;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 
-import io.netty.buffer.ByteBuf;
+import io.vertx.core.buffer.Buffer;
 import jakarta.servlet.ReadListener;
 import jakarta.servlet.ServletInputStream;
 
 public class BufferInputStream extends ServletInputStream {
-  private final ByteBuf byteBuf;
+  private int readIndex = 0;
 
-  public BufferInputStream(ByteBuf buffer) {
+  private final Buffer byteBuf;
+
+  public BufferInputStream(Buffer buffer) {
     this.byteBuf = buffer;
   }
 
   @Override
   public long skip(long len) {
     int skipLen = Math.min((int) len, available());
-    byteBuf.skipBytes(skipLen);
+    this.readIndex += skipLen;
     return skipLen;
   }
 
   public byte readByte() {
-    return byteBuf.readByte();
+    int index = readIndex;
+    readIndex = index + 1;
+    return byteBuf.getByte(index);
   }
 
   @Override
   public int read() {
-    return byteBuf.readUnsignedByte();
+    return this.readByte() & 255;
   }
 
   public boolean readBoolean() {
-    return byteBuf.readBoolean();
+    return this.readByte() != 0;
   }
 
   public short readShort() {
-    return byteBuf.readShort();
+    int index = readIndex;
+    readIndex = index + 2;
+    return byteBuf.getShort(index);
   }
 
   public int readInt() {
-    return byteBuf.readInt();
+    int index = readIndex;
+    readIndex = index + 4;
+    return byteBuf.getInt(index);
   }
 
   public long readLong() {
-    return byteBuf.readLong();
+    int index = readIndex;
+    readIndex = index + 8;
+    return byteBuf.getLong(index);
   }
 
   public int getIndex() {
-    return byteBuf.readerIndex();
+    return readIndex;
   }
 
   public String readString() {
     int length = readInt();
     byte[] bytes = new byte[length];
-    byteBuf.readBytes(bytes);
+    int index = readIndex;
+    readIndex = index + length;
+    byteBuf.getBytes(index, readIndex, bytes);
     return new String(bytes, StandardCharsets.UTF_8);
   }
 
@@ -94,32 +106,35 @@ public class BufferInputStream extends ServletInputStream {
       len = avail;
     }
 
-    byteBuf.readBytes(b, off, len);
+    int index = readIndex;
+    readIndex = index + len;
+
+    byteBuf.getBytes(index, readIndex, b);
     return len;
   }
 
   @Override
   public int available() {
-    return byteBuf.readableBytes();
+    return byteBuf.length() - readIndex;
   }
 
   @Override
   public void close() {
-    byteBuf.release();
+    // nothing to do
   }
 
   @Override
   public void reset() throws IOException {
-    byteBuf.resetReaderIndex();
+    readIndex = 0;
   }
 
-  public ByteBuf getByteBuf() {
+  public Buffer getByteBuf() {
     return byteBuf;
   }
 
   @Override
   public boolean isFinished() {
-    return !byteBuf.isReadable();
+    return byteBuf.length() > readIndex;
   }
 
   @Override
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 f063d5d06..42c9b3126 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
@@ -20,9 +20,7 @@ package org.apache.servicecomb.foundation.vertx.stream;
 import java.io.OutputStream;
 import java.nio.charset.StandardCharsets;
 
-import io.netty.buffer.ByteBuf;
 import io.vertx.core.buffer.Buffer;
-import io.vertx.core.buffer.impl.VertxByteBufAllocator;
 
 /**
  * BufferOutputStream.
@@ -32,40 +30,36 @@ import io.vertx.core.buffer.impl.VertxByteBufAllocator;
 public class BufferOutputStream extends OutputStream {
   private static final int DIRECT_BUFFER_SIZE = 1024;
 
-  protected ByteBuf byteBuf;
+  protected Buffer byteBuf;
 
   public BufferOutputStream() {
-    this(VertxByteBufAllocator.DEFAULT.heapBuffer(DIRECT_BUFFER_SIZE, 
Integer.MAX_VALUE));
+    this(Buffer.buffer(DIRECT_BUFFER_SIZE));
   }
 
-  public BufferOutputStream(ByteBuf buffer) {
+  public BufferOutputStream(Buffer buffer) {
     this.byteBuf = buffer;
   }
 
-  public ByteBuf getByteBuf() {
-    return byteBuf;
-  }
-
   public Buffer getBuffer() {
-    return Buffer.buffer(byteBuf);
+    return byteBuf;
   }
 
   public int length() {
-    return byteBuf.readableBytes();
+    return byteBuf.length();
   }
 
   public void writeByte(byte value) {
-    byteBuf.writeByte(value);
+    byteBuf.appendByte(value);
   }
 
   // 实际是写byte
   @Override
   public void write(int byteValue) {
-    byteBuf.writeByte((byte) byteValue);
+    byteBuf.appendByte((byte) byteValue);
   }
 
   public void write(boolean value) {
-    byteBuf.writeBoolean(value);
+    byteBuf.appendByte(value ? (byte) 1 : (byte) 0);
   }
 
   public void writeInt(int pos, int value) {
@@ -73,20 +67,20 @@ public class BufferOutputStream extends OutputStream {
   }
 
   public void writeShort(short value) {
-    byteBuf.writeShort(value);
+    byteBuf.appendShort(value);
   }
 
   public void writeInt(int value) {
-    byteBuf.writeInt(value);
+    byteBuf.appendInt(value);
   }
 
   public void writeLong(long value) {
-    byteBuf.writeLong(value);
+    byteBuf.appendLong(value);
   }
 
   public void writeString(String value) {
-    byteBuf.writeInt(value.length());
-    byteBuf.writeCharSequence(value, StandardCharsets.UTF_8);
+    writeInt(value.length());
+    byteBuf.appendString(value, StandardCharsets.UTF_8.toString());
   }
 
   @Override
@@ -96,7 +90,7 @@ public class BufferOutputStream extends OutputStream {
 
   @Override
   public void write(byte[] bytes, int offset, int len) {
-    byteBuf.writeBytes(bytes, offset, len);
+    byteBuf.appendBytes(bytes, offset, len);
   }
 
   @Override
@@ -105,6 +99,6 @@ public class BufferOutputStream extends OutputStream {
   }
 
   public int writerIndex() {
-    return byteBuf.writerIndex();
+    return byteBuf.length();
   }
 }
diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/tcp/TcpConnection.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/tcp/TcpConnection.java
index 95f460013..15e6977d2 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/tcp/TcpConnection.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/tcp/TcpConnection.java
@@ -20,9 +20,6 @@ import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.atomic.AtomicLong;
 
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufAllocator;
-import io.netty.buffer.CompositeByteBuf;
 import io.vertx.core.Context;
 import io.vertx.core.buffer.Buffer;
 import io.vertx.core.net.NetSocket;
@@ -49,7 +46,7 @@ public class TcpConnection {
   // so this optimization:
   // 1.avoid vertx's lock
   // 2.reduce netty's task schedule
-  private final Queue<ByteBuf> writeQueue = new ConcurrentLinkedQueue<>();
+  private final Queue<Buffer> writeQueue = new ConcurrentLinkedQueue<>();
 
   private final AtomicLong writeQueueSize = new AtomicLong();
 
@@ -83,7 +80,7 @@ public class TcpConnection {
     this.context = netSocket.getContext();
   }
 
-  public void write(ByteBuf buf) {
+  public void write(Buffer buf) {
     writeQueue.add(buf);
     long oldSize = writeQueueSize.getAndIncrement();
     if (oldSize == 0) {
@@ -97,25 +94,15 @@ public class TcpConnection {
   }
 
   protected void writeInContext() {
-    CompositeByteBuf cbb = ByteBufAllocator.DEFAULT.compositeBuffer();
     for (; ; ) {
-      ByteBuf buf = writeQueue.poll();
+      Buffer buf = writeQueue.poll();
       if (buf == null) {
         break;
       }
 
       writeQueueSize.decrementAndGet();
-      cbb.addComponent(true, buf);
 
-      if (cbb.numComponents() == cbb.maxNumComponents()) {
-        CompositeByteBuf last = cbb;
-        netSocket.write(Buffer.buffer(last)).onComplete(r -> last.release());
-        cbb = ByteBufAllocator.DEFAULT.compositeBuffer();
-      }
-    }
-    if (cbb.isReadable()) {
-      CompositeByteBuf last = cbb;
-      netSocket.write(Buffer.buffer(last)).onComplete(r -> last.release());
+      netSocket.write(buf);
     }
   }
 }
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 2c9fdc895..ea3a797da 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
@@ -22,8 +22,7 @@ import 
org.apache.servicecomb.foundation.vertx.stream.BufferOutputStream;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-import io.netty.buffer.ByteBuf;
-import io.vertx.core.buffer.impl.VertxByteBufAllocator;
+import io.vertx.core.buffer.Buffer;
 
 public class TestStream {
 
@@ -31,16 +30,21 @@ public class TestStream {
 
   @Test
   public void testBufferInputStream() {
-    ByteBuf obuf = 
VertxByteBufAllocator.DEFAULT.heapBuffer(DIRECT_BUFFER_SIZE, Integer.MAX_VALUE);
-    obuf.writeBytes(("testss").getBytes());
+    Buffer obuf = Buffer.buffer(DIRECT_BUFFER_SIZE);
+    obuf.appendBytes(("testss").getBytes());
     @SuppressWarnings("resource")
     BufferInputStream oBufferInputStream = new BufferInputStream(obuf);
-    Assertions.assertNotEquals(1234, oBufferInputStream.skip(0));
-    Assertions.assertNotEquals(obuf.readByte(), oBufferInputStream.readByte());
-    Assertions.assertEquals(obuf.readByte() + 1, oBufferInputStream.read());
-    Assertions.assertEquals(obuf.readBoolean(), 
oBufferInputStream.readBoolean());
-    Assertions.assertEquals(obuf.readerIndex(), oBufferInputStream.getIndex());
-    Assertions.assertEquals(obuf.readableBytes(), 
oBufferInputStream.available());
+
+    byte test = oBufferInputStream.readByte();
+    Assertions.assertEquals((byte) 't', test);
+    Assertions.assertEquals((byte) 'e', oBufferInputStream.read());
+
+    Assertions.assertEquals(2, oBufferInputStream.skip(2));
+    Assertions.assertEquals((byte) 's', oBufferInputStream.read());
+    Assertions.assertTrue(oBufferInputStream.readBoolean());
+
+    Assertions.assertEquals(6, oBufferInputStream.getIndex());
+    Assertions.assertEquals(0, oBufferInputStream.available());
   }
 
   @Test
@@ -53,9 +57,9 @@ public class TestStream {
     Assertions.assertTrue((1 < oBufferOutputStream.length()));
 
     @SuppressWarnings("resource")
-    BufferInputStream oBufferInputStream = new 
BufferInputStream(oBufferOutputStream.getByteBuf());
+    BufferInputStream oBufferInputStream = new 
BufferInputStream(oBufferOutputStream.getBuffer());
     Assertions.assertEquals("test", oBufferInputStream.readString());
     Assertions.assertEquals(1, oBufferInputStream.readByte());
-    Assertions.assertEquals(true, oBufferInputStream.readBoolean());
+    Assertions.assertTrue(oBufferInputStream.readBoolean());
   }
 }
diff --git 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
index 399d0b1f6..f3762fe5f 100644
--- 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
+++ 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/TestVertxUtils.java
@@ -131,11 +131,12 @@ public class TestVertxUtils {
   @Test
   public void testgetBytesFastBufferInputStream() throws IOException {
     byte[] bytes = new byte[] {1};
-    ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
+    Buffer byteBuf = Buffer.buffer(bytes);
 
     try (BufferInputStream inputStream = new BufferInputStream(byteBuf)) {
       byte[] result = VertxUtils.getBytesFast(inputStream);
-      Assertions.assertSame(bytes, result);
+      Assertions.assertEquals(bytes.length, result.length);
+      Assertions.assertEquals(bytes[0], result[0]);
     }
   }
 
diff --git 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnection.java
 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnection.java
index 0767898f2..de87122f1 100644
--- 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnection.java
+++ 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/client/tcp/TestTcpClientConnection.java
@@ -25,13 +25,14 @@ import 
org.apache.servicecomb.foundation.vertx.client.tcp.TcpClientConnection.St
 import org.apache.servicecomb.foundation.vertx.tcp.TcpOutputStream;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
 
 import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 import io.vertx.core.AsyncResult;
 import io.vertx.core.Context;
 import io.vertx.core.Handler;
 import io.vertx.core.Promise;
+import io.vertx.core.buffer.Buffer;
 import io.vertx.core.net.NetSocket;
 import io.vertx.core.net.impl.NetSocketImpl;
 import mockit.Deencapsulation;
@@ -39,7 +40,6 @@ import mockit.Expectations;
 import mockit.Mock;
 import mockit.MockUp;
 import mockit.Mocked;
-import org.junit.jupiter.api.Assertions;
 
 public class TestTcpClientConnection {
   @Mocked
@@ -90,14 +90,14 @@ public class TestTcpClientConnection {
     Deencapsulation.setField(tcpClientConnection, "status", Status.WORKING);
 
     long msgId = 1;
-    ByteBuf byteBuf = Unpooled.buffer();
+    Buffer byteBuf = Buffer.buffer();
     new Expectations(tcpClientConnection) {
       {
         tcpClientPackage.getMsgId();
         result = msgId;
         tcpClientPackage.createStream();
         result = tcpOutputStream;
-        tcpOutputStream.getByteBuf();
+        tcpOutputStream.getBuffer();
         result = byteBuf;
       }
     };
@@ -172,7 +172,7 @@ public class TestTcpClientConnection {
       {
         tcpClientPackage.getMsgId();
         result = msgId;
-        tcpClientConnection.write((ByteBuf) any);
+        tcpClientConnection.write((Buffer) any);
       }
     };
     new MockUp<Context>(context) {
diff --git 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
index d0adef2ce..15e52aa5f 100644
--- 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
+++ 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestStandardHttpServletRequestEx.java
@@ -117,7 +117,7 @@ public class TestStandardHttpServletRequestEx {
     inherited.put("p1", v1);
 
     Buffer buffer = Buffer.buffer("p1=v1-3;p2=v2");
-    BufferInputStream inputStream = new BufferInputStream(buffer.getByteBuf());
+    BufferInputStream inputStream = new BufferInputStream(buffer);
     new Expectations() {
       {
         request.getParameterMap();
diff --git 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestBufferInputStream.java
 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestBufferInputStream.java
index 070fe207d..40be5d486 100644
--- 
a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestBufferInputStream.java
+++ 
b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestBufferInputStream.java
@@ -29,8 +29,7 @@ import org.junit.Test;
 import org.junit.jupiter.api.Assertions;
 import org.mockito.Mockito;
 
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
+import io.vertx.core.buffer.Buffer;
 
 public class TestBufferInputStream {
 
@@ -38,7 +37,7 @@ public class TestBufferInputStream {
 
   @Before
   public void setUp() throws Exception {
-    ByteBuf buffer = Mockito.mock(ByteBuf.class);
+    Buffer buffer = Mockito.mock(Buffer.class);
     instance = new BufferInputStream(buffer);
   }
 
@@ -60,8 +59,8 @@ public class TestBufferInputStream {
     gzipOutputStream.write(text.getBytes());
     gzipOutputStream.close();
 
-    ByteBuf buffer = Unpooled.buffer();
-    buffer.writeBytes(out.toByteArray());
+    Buffer buffer = Buffer.buffer();
+    buffer.appendBytes(out.toByteArray());
     out.close();
     BufferInputStream bufferInputStream = new BufferInputStream(buffer);
     GZIPInputStream gzipInputStream = new GZIPInputStream(bufferInputStream);
diff --git 
a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayProducerInvocationFlow.java
 
b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayProducerInvocationFlow.java
index 36e0af598..f973f9e1c 100644
--- 
a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayProducerInvocationFlow.java
+++ 
b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayProducerInvocationFlow.java
@@ -58,6 +58,6 @@ public class HighwayProducerInvocationFlow extends 
ProducerInvocationFlow {
   @Override
   protected void sendResponse(Invocation invocation, Response response) {
     HighwayTransportContext transportContext = 
invocation.getTransportContext();
-    connection.write(transportContext.getResponseBuffer().getByteBuf());
+    connection.write(transportContext.getResponseBuffer());
   }
 }

Reply via email to