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


##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/link/BindyRaceConditionLinkTest.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Stream;
+
+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 org.junit.jupiter.api.io.TempDir;
+
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/** Test for CAMEL-19833 **/
+public class BindyRaceConditionLinkTest extends CamelTestSupport {
+
+    @TempDir
+    Path tempDir;
+
+    String SOURCE_DIRECTORY_PATH = 
"org/apache/camel/dataformat/bindy/fixed/link";
+
+    @RepeatedTest(3)
+    public void raceConditionTest() throws Exception {
+        copyFiles();
+        MockEndpoint end = getMockEndpoint("mock:end");
+        MockEndpoint fail = getMockEndpoint("mock:fail");
+        end.expectedMessageCount(10);
+        fail.expectedMessageCount(0);
+        end.assertIsSatisfied(5000);
+        fail.assertIsSatisfied(5000);
+        assertEquals(0, end.getFailures().size());
+        end.reset();
+        fail.reset();
+    }
+
+    private void copyFiles() throws IOException, URISyntaxException {
+        try (Stream<Path> stream = 
Files.list(Path.of(ClassLoader.getSystemResource(SOURCE_DIRECTORY_PATH).toURI())))
 {
+            List<Path> paths = stream.filter(path -> 
path.toString().endsWith(".csv")).toList();
+            for (Path source : paths) {
+                Path destination = Paths.get(tempDir.toString() + 
File.separator + source.getFileName());
+                Files.copy(source, destination, REPLACE_EXISTING);
+            }
+        }
+    }
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return true;
+    }

Review Comment:
   Do we really need it? I think it is the default value



##########
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/link/BindyRaceConditionLinkTest.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Stream;
+
+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 org.junit.jupiter.api.io.TempDir;
+
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/** Test for CAMEL-19833 **/
+public class BindyRaceConditionLinkTest extends CamelTestSupport {
+
+    @TempDir
+    Path tempDir;
+
+    String SOURCE_DIRECTORY_PATH = 
"org/apache/camel/dataformat/bindy/fixed/link";
+
+    @RepeatedTest(3)
+    public void raceConditionTest() throws Exception {
+        copyFiles();
+        MockEndpoint end = getMockEndpoint("mock:end");
+        MockEndpoint fail = getMockEndpoint("mock:fail");
+        end.expectedMessageCount(10);
+        fail.expectedMessageCount(0);
+        end.assertIsSatisfied(5000);
+        fail.assertIsSatisfied(5000);
+        assertEquals(0, end.getFailures().size());
+        end.reset();
+        fail.reset();
+    }
+
+    private void copyFiles() throws IOException, URISyntaxException {
+        try (Stream<Path> stream = 
Files.list(Path.of(ClassLoader.getSystemResource(SOURCE_DIRECTORY_PATH).toURI())))
 {
+            List<Path> paths = stream.filter(path -> 
path.toString().endsWith(".csv")).toList();
+            for (Path source : paths) {
+                Path destination = Paths.get(tempDir.toString() + 
File.separator + source.getFileName());
+                Files.copy(source, destination, REPLACE_EXISTING);
+            }
+        }

Review Comment:
   Do we really need 10 big CSV files to reproduce? Maybe we could have only 
one file, split it into lines then parallelize the processing with 
`.split(body()).delimiter("\n").parallelProcessing()`, WDYT?



##########
core/camel-util/src/main/java/org/apache/camel/util/ReflectionHelper.java:
##########
@@ -179,20 +179,10 @@ public static Method findMethod(Class<?> clazz, String 
name, Class<?>... paramTy
 
     public static void setField(Field f, Object instance, Object value) {
         try {
-            boolean oldAccessible = false;
-            try {
-                oldAccessible = f.canAccess(instance);
-            } catch (Exception e) {
-                // ignore
-            }
-            boolean shouldSetAccessible = !Modifier.isPublic(f.getModifiers()) 
&& !oldAccessible;
-            if (shouldSetAccessible) {
+            if (!Modifier.isPublic(f.getModifiers()) && 
!f.canAccess(instance)) {

Review Comment:
   Yes, that sounds better. Maybe, we could do the same with `getField`, don't 
you agree?



##########
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:
   To increase the chance of collision, maybe we should only have one single 
private field instead of many different fields, don't you agree?



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