You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/01/31 10:30:46 UTC
[camel] branch main updated: (chores) camel-ftp: cleanup FromFileToFtpSplitParallelIT
This is an automated email from the ASF dual-hosted git repository.
orpiske 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 5c5e7fce519 (chores) camel-ftp: cleanup FromFileToFtpSplitParallelIT
5c5e7fce519 is described below
commit 5c5e7fce519c78da9d94e07246b300ff0bf3bb75
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Jan 31 09:18:06 2023 +0100
(chores) camel-ftp: cleanup FromFileToFtpSplitParallelIT
- prevent running on nodes without enough resources
- size the pool to the number of available processors
---
.../integration/FromFileToFtpSplitParallelIT.java | 46 +++++++++++++++++-----
1 file changed, 36 insertions(+), 10 deletions(-)
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpSplitParallelIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpSplitParallelIT.java
index ce7e82aff71..e3561dd5e97 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpSplitParallelIT.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFileToFtpSplitParallelIT.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.file.remote.integration;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@@ -26,14 +27,22 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.builder.ThreadPoolProfileBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spi.ThreadPoolProfile;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@Tag("not-parallel")
class FromFileToFtpSplitParallelIT extends FtpServerTestSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(FromFileToFtpSplitParallelIT.class);
private static final int SIZE = 5_000;
+ private static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();
@TempDir
Path testDirectory;
@@ -44,6 +53,21 @@ class FromFileToFtpSplitParallelIT extends FtpServerTestSupport {
@Test
void testSplit() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.setResultWaitTime(TimeUnit.MINUTES.toMillis(5));
+
+ assertDoesNotThrow(() -> context.getRouteController().startAllRoutes(),
+ "The split parallel route should start without exceptions");
+
+ mock.assertIsSatisfied();
+ }
+
+ @BeforeEach
+ public void createBigFile() throws FileNotFoundException {
+ Assumptions.assumeTrue(AVAILABLE_PROCESSORS > 1,
+ "Skipping test because this system may not have enough resources to run it");
+
// create big file
try (PrintWriter writer = new PrintWriter(
new FileOutputStream(testDirectory.toString() + "/bigdata.txt"), true, StandardCharsets.UTF_8)) {
@@ -51,27 +75,29 @@ class FromFileToFtpSplitParallelIT extends FtpServerTestSupport {
writer.printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ%d%n", i);
}
}
-
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMessageCount(1);
-
- context.getRouteController().startAllRoutes();
-
- mock.setResultWaitTime(TimeUnit.MINUTES.toMillis(5));
- mock.assertIsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
+ final int poolSize = AVAILABLE_PROCESSORS / 2;
+
+ LOG.info(
+ "Setting up the max pool size to the number of available processors: {}. Pool size will be set to half of that: {}",
+ AVAILABLE_PROCESSORS, poolSize);
+
ThreadPoolProfile tpp
- = new ThreadPoolProfileBuilder("ftp-pool").poolSize(5).maxPoolSize(10).maxQueueSize(1_000).build();
+ = new ThreadPoolProfileBuilder("ftp-pool")
+ .poolSize(poolSize)
+ .maxPoolSize(AVAILABLE_PROCESSORS)
+ .maxQueueSize(1_000)
+ .build();
context.getExecutorServiceManager().registerThreadPoolProfile(tpp);
onException().maximumRedeliveries(5).redeliveryDelay(1_000);
- from(String.format("file:%s", testDirectory)).noAutoStartup().routeId("foo")
+ fromF("file:%s", testDirectory).noAutoStartup().routeId("foo")
.split(body().tokenize("\n")).executorService("ftp-pool")
.to(getFtpUrl())
.to("log:line?groupSize=100")