apupier commented on code in PR #25265:
URL: https://github.com/apache/camel/pull/25265#discussion_r3688636605


##########
components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletVirtualThreadsRouteCreationTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.component.kamelet;
+
+import java.lang.reflect.Field;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+import org.apache.camel.util.concurrent.ThreadType;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import org.junit.jupiter.api.parallel.Isolated;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+/**
+ * CAMEL-24320: Kamelet route creation must not NPE when virtual threads are 
enabled on JDK 25+.
+ * <p>
+ * Virtual threads must be selected before the first {@code ContextValue} is 
created; the system property is set in
+ * a static initializer so {@code ContextValueFactory} picks the ScopedValue 
backend when this class loads first in an
+ * isolated fork. {@link 
org.apache.camel.util.concurrent.ScopedValueContextValueOrElseTest} is the 
primary unit guard.
+ */
+@Isolated
+@EnabledForJreRange(min = JRE.JAVA_25)
+class KameletVirtualThreadsRouteCreationTest {
+
+    static {
+        System.setProperty("camel.threads.virtual.enabled", "true");
+    }
+
+    @AfterEach
+    void resetThreadType() throws Exception {
+        Field field = ThreadType.class.getDeclaredField("current");
+        field.setAccessible(true);
+        field.set(null, null);
+        System.clearProperty("camel.threads.virtual.enabled");
+    }

Review Comment:
   need to look for the value of the property before the test and reset it to 
thsi value after



##########
components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletVirtualThreadsRouteCreationTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.component.kamelet;
+
+import java.lang.reflect.Field;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+import org.apache.camel.util.concurrent.ThreadType;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import org.junit.jupiter.api.parallel.Isolated;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+/**
+ * CAMEL-24320: Kamelet route creation must not NPE when virtual threads are 
enabled on JDK 25+.
+ * <p>
+ * Virtual threads must be selected before the first {@code ContextValue} is 
created; the system property is set in
+ * a static initializer so {@code ContextValueFactory} picks the ScopedValue 
backend when this class loads first in an
+ * isolated fork. {@link 
org.apache.camel.util.concurrent.ScopedValueContextValueOrElseTest} is the 
primary unit guard.
+ */
+@Isolated
+@EnabledForJreRange(min = JRE.JAVA_25)
+class KameletVirtualThreadsRouteCreationTest {

Review Comment:
   I think we should add a Resource lock like here 
https://github.com/apache/camel/blob/0e101544096baf1c734354718e3b2066722fd88b/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java#L28
   
   and maybe no need of @Isolated in this case



##########
components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletVirtualThreadsRouteCreationTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.component.kamelet;
+
+import java.lang.reflect.Field;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.main.Main;
+import org.apache.camel.util.concurrent.ThreadType;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import org.junit.jupiter.api.parallel.Isolated;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+/**
+ * CAMEL-24320: Kamelet route creation must not NPE when virtual threads are 
enabled on JDK 25+.
+ * <p>
+ * Virtual threads must be selected before the first {@code ContextValue} is 
created; the system property is set in
+ * a static initializer so {@code ContextValueFactory} picks the ScopedValue 
backend when this class loads first in an
+ * isolated fork. {@link 
org.apache.camel.util.concurrent.ScopedValueContextValueOrElseTest} is the 
primary unit guard.
+ */
+@Isolated
+@EnabledForJreRange(min = JRE.JAVA_25)
+class KameletVirtualThreadsRouteCreationTest {
+
+    static {
+        System.setProperty("camel.threads.virtual.enabled", "true");
+    }
+
+    @AfterEach
+    void resetThreadType() throws Exception {
+        Field field = ThreadType.class.getDeclaredField("current");
+        field.setAccessible(true);
+        field.set(null, null);
+        System.clearProperty("camel.threads.virtual.enabled");
+    }
+
+    @Test
+    void mainStartsKameletRouteWithVirtualThreadsEnabled() {
+        assertThatCode(() -> {
+            Main main = new Main();
+            
main.configure().withVirtualThreadsEnabled(true).addRoutesBuilder(new 
RouteBuilder() {
+                @Override
+                public void configure() {
+                    
from("kamelet:vt-repro-source").routeId("vt-kamelet-repro").to("mock:vt-out");
+                }
+            });
+            main.start();
+            
assertThat(main.getCamelContext().getRoute("vt-kamelet-repro")).isNotNull();
+            main.stop();
+        }).doesNotThrowAnyException();

Review Comment:
   there is already an assertion in the test, not sure it is necessary to use 
doesNotThorwAnyException. If an exception is thrown, it will be reorted as an 
error already by the test



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to