You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/04/16 05:26:12 UTC

[camel] 01/02: camel-netty-http - Fixed flaky test

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 37ada72e18efbb2f29202d14389035df929d7d95
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Apr 16 07:22:12 2021 +0200

    camel-netty-http - Fixed flaky test
---
 .../netty/http/NettyHttpCompressTest.java          | 31 +++++++++-------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCompressTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCompressTest.java
index 3f64007..c86fc91 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCompressTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpCompressTest.java
@@ -16,16 +16,14 @@
  */
 package org.apache.camel.component.netty.http;
 
-import java.nio.charset.Charset;
-import java.util.ArrayList;
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
+import java.util.zip.GZIPInputStream;
 
-import io.netty.channel.ChannelHandler;
-import io.netty.handler.codec.http.HttpContentDecompressor;
-import org.apache.camel.BindToRegistry;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.IOHelper;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.parallel.Isolated;
 
@@ -34,24 +32,21 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 @Isolated
 public class NettyHttpCompressTest extends BaseNettyTest {
 
-    // setup the decompress decoder here
-    @BindToRegistry("myDecoders")
-    public List<ChannelHandler> addChannelHandlers() throws Exception {
-        List<ChannelHandler> decoders = new ArrayList<>();
-        decoders.add(new HttpContentDecompressor());
-        return decoders;
-    }
-
     @Test
     public void testContentType() throws Exception {
-        byte[] data = "Hello World".getBytes(Charset.forName("UTF-8"));
+        byte[] data = "Hello World".getBytes(StandardCharsets.UTF_8);
         Map<String, Object> headers = new HashMap<>();
         headers.put("content-type", "text/plain; charset=\"UTF-8\"");
         headers.put("Accept-Encoding", "compress, gzip");
-        String out = template.requestBodyAndHeaders("netty-http:http://localhost:{{port}}/foo?decoders=#myDecoders", data,
-                headers, String.class);
+        byte[] out
+                = template.requestBodyAndHeaders("netty-http:http://localhost:{{port}}/foo", data,
+                        headers, byte[].class);
+        // deflate the zip
+        GZIPInputStream zis = new GZIPInputStream(new ByteArrayInputStream(out));
+        String s = IOHelper.loadText(zis);
+        IOHelper.close(zis);
         // The decoded out has some space to clean up.
-        assertEquals("Bye World", out.trim());
+        assertEquals("Bye World", s.trim());
     }
 
     @Override