essobedo commented on code in PR #11307:
URL: https://github.com/apache/camel/pull/11307#discussion_r1317229845


##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/link/BindyRaceConditionLinkTest.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+
+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 org.junit.jupiter.api.Assertions.assertEquals;
+
+/** Test for CAMEL-19833 **/
+public class BindyRaceConditionLinkTest extends CamelTestSupport {
+
+    String SOURCE_CSV_FILE_PATH = 
"org/apache/camel/dataformat/bindy/fixed/link/bindyRaceConditionLinkTest.csv";
+
+    @RepeatedTest(3)
+    public void raceConditionTest() throws Exception {
+
+        Path filePath = 
Path.of(ClassLoader.getSystemResource(SOURCE_CSV_FILE_PATH).toURI());
+        String csv = Files.readString(filePath);
+        template.requestBody("direct:bindy-link-test", csv);
+
+        MockEndpoint end = getMockEndpoint("mock:end");
+        MockEndpoint fail = getMockEndpoint("mock:fail");
+        fail.expectedMessageCount(0);
+        fail.assertIsSatisfied(5000);
+        assertEquals(0, end.getFailures().size());
+        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(
+                        10,
+                        10,
+                        15,
+                        TimeUnit.SECONDS,
+                        new ArrayBlockingQueue<>(11000));
+
+                
onException(UnsupportedOperationException.class).to("mock:fail");
+
+                from("direct:bindy-link-test")
+                        .routeId("bindy-link-test")
+                        .convertBodyTo(String.class)
+                        .split(body().tokenize("\\n"))
+                        .parallelProcessing(true)
+                        .executorService(executorService)
+                        .log("will unmarshal")

Review Comment:
   Let's remove the log messages that slow down the test and pollute the log 
file



##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/link/BindyRaceConditionLinkTest.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+
+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 org.junit.jupiter.api.Assertions.assertEquals;
+
+/** Test for CAMEL-19833 **/
+public class BindyRaceConditionLinkTest extends CamelTestSupport {
+
+    String SOURCE_CSV_FILE_PATH = 
"org/apache/camel/dataformat/bindy/fixed/link/bindyRaceConditionLinkTest.csv";

Review Comment:
   Should be `static final`



##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fixed/link/MyModel.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.model.fixed.link;
+
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.Link;
+
+@CsvRecord(separator = ",", skipField = true)
+public class MyModel {

Review Comment:
   Could you please tell me why we need many fields to reproduce? I insist on 
that because adding big files to a github project tends to slow down different 
git commands so it should be done only when really needed.



##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/link/BindyRaceConditionLinkTest.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+
+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 org.junit.jupiter.api.Assertions.assertEquals;
+
+/** Test for CAMEL-19833 **/
+public class BindyRaceConditionLinkTest extends CamelTestSupport {
+
+    String SOURCE_CSV_FILE_PATH = 
"org/apache/camel/dataformat/bindy/fixed/link/bindyRaceConditionLinkTest.csv";
+
+    @RepeatedTest(3)
+    public void raceConditionTest() throws Exception {
+
+        Path filePath = 
Path.of(ClassLoader.getSystemResource(SOURCE_CSV_FILE_PATH).toURI());
+        String csv = Files.readString(filePath);
+        template.requestBody("direct:bindy-link-test", csv);
+
+        MockEndpoint end = getMockEndpoint("mock:end");
+        MockEndpoint fail = getMockEndpoint("mock:fail");
+        fail.expectedMessageCount(0);
+        fail.assertIsSatisfied(5000);
+        assertEquals(0, end.getFailures().size());
+        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(
+                        10,
+                        10,
+                        15,
+                        TimeUnit.SECONDS,
+                        new ArrayBlockingQueue<>(11000));
+
+                
onException(UnsupportedOperationException.class).to("mock:fail");
+
+                from("direct:bindy-link-test")
+                        .routeId("bindy-link-test")
+                        .convertBodyTo(String.class)
+                        .split(body().tokenize("\\n"))

Review Comment:
   Why do we need 2 backslashes?



##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/link/BindyRaceConditionLinkTest.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+
+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 org.junit.jupiter.api.Assertions.assertEquals;
+
+/** Test for CAMEL-19833 **/
+public class BindyRaceConditionLinkTest extends CamelTestSupport {
+
+    String SOURCE_CSV_FILE_PATH = 
"org/apache/camel/dataformat/bindy/fixed/link/bindyRaceConditionLinkTest.csv";
+
+    @RepeatedTest(3)
+    public void raceConditionTest() throws Exception {
+
+        Path filePath = 
Path.of(ClassLoader.getSystemResource(SOURCE_CSV_FILE_PATH).toURI());
+        String csv = Files.readString(filePath);
+        template.requestBody("direct:bindy-link-test", csv);
+
+        MockEndpoint end = getMockEndpoint("mock:end");
+        MockEndpoint fail = getMockEndpoint("mock:fail");
+        fail.expectedMessageCount(0);

Review Comment:
   This makes me wonder if the test is properly written because if you expect 
no message, the condition is already met even before starting the Camel route. 
You should rather expect that `mock:end` receives all the messages. I think 
that MockEndpoint should not be needed



-- 
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

Reply via email to