This is an automated email from the ASF dual-hosted git repository.

davsclaus 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 cb1edb01aee3 CAMEL-27605: camel-infinispan-embedded - trim eventTypes, 
warn about unused event types and endpoint options (#30993)
cb1edb01aee3 is described below

commit cb1edb01aee3dbb9f82553dd137099297661fbf5
Author: allthingssecurity <[email protected]>
AuthorDate: Fri Nov 27 22:16:08 2026 +0530

    CAMEL-27605: camel-infinispan-embedded - trim eventTypes, warn about unused 
event types and endpoint options (#30993)
    
    1. eventTypes accepted all 16 Event.Type names, but the listener of the
       consumer (InfinispanEmbeddedEventListener) only has callbacks for 9 of
       them, so with TOPOLOGY_CHANGED, CACHE_ENTRY_EVICTED, the TRANSACTION_*,
       DATA_REHASHED, PARTITION_STATUS_CHANGED or
       PERSISTENCE_AVAILABILITY_CHANGED the route started and never received
       those events, without a log. The consumer now logs a WARN at start that
       names the types it never receives and the ones it does. It still starts,
       so a route that lists such a type next to a received one keeps working.
       The names are now trimmed, so "CACHE_ENTRY_CREATED, CACHE_ENTRY_REMOVED"
       no longer fails the start, and empty names are skipped.
    
    2. cacheContainer, cacheContainerConfiguration, configurationUri and flags
       set on an endpoint are not used: every endpoint uses the one cache
       manager of the component, created from the configuration of the
       component, and its flags. The doc page already says so; the endpoint now
       also logs a WARN that names the options whose value differs from the one
       of the component. The options are kept on the endpoint (no change to the
       Endpoint DSL).
    
    Not changed:
    3. CamelInfinispanOldValue keeps label producer. The constant is shared
       with the infinispan (remote) component, whose consumer does not set it,
       so label common would be wrong there; the descriptions pull request for
       CAMEL-23832 (#30944) says in the description that the embedded consumer
       sets it for CACHE_ENTRY_REMOVED.
    4. CamelInfinispanCurrentState stays. Making it useful needs listener
       variants with includeCurrentState=true and the header set for
       CACHE_ENTRY_CREATED events (how Infinispan delivers the existing 
entries),
       which is a new feature; removing its metadata would remove a generated
       Endpoint DSL header method. #30944 describes when it is true.
    
    The doc page (and its catalog copy) says that the endpoint logs a WARN for
    the component-only options.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../docs/infinispan-embedded-component.adoc        |   4 +-
 .../main/docs/infinispan-embedded-component.adoc   |   4 +-
 .../embedded/InfinispanEmbeddedComponent.java      |  35 ++++++
 .../embedded/InfinispanEmbeddedConsumer.java       |  17 ++-
 .../embedded/InfinispanEmbeddedEventListener.java  |  15 +++
 ...anEmbeddedEventTypesAndEndpointOptionsTest.java | 126 +++++++++++++++++++++
 6 files changed, 196 insertions(+), 5 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/infinispan-embedded-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/infinispan-embedded-component.adoc
index cd7182b7d53b..f7bd50149426 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/infinispan-embedded-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/infinispan-embedded-component.adoc
@@ -55,8 +55,8 @@ If no cache configuration is provided, embedded 
cacheContainer is created direct
 
 All the endpoints of the component share one cache manager, which the 
component creates when it starts. So the
 options that configure the cache manager are read on the component only: 
`configurationUri`, `cacheContainer`,
-`cacheContainerConfiguration` and `flags`. Set on an endpoint, these options 
are not used. Configure them on the
-component instead, for example in `application.properties`:
+`cacheContainerConfiguration` and `flags`. Set on an endpoint, these options 
are not used, and the endpoint logs a
+WARN that names them. Configure them on the component instead, for example in 
`application.properties`:
 
 [source,properties]
 ----
diff --git 
a/components/camel-infinispan/camel-infinispan-embedded/src/main/docs/infinispan-embedded-component.adoc
 
b/components/camel-infinispan/camel-infinispan-embedded/src/main/docs/infinispan-embedded-component.adoc
index cd7182b7d53b..f7bd50149426 100644
--- 
a/components/camel-infinispan/camel-infinispan-embedded/src/main/docs/infinispan-embedded-component.adoc
+++ 
b/components/camel-infinispan/camel-infinispan-embedded/src/main/docs/infinispan-embedded-component.adoc
@@ -55,8 +55,8 @@ If no cache configuration is provided, embedded 
cacheContainer is created direct
 
 All the endpoints of the component share one cache manager, which the 
component creates when it starts. So the
 options that configure the cache manager are read on the component only: 
`configurationUri`, `cacheContainer`,
-`cacheContainerConfiguration` and `flags`. Set on an endpoint, these options 
are not used. Configure them on the
-component instead, for example in `application.properties`:
+`cacheContainerConfiguration` and `flags`. Set on an endpoint, these options 
are not used, and the endpoint logs a
+WARN that names them. Configure them on the component instead, for example in 
`application.properties`:
 
 [source,properties]
 ----
diff --git 
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedComponent.java
 
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedComponent.java
index d7a6dc117775..b671affc1c28 100644
--- 
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedComponent.java
+++ 
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedComponent.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.component.infinispan.embedded;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
@@ -24,11 +28,16 @@ import 
org.apache.camel.component.infinispan.InfinispanComponent;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.service.ServiceHelper;
+import org.apache.camel.util.URISupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @Component(InfinispanEmbeddedComponent.SCHEME)
 public class InfinispanEmbeddedComponent extends InfinispanComponent {
     public static final String SCHEME = "infinispan-embedded";
 
+    private static final Logger LOG = 
LoggerFactory.getLogger(InfinispanEmbeddedComponent.class);
+
     @Metadata(description = "The configuration of the component, which each 
endpoint copies and then changes with its own"
                             + " options. The cache manager of the component 
uses only this configuration.")
     private InfinispanEmbeddedConfiguration configuration = new 
InfinispanEmbeddedConfiguration();
@@ -48,9 +57,35 @@ public class InfinispanEmbeddedComponent extends 
InfinispanComponent {
 
         InfinispanEmbeddedEndpoint endpoint = new 
InfinispanEmbeddedEndpoint(uri, remaining, this, conf);
         setProperties(endpoint, parameters);
+        warnAboutIgnoredOptions(uri, conf);
         return endpoint;
     }
 
+    /**
+     * All the endpoints use the one cache manager of the component, which is 
created from the configuration of the
+     * component, and its flags. The values of the endpoint for these options 
are not used.
+     */
+    private void warnAboutIgnoredOptions(String uri, 
InfinispanEmbeddedConfiguration conf) {
+        List<String> ignored = new ArrayList<>();
+        if (conf.getCacheContainer() != configuration.getCacheContainer()) {
+            ignored.add("cacheContainer");
+        }
+        if (conf.getCacheContainerConfiguration() != 
configuration.getCacheContainerConfiguration()) {
+            ignored.add("cacheContainerConfiguration");
+        }
+        if (!Objects.equals(conf.getConfigurationUri(), 
configuration.getConfigurationUri())) {
+            ignored.add("configurationUri");
+        }
+        if (!Arrays.equals(conf.getFlags(), configuration.getFlags())) {
+            ignored.add("flags");
+        }
+        if (!ignored.isEmpty()) {
+            LOG.warn("The options {} of endpoint {} are not used: every 
infinispan-embedded endpoint uses the cache"
+                     + " manager and the flags of the component. Set them on 
the component instead.",
+                    ignored, URISupport.sanitizeUri(uri));
+        }
+    }
+
     @Override
     protected void doInit() throws Exception {
         super.doInit();
diff --git 
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedConsumer.java
 
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedConsumer.java
index c4550f65fe2b..6c6a661ec18e 100644
--- 
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedConsumer.java
+++ 
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedConsumer.java
@@ -33,10 +33,14 @@ import 
org.infinispan.commons.api.query.ContinuousQueryListener;
 import org.infinispan.commons.api.query.Query;
 import org.infinispan.manager.EmbeddedCacheManager;
 import org.infinispan.notifications.cachelistener.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class InfinispanEmbeddedConsumer
         extends InfinispanConsumer<EmbeddedCacheManager, 
InfinispanEmbeddedManager, InfinispanEmbeddedConfiguration> {
 
+    private static final Logger LOG = 
LoggerFactory.getLogger(InfinispanEmbeddedConsumer.class);
+
     private Service handler;
 
     public InfinispanEmbeddedConsumer(InfinispanEndpoint endpoint,
@@ -126,9 +130,20 @@ public class InfinispanEmbeddedConsumer
                 if (configuration.getEventTypes() != null) {
                     String eventTypes = configuration.getEventTypes();
                     for (String event : eventTypes.split(",")) {
-                        events.add(Event.Type.valueOf(event));
+                        String name = event.trim();
+                        if (!name.isEmpty()) {
+                            events.add(Event.Type.valueOf(name));
+                        }
                     }
                 }
+                Set<Event.Type> notReceived = EnumSet.noneOf(Event.Type.class);
+                notReceived.addAll(events);
+                
notReceived.removeAll(InfinispanEmbeddedEventListener.RECEIVED_EVENT_TYPES);
+                if (!notReceived.isEmpty()) {
+                    LOG.warn("The consumer of cache {} never receives the 
event types {} of the eventTypes option: its"
+                             + " listener only receives {}. Use a 
customListener for other event types.",
+                            cache.getName(), notReceived, 
InfinispanEmbeddedEventListener.RECEIVED_EVENT_TYPES);
+                }
 
                 if (configuration.isClusteredListener()) {
                     listener = configuration.isSync()
diff --git 
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedEventListener.java
 
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedEventListener.java
index 706d9e585ff5..fed4c4eb6620 100644
--- 
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedEventListener.java
+++ 
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedEventListener.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.infinispan.embedded;
 
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.Set;
 
 import org.apache.camel.component.infinispan.InfinispanConstants;
@@ -42,6 +43,20 @@ import 
org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent;
 import org.infinispan.notifications.cachelistener.event.Event;
 
 public abstract class InfinispanEmbeddedEventListener extends 
InfinispanEventListener<Event.Type> {
+    /**
+     * The event types this listener has a callback for. Infinispan does not 
deliver the other event types to it.
+     */
+    static final Set<Event.Type> RECEIVED_EVENT_TYPES = 
Collections.unmodifiableSet(EnumSet.of(
+            Event.Type.CACHE_ENTRY_ACTIVATED,
+            Event.Type.CACHE_ENTRY_CREATED,
+            Event.Type.CACHE_ENTRY_EXPIRED,
+            Event.Type.CACHE_ENTRY_INVALIDATED,
+            Event.Type.CACHE_ENTRY_LOADED,
+            Event.Type.CACHE_ENTRY_MODIFIED,
+            Event.Type.CACHE_ENTRY_PASSIVATED,
+            Event.Type.CACHE_ENTRY_REMOVED,
+            Event.Type.CACHE_ENTRY_VISITED));
+
     protected InfinispanEmbeddedEventListener() {
         super(Collections.emptySet());
     }
diff --git 
a/components/camel-infinispan/camel-infinispan-embedded/src/test/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedEventTypesAndEndpointOptionsTest.java
 
b/components/camel-infinispan/camel-infinispan-embedded/src/test/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedEventTypesAndEndpointOptionsTest.java
new file mode 100644
index 000000000000..d23961bc458b
--- /dev/null
+++ 
b/components/camel-infinispan/camel-infinispan-embedded/src/test/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedEventTypesAndEndpointOptionsTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.infinispan.embedded;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.infinispan.InfinispanConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Property;
+import org.infinispan.commons.api.BasicCache;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The eventTypes option of the consumer, and the endpoint options that only 
the component uses. Runs with the default
+ * embedded cache manager of the component, in this JVM.
+ */
+public class InfinispanEmbeddedEventTypesAndEndpointOptionsTest {
+
+    private final List<String> warnings = new CopyOnWriteArrayList<>();
+    private final AbstractAppender appender
+            = new AbstractAppender("InfinispanEmbeddedWarnings", null, null, 
true, Property.EMPTY_ARRAY) {
+                @Override
+                public void append(LogEvent event) {
+                    if (event.getLevel() == Level.WARN) {
+                        warnings.add(event.getMessage().getFormattedMessage());
+                    }
+                }
+            };
+    private CamelContext context;
+
+    @BeforeEach
+    void setUp() {
+        appender.start();
+        ((Logger) 
LogManager.getLogger(InfinispanEmbeddedConsumer.class)).addAppender(appender);
+        ((Logger) 
LogManager.getLogger(InfinispanEmbeddedComponent.class)).addAppender(appender);
+        context = new DefaultCamelContext();
+    }
+
+    @AfterEach
+    void tearDown() {
+        context.stop();
+        ((Logger) 
LogManager.getLogger(InfinispanEmbeddedConsumer.class)).removeAppender(appender);
+        ((Logger) 
LogManager.getLogger(InfinispanEmbeddedComponent.class)).removeAppender(appender);
+        appender.stop();
+    }
+
+    private void consume(String uri) throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from(uri).to("mock:events");
+            }
+        });
+        context.start();
+    }
+
+    private BasicCache<Object, Object> cache() {
+        return context.getComponent(InfinispanEmbeddedComponent.SCHEME, 
InfinispanEmbeddedComponent.class)
+                .getManager().getCache("default");
+    }
+
+    private boolean warned(String... parts) {
+        return warnings.stream().anyMatch(message -> 
List.of(parts).stream().allMatch(message::contains));
+    }
+
+    @Test
+    public void testEventTypesWithSpaces() throws Exception {
+        
consume("infinispan-embedded:default?sync=true&eventTypes=CACHE_ENTRY_CREATED, 
CACHE_ENTRY_REMOVED");
+
+        MockEndpoint mock = context.getEndpoint("mock:events", 
MockEndpoint.class);
+        
mock.expectedHeaderValuesReceivedInAnyOrder(InfinispanConstants.EVENT_TYPE,
+                "CACHE_ENTRY_CREATED", "CACHE_ENTRY_CREATED", 
"CACHE_ENTRY_REMOVED", "CACHE_ENTRY_REMOVED");
+
+        cache().put("key", "value");
+        cache().remove("key");
+
+        mock.assertIsSatisfied();
+    }
+
+    @Test
+    public void testEventTypeThatTheListenerNeverReceivesIsLogged() throws 
Exception {
+        
consume("infinispan-embedded:default?eventTypes=CACHE_ENTRY_CREATED,TOPOLOGY_CHANGED");
+
+        assertTrue(warned("TOPOLOGY_CHANGED", "never receives"), "warnings: " 
+ warnings);
+        assertTrue(warnings.stream().noneMatch(message -> 
message.contains("[CACHE_ENTRY_CREATED]")),
+                "warnings: " + warnings);
+    }
+
+    @Test
+    public void testEndpointOptionsOfTheCacheManagerAreLogged() throws 
Exception {
+        context.start();
+        
context.getEndpoint("infinispan-embedded:default?flags=SKIP_CACHE_LOAD&configurationUri=infinispan.xml");
+        context.getEndpoint("infinispan-embedded:other?sync=false");
+
+        assertTrue(warned("[configurationUri, flags]", 
"infinispan-embedded://default"), "warnings: " + warnings);
+        assertTrue(warnings.stream().noneMatch(message -> 
message.contains("infinispan-embedded://other")),
+                "warnings: " + warnings);
+    }
+}

Reply via email to