wujimin closed pull request #1001: [SCB-968]968 http2 do not support pump download URL: https://github.com/apache/servicecomb-java-chassis/pull/1001
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/LICENSE b/LICENSE index c75dbb5b5..48c8a8e59 100644 --- a/LICENSE +++ b/LICENSE @@ -216,6 +216,11 @@ transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicec This product bundles files from vertx which is licensed under the Apache License v2. For details, see https://github.com/vert-x3/vertx-web +================================================================ +For foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpImplEx.java +================================================================ +This product bundles files from vertx which is licensed under the Apache License v2. +For details, see https://github.com/eclipse-vertx/vert.x ================================================================ For swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/extend/property/AbstractBaseIntegerProperty.java diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpCommon.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpCommon.java index 77334b9c9..090882ab1 100644 --- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpCommon.java +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpCommon.java @@ -23,7 +23,6 @@ import io.vertx.core.Context; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpClientResponse; -import io.vertx.core.streams.Pump; import io.vertx.core.streams.ReadStream; import io.vertx.core.streams.WriteStream; @@ -64,7 +63,7 @@ // belongs to difference eventloop // maybe will cause deadlock // if happened, vertx will print deadlock stacks - Pump.pump(readStream, writeStream).start(); + PumpImplEx.getPumpImplEx(readStream, writeStream).start(); try { context.runOnContext(v -> readStream.resume()); } catch (Throwable e) { diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpImplEx.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpImplEx.java new file mode 100644 index 000000000..e8356298f --- /dev/null +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpImplEx.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2014 Red Hat, Inc. and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + */ + +/* + * Froked from https://github.com/eclipse-vertx/vert.x/blob/master/src/main/java/io/vertx/core/streams/impl/PumpImpl.java + * + */ +package org.apache.servicecomb.foundation.vertx.stream; + +import io.vertx.core.Handler; +import io.vertx.core.buffer.Buffer; +import io.vertx.core.streams.Pump; +import io.vertx.core.streams.ReadStream; +import io.vertx.core.streams.WriteStream; + +public class PumpImplEx<T> implements Pump { + + private final ReadStream<T> readStream; + + private final WriteStream<T> writeStream; + + private final Handler<T> dataHandler; + + private final Handler<Void> drainHandler; + + private int pumped; + + public PumpImplEx(ReadStream<T> readStream, WriteStream<T> writeStream, int maxWriteQueueSize) { + this(readStream, writeStream); + this.writeStream.setWriteQueueMaxSize(maxWriteQueueSize); + } + + public PumpImplEx(ReadStream<T> readStream, WriteStream<T> writeStream) { + this.readStream = readStream; + this.writeStream = writeStream; + drainHandler = v -> readStream.resume(); + dataHandler = data -> { + if (data instanceof Buffer) { + if (((Buffer) data).length() == 0) { + return; + } + } + writeStream.write(data); + incPumped(); + if (writeStream.writeQueueFull()) { + readStream.pause(); + writeStream.drainHandler(drainHandler); + } + }; + } + + + @Override + public PumpImplEx<T> setWriteQueueMaxSize(int maxSize) { + writeStream.setWriteQueueMaxSize(maxSize); + return this; + } + + @Override + public PumpImplEx<T> start() { + readStream.handler(dataHandler); + return this; + } + + @Override + public PumpImplEx<T> stop() { + writeStream.drainHandler(null); + readStream.handler(null); + return this; + } + + + @Override + public synchronized int numberPumped() { + return pumped; + } + + + private synchronized void incPumped() { + pumped++; + } + + public Handler<T> getDataHandler() { + return dataHandler; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public static PumpImplEx getPumpImplEx(ReadStream rs, WriteStream ws) { + return new PumpImplEx(rs, ws); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public static PumpImplEx getPumpImplEx(ReadStream rs, WriteStream ws, int writeQueueMaxSize) { + return new PumpImplEx(rs, ws, writeQueueMaxSize); + } +} diff --git a/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpImpl.java b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpImpl.java new file mode 100644 index 000000000..3380550e1 --- /dev/null +++ b/foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/stream/TestPumpImpl.java @@ -0,0 +1,50 @@ +/* + * 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.servicecomb.foundation.vertx.stream; + +import org.junit.Assert; +import org.junit.Test; + +import io.vertx.core.Handler; +import io.vertx.core.buffer.Buffer; +import io.vertx.core.streams.ReadStream; +import io.vertx.core.streams.WriteStream; +import mockit.Expectations; +import mockit.Mocked; + +public class TestPumpImpl { + + @Test + public void testPumpWithPending(@Mocked ReadStream<Object> rs, @Mocked WriteStream<Object> ws, @Mocked Buffer zeroBuf, + @Mocked Buffer contentBuf) { + PumpImplEx<Object> pump = new PumpImplEx<>(rs, ws); + Handler<Object> handler = pump.getDataHandler(); + new Expectations() { + { + zeroBuf.length(); + result = 0; + contentBuf.length(); + result = 1; + } + }; + handler.handle(zeroBuf); + handler.handle(contentBuf); + Assert.assertEquals(1, pump.numberPumped()); + handler.handle(contentBuf); + Assert.assertEquals(2, pump.numberPumped()); + } +} diff --git a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java index 2209583cb..0ef503900 100644 --- a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java +++ b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java @@ -103,10 +103,7 @@ private static void runShareTestCases() throws Throwable { // only rest support default value feature ITJUnitUtils.runWithRest(TestDefaultValue.class); - // currently have bug with http2 - if (!ITJUnitUtils.getProducerName().endsWith("-h2") && !ITJUnitUtils.getProducerName().endsWith("-h2c")) { - ITJUnitUtils.runWithRest(TestDownload.class); - } + ITJUnitUtils.runWithRest(TestDownload.class); ITJUnitUtils.runWithHighwayAndRest(TestTrace.class); ITJUnitUtils.run(TestTraceEdge.class); diff --git a/integration-tests/it-producer-deploy-springboot2-servlet/pom.xml b/integration-tests/it-producer-deploy-springboot2-servlet/pom.xml index b8bf93e38..068674ec7 100644 --- a/integration-tests/it-producer-deploy-springboot2-servlet/pom.xml +++ b/integration-tests/it-producer-deploy-springboot2-servlet/pom.xml @@ -92,6 +92,7 @@ <!-- Skip the source files which are forked from vertx --> <exclude>**/io/vertx/ext/web/impl/MimeTypesUtils.java</exclude> <exclude>**/java/org/apache/servicecomb/transport/rest/vertx/RestBodyHandler.java</exclude> + <exclude>**/java/org/apache/servicecomb/foundation/vertx/stream/PumpImplEx.java</exclude> <!--Skip protobuf generated file--> <exclude>**/java/org/apache/servicecomb/foundation/protobuf/internal/model/ProtobufRoot.java</exclude> </excludes> diff --git a/integration-tests/it-producer-deploy-springboot2-standalone/pom.xml b/integration-tests/it-producer-deploy-springboot2-standalone/pom.xml index e05b10c15..e35dc0203 100644 --- a/integration-tests/it-producer-deploy-springboot2-standalone/pom.xml +++ b/integration-tests/it-producer-deploy-springboot2-standalone/pom.xml @@ -92,6 +92,7 @@ <!-- Skip the source files which are forked from vertx --> <exclude>**/io/vertx/ext/web/impl/MimeTypesUtils.java</exclude> <exclude>**/java/org/apache/servicecomb/transport/rest/vertx/RestBodyHandler.java</exclude> + <exclude>**/java/org/apache/servicecomb/foundation/vertx/stream/PumpImplEx.java</exclude> <!--Skip protobuf generated file--> <exclude>**/java/org/apache/servicecomb/foundation/protobuf/internal/model/ProtobufRoot.java</exclude> </excludes> diff --git a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DownloadSchema.java b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DownloadSchema.java index b1123b60f..5ba7d8b85 100644 --- a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DownloadSchema.java +++ b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DownloadSchema.java @@ -197,7 +197,6 @@ public String getFilename() { .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=netInputStream.txt") .body(conn.getInputStream()); - conn.disconnect(); return responseEntity; } diff --git a/java-chassis-distribution/src/release/LICENSE b/java-chassis-distribution/src/release/LICENSE index df7780670..638a7a9be 100644 --- a/java-chassis-distribution/src/release/LICENSE +++ b/java-chassis-distribution/src/release/LICENSE @@ -368,6 +368,12 @@ transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicec This product bundles files from vertx which is licensed under the Apache License v2. For details, see https://github.com/vert-x3/vertx-web +================================================================ +For foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/stream/PumpImplEx.java +================================================================ +This product bundles files from vertx which is licensed under the Apache License v2. +For details, see https://github.com/eclipse-vertx/vert.x + ================================================================ For swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/extend/property/AbstractBaseIntegerProperty.java ================================================================ diff --git a/pom.xml b/pom.xml index 40e6ce09a..b111da29b 100644 --- a/pom.xml +++ b/pom.xml @@ -195,6 +195,7 @@ <!-- Skip the source files which are forked from vertx --> <exclude>**/io/vertx/ext/web/impl/MimeTypesUtils.java</exclude> <exclude>**/java/org/apache/servicecomb/transport/rest/vertx/RestBodyHandler.java</exclude> + <exclude>**/java/org/apache/servicecomb/foundation/vertx/stream/PumpImplEx.java</exclude> <!--Skip protobuf generated file--> <exclude>**/java/org/apache/servicecomb/foundation/protobuf/internal/model/ProtobufRoot.java</exclude> </excludes> ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
