You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2023/02/22 20:01:24 UTC
[camel] branch main updated: CAMEL-18988: camel-core - tests failing due to OOM (#9398)
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 47b88426325 CAMEL-18988: camel-core - tests failing due to OOM (#9398)
47b88426325 is described below
commit 47b884263256145b89b0b17e5efb5f6aa2570378
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Wed Feb 22 21:01:15 2023 +0100
CAMEL-18988: camel-core - tests failing due to OOM (#9398)
## Motivation
Since we upgraded to surefire + failsafe M8, some of our tests have started to fail with `OutOfMemoryException`.
## Modifications
After a deeper analysis using JProfiler, it appears that there is no significant memory leak, only small ones, especially some `DefaultCamelContext` leaks.
* Restore the log level to info
* Fix main `DefaultCamelContext` leaks except for the Simple expression cache and the cache in `DefaultParameterMappingStrategy`.
* Add JVM options to allow future analysis if it happens again
---
core/camel-core/pom.xml | 1 +
.../apache/camel/builder/ExchangeBuilderTest.java | 22 +++++++++++++++++-----
.../camel/catalog/RuntimeCamelCatalogTest.java | 6 ++++++
.../camel/component/log/LogEndpointTest.java | 6 ++++++
.../CamelProduceInterfaceEventNotifierTest.java | 2 +-
.../event/CamelEventsTimestampEnabledTest.java | 10 +---------
.../camel/impl/event/EventNotifierEventsTest.java | 3 +--
.../event/EventNotifierExchangeCompletedTest.java | 10 +---------
.../impl/event/EventNotifierExchangeSentTest.java | 2 +-
.../EventNotifierFailureHandledEventsTest.java | 10 +---------
...ntNotifierIgnoreCamelContextInitEventsTest.java | 3 +--
.../event/EventNotifierRedeliveryEventsTest.java | 10 +---------
...ventNotifierServiceStoppingFailedEventTest.java | 10 +---------
.../event/MultipleEventNotifierEventsTest.java | 13 ++-----------
.../impl/event/SimpleEventNotifierEventsTest.java | 3 +--
.../apache/camel/processor/NavigateRouteTest.java | 2 +-
.../src/test/resources/log4j2.properties | 8 ++++----
.../throttling/ThrottlingExceptionRoutePolicy.java | 9 +++++++++
18 files changed, 56 insertions(+), 74 deletions(-)
diff --git a/core/camel-core/pom.xml b/core/camel-core/pom.xml
index d8ccffda633..a7e046552a3 100644
--- a/core/camel-core/pom.xml
+++ b/core/camel-core/pom.xml
@@ -286,6 +286,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- skip file stress tests as they are intended to run manually -->
+ <argLine>${camel.surefire.fork.vmargs} -Xmx2G -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError="jcmd %p Thread.print" -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=jvm.log</argLine>
<excludes>
<exclude>org/apache/camel/component/file/stress/**.java</exclude>
<exclude>**/DistributedCompletionIntervalTest.java</exclude>
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/ExchangeBuilderTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/ExchangeBuilderTest.java
index a60d63296a6..7912f8a5166 100644
--- a/core/camel-core/src/test/java/org/apache/camel/builder/ExchangeBuilderTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/ExchangeBuilderTest.java
@@ -21,22 +21,34 @@ import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ExchangeBuilderTest {
- private static final CamelContext CONTEXT = new DefaultCamelContext();
+ private static CamelContext context;
private static final String BODY = "Message Body";
private static final String KEY = "Header key";
private static final String VALUE = "Header value";
private static final String PROPERTY_KEY = "Property key";
private static final String PROPERTY_VALUE = "Property value";
+ @BeforeAll
+ public static void init() {
+ context = new DefaultCamelContext();
+ }
+
+ @AfterAll
+ public static void destroy() {
+ context = null;
+ }
+
@Test
public void testBuildAnExchangeWithDefaultPattern() {
- Exchange exchange = new DefaultExchange(CONTEXT);
- Exchange builtExchange = ExchangeBuilder.anExchange(CONTEXT).build();
+ Exchange exchange = new DefaultExchange(context);
+ Exchange builtExchange = ExchangeBuilder.anExchange(context).build();
assertEquals(exchange.getPattern(), builtExchange.getPattern());
}
@@ -44,7 +56,7 @@ public class ExchangeBuilderTest {
@Test
public void testBuildAnExchangeWithBodyHeaderAndPatternInOnly() throws Exception {
- Exchange exchange = ExchangeBuilder.anExchange(CONTEXT).withBody(BODY).withHeader(KEY, VALUE)
+ Exchange exchange = ExchangeBuilder.anExchange(context).withBody(BODY).withHeader(KEY, VALUE)
.withProperty(PROPERTY_KEY, PROPERTY_VALUE).withPattern(ExchangePattern.InOnly)
.build();
@@ -57,7 +69,7 @@ public class ExchangeBuilderTest {
@Test
public void testBuildAnExchangeWithBodyHeaderAndPatternInOut() throws Exception {
- Exchange exchange = ExchangeBuilder.anExchange(CONTEXT).withBody(BODY).withHeader(KEY, VALUE)
+ Exchange exchange = ExchangeBuilder.anExchange(context).withBody(BODY).withHeader(KEY, VALUE)
.withProperty(PROPERTY_KEY, PROPERTY_VALUE).withPattern(ExchangePattern.InOut)
.build();
diff --git a/core/camel-core/src/test/java/org/apache/camel/catalog/RuntimeCamelCatalogTest.java b/core/camel-core/src/test/java/org/apache/camel/catalog/RuntimeCamelCatalogTest.java
index dc3f79fc9dc..bffba9d194c 100644
--- a/core/camel-core/src/test/java/org/apache/camel/catalog/RuntimeCamelCatalogTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/catalog/RuntimeCamelCatalogTest.java
@@ -23,6 +23,7 @@ import java.util.Objects;
import org.apache.camel.catalog.impl.DefaultRuntimeCamelCatalog;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.tooling.model.ComponentModel;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -40,6 +41,11 @@ public class RuntimeCamelCatalogTest {
catalog.setCamelContext(new DefaultCamelContext());
}
+ @AfterAll
+ public static void cleanCamelCatalog() {
+ catalog = null;
+ }
+
@Test
public void testAsEndpointUriMapFile() throws Exception {
Map<String, String> map = new HashMap<>();
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java
index 4000fe7664d..57f6dfc30fc 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/log/LogEndpointTest.java
@@ -27,6 +27,7 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spi.CamelLogger;
import org.apache.camel.spi.LogListener;
import org.apache.camel.support.processor.CamelLogProcessor;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -36,6 +37,11 @@ public class LogEndpointTest extends ContextTestSupport {
private static Exchange logged;
+ @AfterAll
+ public static void clean() {
+ logged = null;
+ }
+
private static class MyLogger extends CamelLogProcessor {
@Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/CamelProduceInterfaceEventNotifierTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/CamelProduceInterfaceEventNotifierTest.java
index 40a968e2117..0c2a21dcf73 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/CamelProduceInterfaceEventNotifierTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/CamelProduceInterfaceEventNotifierTest.java
@@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class CamelProduceInterfaceEventNotifierTest extends ContextTestSupport {
- private static List<CamelEvent> events = new ArrayList<>();
+ private final List<CamelEvent> events = new ArrayList<>();
private CamelBeanPostProcessor postProcessor;
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/CamelEventsTimestampEnabledTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/CamelEventsTimestampEnabledTest.java
index 248bc571327..a4cd3933cf7 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/CamelEventsTimestampEnabledTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/CamelEventsTimestampEnabledTest.java
@@ -27,19 +27,11 @@ import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.CamelEvent;
import org.apache.camel.support.EventNotifierSupport;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class CamelEventsTimestampEnabledTest extends ContextTestSupport {
- private static List<CamelEvent> events = new ArrayList<>();
-
- @Override
- @BeforeEach
- public void setUp() throws Exception {
- events.clear();
- super.setUp();
- }
+ private final List<CamelEvent> events = new ArrayList<>();
@Override
protected CamelContext createCamelContext() throws Exception {
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierEventsTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierEventsTest.java
index 616f17850a7..7cea0af763b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierEventsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierEventsTest.java
@@ -36,14 +36,13 @@ import static org.junit.jupiter.api.Assertions.*;
public class EventNotifierEventsTest {
- private static List<CamelEvent> events = new ArrayList<>();
+ private final List<CamelEvent> events = new ArrayList<>();
private CamelContext context;
private ProducerTemplate template;
@BeforeEach
public void setUp() throws Exception {
- events.clear();
context = createCamelContext();
context.addRoutes(createRouteBuilder());
template = context.createProducerTemplate();
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierExchangeCompletedTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierExchangeCompletedTest.java
index 8197969e0cf..e43d1adf263 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierExchangeCompletedTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierExchangeCompletedTest.java
@@ -26,21 +26,13 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.CamelEvent;
import org.apache.camel.support.EventNotifierSupport;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class EventNotifierExchangeCompletedTest extends ContextTestSupport {
- private static List<CamelEvent> events = new ArrayList<>();
-
- @Override
- @BeforeEach
- public void setUp() throws Exception {
- events.clear();
- super.setUp();
- }
+ private final List<CamelEvent> events = new ArrayList<>();
@Override
protected CamelContext createCamelContext() throws Exception {
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierExchangeSentTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierExchangeSentTest.java
index 3091692e740..223476d26b0 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierExchangeSentTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierExchangeSentTest.java
@@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class EventNotifierExchangeSentTest extends ContextTestSupport {
- protected List<CamelEvent> events = new ArrayList<>();
+ protected final List<CamelEvent> events = new ArrayList<>();
@BeforeEach
public void clearEvents() throws Exception {
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierFailureHandledEventsTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierFailureHandledEventsTest.java
index 4daa4956d97..c35553dbef3 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierFailureHandledEventsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierFailureHandledEventsTest.java
@@ -28,21 +28,13 @@ import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.processor.SendProcessor;
import org.apache.camel.spi.CamelEvent;
import org.apache.camel.support.EventNotifierSupport;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class EventNotifierFailureHandledEventsTest extends ContextTestSupport {
- private static List<CamelEvent> events = new ArrayList<>();
-
- @Override
- @BeforeEach
- public void setUp() throws Exception {
- events.clear();
- super.setUp();
- }
+ private final List<CamelEvent> events = new ArrayList<>();
@Override
public boolean isUseRouteBuilder() {
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierIgnoreCamelContextInitEventsTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierIgnoreCamelContextInitEventsTest.java
index f04ab8cf1d0..1cd8f1b98e9 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierIgnoreCamelContextInitEventsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierIgnoreCamelContextInitEventsTest.java
@@ -34,14 +34,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class EventNotifierIgnoreCamelContextInitEventsTest {
- private static List<CamelEvent> events = new ArrayList<>();
+ private final List<CamelEvent> events = new ArrayList<>();
private CamelContext context;
private ProducerTemplate template;
@BeforeEach
public void setUp() throws Exception {
- events.clear();
context = createCamelContext();
context.addRoutes(createRouteBuilder());
template = context.createProducerTemplate();
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierRedeliveryEventsTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierRedeliveryEventsTest.java
index 877664bdfd2..f6107dd1d46 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierRedeliveryEventsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierRedeliveryEventsTest.java
@@ -25,7 +25,6 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.CamelEvent;
import org.apache.camel.support.EventNotifierSupport;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,14 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class EventNotifierRedeliveryEventsTest extends ContextTestSupport {
- private static List<CamelEvent> events = new ArrayList<>();
-
- @Override
- @BeforeEach
- public void setUp() throws Exception {
- events.clear();
- super.setUp();
- }
+ private final List<CamelEvent> events = new ArrayList<>();
@Override
public boolean isUseRouteBuilder() {
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierServiceStoppingFailedEventTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierServiceStoppingFailedEventTest.java
index 14948b5b784..5a2a11ad946 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierServiceStoppingFailedEventTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/EventNotifierServiceStoppingFailedEventTest.java
@@ -24,22 +24,14 @@ import org.apache.camel.ContextTestSupport;
import org.apache.camel.Service;
import org.apache.camel.spi.CamelEvent;
import org.apache.camel.support.EventNotifierSupport;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class EventNotifierServiceStoppingFailedEventTest extends ContextTestSupport {
- private static List<CamelEvent> events = new ArrayList<>();
private static String stopOrder;
-
- @Override
- @BeforeEach
- public void setUp() throws Exception {
- events.clear();
- super.setUp();
- }
+ private final List<CamelEvent> events = new ArrayList<>();
@Override
protected CamelContext createCamelContext() throws Exception {
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/MultipleEventNotifierEventsTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/MultipleEventNotifierEventsTest.java
index b53eaf830d1..7ad5f8cc34d 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/MultipleEventNotifierEventsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/MultipleEventNotifierEventsTest.java
@@ -25,7 +25,6 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.CamelEvent;
import org.apache.camel.support.EventNotifierSupport;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,22 +32,14 @@ import static org.junit.jupiter.api.Assertions.fail;
public class MultipleEventNotifierEventsTest extends ContextTestSupport {
- private static List<CamelEvent> events = new ArrayList<>();
- private static List<CamelEvent> events2 = new ArrayList<>();
+ private final List<CamelEvent> events = new ArrayList<>();
+ private final List<CamelEvent> events2 = new ArrayList<>();
@Override
protected boolean useJmx() {
return true;
}
- @Override
- @BeforeEach
- public void setUp() throws Exception {
- events.clear();
- events2.clear();
- super.setUp();
- }
-
@Override
protected CamelContext createCamelContext() throws Exception {
DefaultCamelContext context = new DefaultCamelContext(createRegistry());
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/event/SimpleEventNotifierEventsTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/event/SimpleEventNotifierEventsTest.java
index ce174d386ba..14dd994018a 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/event/SimpleEventNotifierEventsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/event/SimpleEventNotifierEventsTest.java
@@ -36,14 +36,13 @@ import static org.junit.jupiter.api.Assertions.*;
public class SimpleEventNotifierEventsTest {
- private static List<CamelEvent> events = new ArrayList<>();
+ private final List<CamelEvent> events = new ArrayList<>();
private CamelContext context;
private ProducerTemplate template;
@BeforeEach
public void setUp() throws Exception {
- events.clear();
context = createCamelContext();
context.addRoutes(createRouteBuilder());
template = context.createProducerTemplate();
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/NavigateRouteTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/NavigateRouteTest.java
index 9adc2638950..417c9026a10 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/NavigateRouteTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/NavigateRouteTest.java
@@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
*/
public class NavigateRouteTest extends ContextTestSupport {
- private static List<Processor> processors = new ArrayList<>();
+ private final List<Processor> processors = new ArrayList<>();
@Test
public void testNavigateRoute() throws Exception {
diff --git a/core/camel-core/src/test/resources/log4j2.properties b/core/camel-core/src/test/resources/log4j2.properties
index 6c2228a570d..eda60d47650 100644
--- a/core/camel-core/src/test/resources/log4j2.properties
+++ b/core/camel-core/src/test/resources/log4j2.properties
@@ -37,16 +37,16 @@ appender.file2.layout.type = PatternLayout
appender.file2.layout.pattern = %-5p %c{1} %m%n
logger.customlogger.name = org.apache.camel.customlogger
-logger.customlogger.level = TRACE
+logger.customlogger.level = INFO
logger.customlogger.appenderRef.file2.ref = file2
logger.file-cluster.name = org.apache.camel.component.file.cluster
-logger.file-cluster.level = DEBUG
+logger.file-cluster.level = INFO
-rootLogger.level = DEBUG
+rootLogger.level = INFO
rootLogger.appenderRef.file.ref = file
#rootLogger.appenderRef.console.ref = console
#logger.camel-core.name = org.apache.camel
-#logger.camel-core.level = TRACE
+#logger.camel-core.level = INFO
diff --git a/core/camel-support/src/main/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicy.java b/core/camel-support/src/main/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicy.java
index fc6a312d48b..94a59b00fb6 100644
--- a/core/camel-support/src/main/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/throttling/ThrottlingExceptionRoutePolicy.java
@@ -114,6 +114,15 @@ public class ThrottlingExceptionRoutePolicy extends RoutePolicySupport implement
}
}
+ @Override
+ protected void doStop() throws Exception {
+ Timer timer = halfOpenTimer;
+ if (timer != null) {
+ timer.cancel();
+ halfOpenTimer = null;
+ }
+ }
+
@Override
public void onExchangeDone(Route route, Exchange exchange) {
if (keepOpen.get()) {