[1/2] camel git commit: CAMEL-10409 Double release of netty buffer with thanks to Vitalii

2016-11-14 Thread ningjiang
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x e6256ae9d -> 3f346ea84


CAMEL-10409 Double release of netty buffer with thanks to Vitalii

Conflicts:

components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/27b572dc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/27b572dc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/27b572dc

Branch: refs/heads/camel-2.18.x
Commit: 27b572dc10f3cb61e9ae77f6f42f7fc29c0ea6d4
Parents: e6256ae
Author: Willem Jiang 
Authored: Tue Nov 15 10:04:41 2016 +0800
Committer: Willem Jiang 
Committed: Tue Nov 15 10:56:19 2016 +0800

--
 .../netty4/http/NettyHttpProducer.java  | 14 -
 .../component/netty4/http/BaseNettyTest.java| 25 
 .../netty4/http/LogCaptureAppender.java | 65 
 .../component/netty4/http/LogCaptureTest.java   | 35 +++
 .../src/test/resources/log4j2.properties|  7 +++
 .../camel/component/netty4/NettyProducer.java   | 43 +++--
 6 files changed, 169 insertions(+), 20 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/camel/blob/27b572dc/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
--
diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
index 8a6b540..0be479a 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
@@ -74,20 +74,6 @@ public class NettyHttpProducer extends NettyProducer {
 // Need to remove the Host key as it should be not used when 
bridging/proxying
 exchange.getIn().removeHeader("host");
 }
-
-// need to release the request when we are done
-exchange.addOnCompletion(new SynchronizationAdapter() {
-@Override
-public void onDone(Exchange exchange) {
-if (request instanceof ReferenceCounted) {
-if (((ReferenceCounted) request).refCnt() > 0) {
-log.debug("Releasing Netty HttpRequest ByteBuf");
-ReferenceCountUtil.release(request);
-}
-}
-}
-});
-
 return request;
 }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/27b572dc/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
--
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
index c511d89..75916e5 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
@@ -18,14 +18,19 @@ package org.apache.camel.component.netty4.http;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.util.Collection;
 import java.util.Properties;
 
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.util.ResourceLeakDetector;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.converter.IOConverter;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.logging.log4j.core.LogEvent;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -65,6 +70,26 @@ public class BaseNettyTest extends CamelTestSupport {
 }
 }
 
+@BeforeClass
+public static void startLeakDetection() {
+System.setProperty("io.netty.leakDetection.maxRecords", "100");
+ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
+}
+
+@AfterClass
+public static void verifyNoLeaks() throws Exception {
+//Force GC to bring up leaks
+System.gc();
+//Kick leak detection logging
+ByteBufAllocator.DEFAULT.buffer(1).release();
+Collection events = LogCaptureAppender.getEvents();
+if (!events.isEmpty()) {
+String message = "Leaks detected while running tests: " + events;
+

camel git commit: CAMEL-10409 Double release of netty buffer with thanks to Vitalii

2016-11-14 Thread ningjiang
Repository: camel
Updated Branches:
  refs/heads/master 268b6947e -> 7d46782a7


CAMEL-10409 Double release of netty buffer with thanks to Vitalii


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7d46782a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7d46782a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7d46782a

Branch: refs/heads/master
Commit: 7d46782a7bad42053dd5fb0d27281a85f4ec08c4
Parents: 268b6947
Author: Willem Jiang 
Authored: Tue Nov 15 10:04:41 2016 +0800
Committer: Willem Jiang 
Committed: Tue Nov 15 10:25:46 2016 +0800

--
 .../netty4/http/NettyHttpProducer.java  | 13 
 .../component/netty4/http/BaseNettyTest.java| 25 
 .../netty4/http/LogCaptureAppender.java | 65 
 .../component/netty4/http/LogCaptureTest.java   | 35 +++
 .../src/test/resources/log4j2.properties|  7 +++
 .../camel/component/netty4/NettyProducer.java   | 43 +++--
 6 files changed, 169 insertions(+), 19 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/camel/blob/7d46782a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
--
diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
index 31710e0..1ee3616 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpProducer.java
@@ -86,19 +86,6 @@ public class NettyHttpProducer extends NettyProducer {
 }
 }
 
-// need to release the request when we are done
-exchange.addOnCompletion(new SynchronizationAdapter() {
-@Override
-public void onDone(Exchange exchange) {
-if (request instanceof ReferenceCounted) {
-if (((ReferenceCounted) request).refCnt() > 0) {
-log.debug("Releasing Netty HttpRequest ByteBuf");
-ReferenceCountUtil.release(request);
-}
-}
-}
-});
-
 return request;
 }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/7d46782a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
--
diff --git 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
index c511d89..75916e5 100644
--- 
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
+++ 
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/BaseNettyTest.java
@@ -18,14 +18,19 @@ package org.apache.camel.component.netty4.http;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.util.Collection;
 import java.util.Properties;
 
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.util.ResourceLeakDetector;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.converter.IOConverter;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.logging.log4j.core.LogEvent;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -65,6 +70,26 @@ public class BaseNettyTest extends CamelTestSupport {
 }
 }
 
+@BeforeClass
+public static void startLeakDetection() {
+System.setProperty("io.netty.leakDetection.maxRecords", "100");
+ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
+}
+
+@AfterClass
+public static void verifyNoLeaks() throws Exception {
+//Force GC to bring up leaks
+System.gc();
+//Kick leak detection logging
+ByteBufAllocator.DEFAULT.buffer(1).release();
+Collection events = LogCaptureAppender.getEvents();
+if (!events.isEmpty()) {
+String message = "Leaks detected while running tests: " + events;
+LogCaptureAppender.reset();
+throw new AssertionError(message);
+}
+}
+
 @Override
 protected CamelContext createCamelContext() throws Exception {
 CamelContext context = super.createCamelContext();

http://git-wip-us.apache.org