essobedo commented on code in PR #11307: URL: https://github.com/apache/camel/pull/11307#discussion_r1318438857
########## components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/link/BindyRaceConditionLinkTest.java: ########## @@ -0,0 +1,100 @@ +/* + * 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.camel.dataformat.bindy.fixed.link; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadPoolExecutor; + +import org.apache.camel.Endpoint; +import org.apache.camel.EndpointInject; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat; +import org.apache.camel.dataformat.bindy.model.fixed.link.MyModel; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.RepeatedTest; + +import static java.util.concurrent.TimeUnit.SECONDS; + +/** Test for CAMEL-19833 **/ +public class BindyRaceConditionLinkTest extends CamelTestSupport { + + private static final String SOURCE_CSV_FILE_PATH + = "org/apache/camel/dataformat/bindy/fixed/link/bindyRaceConditionLinkTest.csv"; + + private static final int EXPECTED_SUCCESSFUL_MESSAGE_COUNT = 1500; + private static final int EXPECTED_FAILED_MESSAGE_COUNT = 0; + private static final long WAIT_TIMEOUT = 5; + private static final int THREAD_POOL_CORE_SIZE = 10; + private static final int THREAD_POOL_MAX_SIZE = 10; + private static final int THREAD_POOL_KEEP_ALIVE_TIME = 15; + private static final int THREAD_POOL_QUEUE_SIZE = 2000; + + @EndpointInject("mock:fail") + private MockEndpoint fail; + + @EndpointInject("mock:end") + private MockEndpoint end; + + @EndpointInject("direct:bindy-link-test") + private Endpoint begin; + + @RepeatedTest(3) + public void raceConditionTest() throws Exception { + Path filePath = Path.of(ClassLoader.getSystemResource(SOURCE_CSV_FILE_PATH).toURI()); + String csv = Files.readString(filePath); + template.sendBody(begin, csv); + fail.expectedMessageCount(EXPECTED_FAILED_MESSAGE_COUNT); + end.expectedMessageCount(EXPECTED_SUCCESSFUL_MESSAGE_COUNT); + MockEndpoint.assertIsSatisfied(context, WAIT_TIMEOUT, SECONDS); + end.reset(); + fail.reset(); + } + + @Override + public RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + BindyCsvDataFormat bindy = new BindyCsvDataFormat(MyModel.class); + + ExecutorService executorService = new ThreadPoolExecutor( + THREAD_POOL_CORE_SIZE, + THREAD_POOL_MAX_SIZE, + THREAD_POOL_KEEP_ALIVE_TIME, + SECONDS, + new ArrayBlockingQueue<>(THREAD_POOL_QUEUE_SIZE)); Review Comment: Did you check if your test fails without your custom `ExecutorService` and the bug fix? If you really need it make sure that it is shutdown properly at the end of the test to free up the memory. I can't remember if it is already done out of the box by Camel. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org