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 9f9946b37b9a CAMEL-27012: camel-ehcache, camel-hazelcast,
camel-infinispan, camel-jcache, camel-spring, camel-seda - the cache
repositories tell whether they keep their data only in memory (#30612)
9f9946b37b9a is described below
commit 9f9946b37b9ae5a0bcd70701a52af742ae06555c
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 23 09:52:02 2026 +0100
CAMEL-27012: camel-ehcache, camel-hazelcast, camel-infinispan,
camel-jcache, camel-spring, camel-seda - the cache repositories tell whether
they keep their data only in memory (#30612)
The repositories of the configurable caches implement InMemoryStrategy and
answer for the configuration in use: the resource pools of an Ehcache cache,
the stores and cache mode of an embedded Infinispan cache, the cluster,
backups,
MapStore and data persistence of a Hazelcast map (decided when asked), the
caching provider and write-through of a JCache cache, and the cache class of
a Spring cache. The queue of a seda endpoint tells it too.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/component/ehcache/EhcacheManager.java | 23 +++
.../processor/EhcacheKeyValueRepository.java | 9 +-
.../aggregate/EhcacheAggregationRepository.java | 12 +-
.../idempotent/EhcacheIdempotentRepository.java | 9 +-
.../processor/EhcacheRepositoriesInMemoryTest.java | 134 +++++++++++++++
.../hazelcast/HazelcastKeyValueRepository.java | 13 +-
.../camel/component/hazelcast/HazelcastUtil.java | 42 +++++
.../hazelcast/HazelcastAggregationRepository.java | 14 +-
.../ReplicatedHazelcastAggregationRepository.java | 10 ++
.../hazelcast/HazelcastIdempotentRepository.java | 13 +-
.../HazelcastRepositoriesInMemoryTest.java | 186 +++++++++++++++++++++
.../InfinispanEmbeddedAggregationRepository.java | 11 +-
.../InfinispanEmbeddedIdempotentRepository.java | 13 +-
.../embedded/InfinispanEmbeddedUtil.java | 31 ++++
...InfinispanEmbeddedRepositoriesInMemoryTest.java | 163 ++++++++++++++++++
.../camel/component/jcache/JCacheHelper.java | 33 ++++
.../jcache/processor/JCacheKeyValueRepository.java | 13 +-
.../aggregate/JCacheAggregationRepository.java | 11 +-
.../idempotent/JCacheIdempotentRepository.java | 13 +-
.../jcache/JCacheRepositoriesInMemoryTest.java | 87 ++++++++++
.../apache/camel/component/seda/SedaEndpoint.java | 20 ++-
.../SpringCacheIdempotentRepository.java | 17 +-
...pringCacheIdempotentRepositoryInMemoryTest.java | 58 +++++++
.../camel/component/seda/SedaInMemoryTest.java | 56 +++++++
24 files changed, 978 insertions(+), 13 deletions(-)
diff --git
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
index 4b1d5858a068..cd2e3cb2684c 100644
---
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
+++
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
@@ -27,6 +27,8 @@ import org.apache.camel.util.ReferenceCount;
import org.ehcache.Cache;
import org.ehcache.CacheManager;
import org.ehcache.config.CacheConfiguration;
+import org.ehcache.config.ResourcePools;
+import org.ehcache.config.ResourceType;
import org.ehcache.config.builders.CacheConfigurationBuilder;
import org.ehcache.config.builders.ResourcePoolsBuilder;
import org.ehcache.spi.service.ServiceConfiguration;
@@ -184,6 +186,27 @@ public class EhcacheManager extends ServiceSupport {
}
}
+ /**
+ * Whether the cache keeps its entries only in memory, so they are lost
when the application stops. This is read
+ * from the resource pools of the cache: the heap, the off-heap and a disk
tier that is not persistent lose the
+ * entries; a persistent disk tier, or a tier of another kind such as a
clustered one, keeps them. False when the
+ * cache is not known yet, as the repository is not started.
+ */
+ public static boolean isInMemory(Cache<?, ?> cache) {
+ if (cache == null) {
+ return false;
+ }
+ ResourcePools pools =
cache.getRuntimeConfiguration().getResourcePools();
+ for (ResourceType<?> type : pools.getResourceTypeSet()) {
+ boolean memory = type == ResourceType.Core.HEAP || type ==
ResourceType.Core.OFFHEAP
+ || (type == ResourceType.Core.DISK &&
!pools.getPoolForResource(type).isPersistent());
+ if (!memory) {
+ return false;
+ }
+ }
+ return true;
+ }
+
CacheManager getCacheManager() {
return this.cacheManager;
}
diff --git
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/EhcacheKeyValueRepository.java
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/EhcacheKeyValueRepository.java
index 18bb6e192a36..2366f648c1cf 100644
---
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/EhcacheKeyValueRepository.java
+++
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/EhcacheKeyValueRepository.java
@@ -27,6 +27,7 @@ import org.apache.camel.api.management.ManagedOperation;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.component.ehcache.EhcacheManager;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.KeyValueRepository;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.KeyValueRepositoryHelper;
@@ -53,7 +54,7 @@ import org.ehcache.CacheManager;
annotations = {
"interfaceName=org.apache.camel.spi.KeyValueRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "Ehcache based key-value repository")
-public class EhcacheKeyValueRepository extends ServiceSupport implements
KeyValueRepository {
+public class EhcacheKeyValueRepository extends ServiceSupport implements
KeyValueRepository, InMemoryStrategy {
private Cache<String, KeyValueTtlValue> cache;
private EhcacheManager ehcacheManager;
@@ -233,6 +234,12 @@ public class EhcacheKeyValueRepository extends
ServiceSupport implements KeyValu
cache.clear();
}
+ @Override
+ @ManagedAttribute(description = "Whether the entries are kept only in
memory (lost when the application stops)")
+ public boolean isInMemory() {
+ return EhcacheManager.isInMemory(cache);
+ }
+
@Override
@ManagedAttribute(description = "The number of entries in the repository")
public int size() {
diff --git
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/aggregate/EhcacheAggregationRepository.java
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/aggregate/EhcacheAggregationRepository.java
index f741121274a7..d4781f2d1e08 100644
---
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/aggregate/EhcacheAggregationRepository.java
+++
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/aggregate/EhcacheAggregationRepository.java
@@ -23,8 +23,11 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
+import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.component.ehcache.EhcacheManager;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.RecoverableAggregationRepository;
import org.apache.camel.support.DefaultExchange;
@@ -41,7 +44,8 @@ import org.slf4j.LoggerFactory;
annotations = {
"interfaceName=org.apache.camel.spi.AggregationRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "EHCache based aggregation repository")
-public class EhcacheAggregationRepository extends ServiceSupport implements
RecoverableAggregationRepository {
+public class EhcacheAggregationRepository extends ServiceSupport
+ implements RecoverableAggregationRepository, InMemoryStrategy {
private static final Logger LOG =
LoggerFactory.getLogger(EhcacheAggregationRepository.class);
@@ -79,6 +83,12 @@ public class EhcacheAggregationRepository extends
ServiceSupport implements Reco
this.camelContext = camelContext;
}
+ @Override
+ @ManagedAttribute(description = "Whether the aggregates are kept only in
memory (lost when the application stops)")
+ public boolean isInMemory() {
+ return EhcacheManager.isInMemory(cache);
+ }
+
public CacheManager getCacheManager() {
return cacheManager;
}
diff --git
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/idempotent/EhcacheIdempotentRepository.java
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/idempotent/EhcacheIdempotentRepository.java
index 576e339a444a..b5af668d2f54 100644
---
a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/idempotent/EhcacheIdempotentRepository.java
+++
b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/processor/idempotent/EhcacheIdempotentRepository.java
@@ -22,6 +22,7 @@ import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.component.ehcache.EhcacheManager;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceSupport;
import org.ehcache.Cache;
@@ -32,7 +33,7 @@ import org.ehcache.CacheManager;
annotations = {
"interfaceName=org.apache.camel.spi.IdempotentRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "EHCache based message id repository")
-public class EhcacheIdempotentRepository extends ServiceSupport implements
IdempotentRepository {
+public class EhcacheIdempotentRepository extends ServiceSupport implements
IdempotentRepository, InMemoryStrategy {
@Metadata(description = "Name of cache", defaultValue =
"EhcacheIdempotentRepository")
private String cacheName;
@@ -57,6 +58,12 @@ public class EhcacheIdempotentRepository extends
ServiceSupport implements Idemp
return cacheName;
}
+ @Override
+ @ManagedAttribute(description = "Whether the keys are kept only in memory
(lost when the application stops)")
+ public boolean isInMemory() {
+ return EhcacheManager.isInMemory(cache);
+ }
+
@Override
@ManagedOperation(description = "Adds the key to the store")
public boolean add(String key) {
diff --git
a/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/processor/EhcacheRepositoriesInMemoryTest.java
b/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/processor/EhcacheRepositoriesInMemoryTest.java
new file mode 100644
index 000000000000..00824a6eb82e
--- /dev/null
+++
b/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/processor/EhcacheRepositoriesInMemoryTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.ehcache.processor;
+
+import java.nio.file.Path;
+
+import
org.apache.camel.component.ehcache.processor.aggregate.EhcacheAggregationRepository;
+import
org.apache.camel.component.ehcache.processor.idempotent.EhcacheIdempotentRepository;
+import org.apache.camel.support.DefaultExchangeHolder;
+import org.apache.camel.support.KeyValueTtlValue;
+import org.ehcache.CacheManager;
+import org.ehcache.config.builders.CacheConfigurationBuilder;
+import org.ehcache.config.builders.CacheManagerBuilder;
+import org.ehcache.config.builders.ResourcePoolsBuilder;
+import org.ehcache.config.units.MemoryUnit;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The Ehcache repositories tell from the resource pools of their cache
whether they keep their data only in memory.
+ */
+class EhcacheRepositoriesInMemoryTest {
+
+ @TempDir
+ Path dir;
+
+ private CacheManager cacheManager;
+ private EhcacheIdempotentRepository idempotent;
+ private EhcacheKeyValueRepository keyValue;
+ private EhcacheAggregationRepository aggregation;
+
+ @AfterEach
+ void stop() {
+ if (idempotent != null) {
+ idempotent.stop();
+ }
+ if (keyValue != null) {
+ keyValue.stop();
+ }
+ if (aggregation != null) {
+ aggregation.stop();
+ }
+ if (cacheManager != null) {
+ cacheManager.close();
+ }
+ }
+
+ @Test
+ void heapOnlyIsInMemory() {
+ startRepositories(ResourcePoolsBuilder.heap(100), false);
+
+ assertTrue(idempotent.isInMemory());
+ assertTrue(keyValue.isInMemory());
+ assertTrue(aggregation.isInMemory());
+ }
+
+ @Test
+ void heapAndOffHeapIsInMemory() {
+ startRepositories(ResourcePoolsBuilder.heap(100).offheap(1,
MemoryUnit.MB), false);
+
+ assertTrue(idempotent.isInMemory());
+ assertTrue(keyValue.isInMemory());
+ assertTrue(aggregation.isInMemory());
+ }
+
+ @Test
+ void diskTierThatIsNotPersistentIsInMemory() {
+ // the entries on such a disk tier are removed when the cache manager
closes
+ startRepositories(ResourcePoolsBuilder.heap(100).disk(10,
MemoryUnit.MB, false), true);
+
+ assertTrue(idempotent.isInMemory());
+ assertTrue(keyValue.isInMemory());
+ assertTrue(aggregation.isInMemory());
+ }
+
+ @Test
+ void persistentDiskTierIsNotInMemory() {
+ startRepositories(ResourcePoolsBuilder.heap(100).disk(10,
MemoryUnit.MB, true), true);
+
+ assertFalse(idempotent.isInMemory());
+ assertFalse(keyValue.isInMemory());
+ assertFalse(aggregation.isInMemory());
+ }
+
+ @Test
+ void notStartedCannotTell() {
+ cacheManager =
CacheManagerBuilder.newCacheManagerBuilder().build(true);
+
+ assertFalse(new EhcacheIdempotentRepository(cacheManager,
"ids").isInMemory());
+ assertFalse(new EhcacheKeyValueRepository(cacheManager,
"entries").isInMemory());
+ assertFalse(new EhcacheAggregationRepository().isInMemory());
+ }
+
+ private void startRepositories(ResourcePoolsBuilder pools, boolean disk) {
+ CacheManagerBuilder<? extends CacheManager> builder = disk
+ ?
CacheManagerBuilder.newCacheManagerBuilder().with(CacheManagerBuilder.persistence(dir.toFile()))
+ : CacheManagerBuilder.newCacheManagerBuilder();
+ cacheManager = builder
+ .withCache("ids",
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class,
Boolean.class, pools))
+ .withCache("entries",
+
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class,
KeyValueTtlValue.class, pools))
+ .withCache("aggregates",
+
CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class,
DefaultExchangeHolder.class,
+ pools))
+ .build(true);
+
+ idempotent = new EhcacheIdempotentRepository(cacheManager, "ids");
+ idempotent.start();
+ keyValue = new EhcacheKeyValueRepository(cacheManager, "entries");
+ keyValue.start();
+ aggregation = new EhcacheAggregationRepository();
+ aggregation.setCacheManager(cacheManager);
+ aggregation.setCacheName("aggregates");
+ aggregation.start();
+ }
+}
diff --git
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastKeyValueRepository.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastKeyValueRepository.java
index cc4de61d08ba..ef0c1cb08419 100644
---
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastKeyValueRepository.java
+++
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastKeyValueRepository.java
@@ -31,6 +31,7 @@ import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedOperation;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.KeyValueRepository;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.KeyValueRepositoryHelper;
@@ -60,7 +61,7 @@ import org.apache.camel.util.ObjectHelper;
annotations = {
"interfaceName=org.apache.camel.spi.KeyValueRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "Hazelcast based key-value repository")
-public class HazelcastKeyValueRepository extends ServiceSupport implements
KeyValueRepository {
+public class HazelcastKeyValueRepository extends ServiceSupport implements
KeyValueRepository, InMemoryStrategy {
private boolean useLocalHzInstance;
private IMap<String, byte[]> map;
@@ -213,6 +214,16 @@ public class HazelcastKeyValueRepository extends
ServiceSupport implements KeyVa
return map.remove(key, expectedBytes);
}
+ /**
+ * Whether the entries are kept only in memory, decided when asked as the
cluster changes; see
+ * {@link HazelcastUtil#isInMemory(HazelcastInstance, String)}.
+ */
+ @Override
+ @ManagedAttribute(description = "Whether the entries are kept only in
memory (lost when the application stops)")
+ public boolean isInMemory() {
+ return map != null && HazelcastUtil.isInMemory(hazelcastInstance,
mapName);
+ }
+
@Override
@ManagedAttribute(description = "The number of entries in the repository")
public int size() {
diff --git
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastUtil.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastUtil.java
index cf2dffe44693..5c85ac015aaf 100644
---
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastUtil.java
+++
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastUtil.java
@@ -16,7 +16,9 @@
*/
package org.apache.camel.component.hazelcast;
+import com.hazelcast.cluster.Member;
import com.hazelcast.config.Config;
+import com.hazelcast.config.MapConfig;
import com.hazelcast.config.XmlConfigBuilder;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
@@ -43,4 +45,44 @@ public final class HazelcastUtil {
public static HazelcastInstance newInstance(Config cfg) {
return Hazelcast.newHazelcastInstance(cfg);
}
+
+ /**
+ * Whether the entries of the map are kept only in the memory of this JVM,
so they are lost when the application
+ * stops. This is decided when asked, as the cluster changes: a client or
a lite member keeps no entries in this
+ * JVM, and a map store or data persistence keeps them elsewhere. A member
alone in its cluster loses them. With
+ * other data members, the backups decide: a backup count above 0 (1 is
the default) keeps a copy on another member.
+ */
+ public static boolean isInMemory(HazelcastInstance instance, String
mapName) {
+ if (!isDataMember(instance)) {
+ return false;
+ }
+ MapConfig config = instance.getConfig().findMapConfig(mapName);
+ if (config.getMapStoreConfig().isEnabled() ||
config.getDataPersistenceConfig().isEnabled()) {
+ return false;
+ }
+ return config.getTotalBackupCount() == 0 ||
!hasOtherDataMembers(instance);
+ }
+
+ /**
+ * Whether the entries of a replicated map are kept only in the memory of
this JVM: a replicated map has a copy on
+ * every data member, so only a member alone in its cluster loses them. A
client or a lite member keeps none.
+ */
+ public static boolean isReplicatedInMemory(HazelcastInstance instance) {
+ return isDataMember(instance) && !hasOtherDataMembers(instance);
+ }
+
+ private static boolean isDataMember(HazelcastInstance instance) {
+ // the local endpoint of a client is not a member
+ return instance != null && instance.getLifecycleService().isRunning()
+ && instance.getLocalEndpoint() instanceof Member member &&
!member.isLiteMember();
+ }
+
+ private static boolean hasOtherDataMembers(HazelcastInstance instance) {
+ for (Member member : instance.getCluster().getMembers()) {
+ if (!member.localMember() && !member.isLiteMember()) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git
a/components/camel-hazelcast/src/main/java/org/apache/camel/processor/aggregate/hazelcast/HazelcastAggregationRepository.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/processor/aggregate/hazelcast/HazelcastAggregationRepository.java
index 8791ab3dbbf2..53a347dbff03 100644
---
a/components/camel-hazelcast/src/main/java/org/apache/camel/processor/aggregate/hazelcast/HazelcastAggregationRepository.java
+++
b/components/camel-hazelcast/src/main/java/org/apache/camel/processor/aggregate/hazelcast/HazelcastAggregationRepository.java
@@ -32,7 +32,9 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.hazelcast.HazelcastSerializationFilterHelper;
+import org.apache.camel.component.hazelcast.HazelcastUtil;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.OptimisticLockingAggregationRepository;
import org.apache.camel.spi.RecoverableAggregationRepository;
@@ -60,7 +62,7 @@ import org.slf4j.LoggerFactory;
@Configurer(metadataOnly = true)
public class HazelcastAggregationRepository extends ServiceSupport
implements RecoverableAggregationRepository,
- OptimisticLockingAggregationRepository {
+ OptimisticLockingAggregationRepository, InMemoryStrategy {
protected static final String COMPLETED_SUFFIX = "-completed";
@@ -478,6 +480,16 @@ public class HazelcastAggregationRepository extends
ServiceSupport
return Collections.unmodifiableSet(cache.keySet());
}
+ /**
+ * Whether the aggregates, and the completed exchanges kept for recovery,
are kept only in memory, decided when
+ * asked as the cluster changes; see {@link
HazelcastUtil#isInMemory(HazelcastInstance, String)}.
+ */
+ @Override
+ public boolean isInMemory() {
+ return cache != null && HazelcastUtil.isInMemory(hazelcastInstance,
mapName)
+ && (!useRecovery ||
HazelcastUtil.isInMemory(hazelcastInstance, persistenceMapName));
+ }
+
/**
* @return Persistent repository {@link IMap} name;
*/
diff --git
a/components/camel-hazelcast/src/main/java/org/apache/camel/processor/aggregate/hazelcast/ReplicatedHazelcastAggregationRepository.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/processor/aggregate/hazelcast/ReplicatedHazelcastAggregationRepository.java
index 5941f60849d2..fc680be8492e 100644
---
a/components/camel-hazelcast/src/main/java/org/apache/camel/processor/aggregate/hazelcast/ReplicatedHazelcastAggregationRepository.java
+++
b/components/camel-hazelcast/src/main/java/org/apache/camel/processor/aggregate/hazelcast/ReplicatedHazelcastAggregationRepository.java
@@ -28,6 +28,7 @@ import com.hazelcast.map.IMap;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.component.hazelcast.HazelcastSerializationFilterHelper;
+import org.apache.camel.component.hazelcast.HazelcastUtil;
import org.apache.camel.spi.OptimisticLockingAggregationRepository;
import org.apache.camel.spi.RecoverableAggregationRepository;
import org.apache.camel.support.DefaultExchangeHolder;
@@ -305,6 +306,15 @@ public class ReplicatedHazelcastAggregationRepository
extends HazelcastAggregati
return Collections.unmodifiableSet(replicatedCache.keySet());
}
+ /**
+ * Whether the aggregates are kept only in memory: a replicated map has a
copy on every data member, so only a
+ * member alone in its cluster loses them; see {@link
HazelcastUtil#isReplicatedInMemory(HazelcastInstance)}.
+ */
+ @Override
+ public boolean isInMemory() {
+ return replicatedCache != null &&
HazelcastUtil.isReplicatedInMemory(hazelcastInstance);
+ }
+
@Override
protected void doStart() throws Exception {
if (maximumRedeliveries < 0) {
diff --git
a/components/camel-hazelcast/src/main/java/org/apache/camel/processor/idempotent/hazelcast/HazelcastIdempotentRepository.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/processor/idempotent/hazelcast/HazelcastIdempotentRepository.java
index 7cc3995cef22..230b9334a4ab 100644
---
a/components/camel-hazelcast/src/main/java/org/apache/camel/processor/idempotent/hazelcast/HazelcastIdempotentRepository.java
+++
b/components/camel-hazelcast/src/main/java/org/apache/camel/processor/idempotent/hazelcast/HazelcastIdempotentRepository.java
@@ -22,8 +22,10 @@ import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import org.apache.camel.component.hazelcast.HazelcastSerializationFilterHelper;
+import org.apache.camel.component.hazelcast.HazelcastUtil;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceSupport;
import org.apache.camel.util.ObjectHelper;
@@ -32,7 +34,7 @@ import org.apache.camel.util.ObjectHelper;
description = "Idempotent repository that uses Hazelcast cache to
store message ids.",
annotations = {
"interfaceName=org.apache.camel.spi.IdempotentRepository" })
@Configurer(metadataOnly = true)
-public class HazelcastIdempotentRepository extends ServiceSupport implements
IdempotentRepository {
+public class HazelcastIdempotentRepository extends ServiceSupport implements
IdempotentRepository, InMemoryStrategy {
protected boolean useLocalHzInstance;
@@ -125,6 +127,15 @@ public class HazelcastIdempotentRepository extends
ServiceSupport implements Ide
repo.clear();
}
+ /**
+ * Whether the keys are kept only in memory, decided when asked as the
cluster changes; see
+ * {@link HazelcastUtil#isInMemory(HazelcastInstance, String)}.
+ */
+ @Override
+ public boolean isInMemory() {
+ return repo != null && HazelcastUtil.isInMemory(hazelcastInstance,
repositoryName);
+ }
+
public String getRepositoryName() {
return repositoryName;
}
diff --git
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastRepositoriesInMemoryTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastRepositoriesInMemoryTest.java
new file mode 100644
index 000000000000..51cfbf63869e
--- /dev/null
+++
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastRepositoriesInMemoryTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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.hazelcast;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import com.hazelcast.client.HazelcastClient;
+import com.hazelcast.client.config.ClientConfig;
+import com.hazelcast.cluster.Address;
+import com.hazelcast.config.Config;
+import com.hazelcast.config.MapConfig;
+import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.map.MapStoreAdapter;
+import
org.apache.camel.processor.aggregate.hazelcast.HazelcastAggregationRepository;
+import
org.apache.camel.processor.aggregate.hazelcast.ReplicatedHazelcastAggregationRepository;
+import
org.apache.camel.processor.idempotent.hazelcast.HazelcastIdempotentRepository;
+import org.apache.camel.support.service.ServiceSupport;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The Hazelcast repositories tell whether they keep their data only in
memory, from the cluster as it is when asked.
+ */
+class HazelcastRepositoriesInMemoryTest {
+
+ private final String clusterName = "in-memory-" + UUID.randomUUID();
+ private final List<HazelcastInstance> instances = new ArrayList<>();
+ private final List<ServiceSupport> repositories = new ArrayList<>();
+
+ @AfterEach
+ void stop() {
+ repositories.forEach(ServiceSupport::stop);
+ // the client first, then the members
+ for (int i = instances.size() - 1; i >= 0; i--) {
+ instances.get(i).shutdown();
+ }
+ }
+
+ @Test
+ void memberAloneIsInMemory() {
+ HazelcastInstance member = newMember(memberConfig());
+
+ assertTrue(idempotent(member).isInMemory());
+ assertTrue(keyValue(member).isInMemory());
+ assertTrue(aggregation(member).isInMemory());
+ assertTrue(replicatedAggregation(member).isInMemory());
+ }
+
+ @Test
+ void backupOnAnotherMemberIsNotInMemory() {
+ HazelcastInstance member = newMember(memberConfig());
+ HazelcastIdempotentRepository idempotent = idempotent(member);
+ HazelcastKeyValueRepository keyValue = keyValue(member);
+ HazelcastAggregationRepository aggregation = aggregation(member);
+ ReplicatedHazelcastAggregationRepository replicated =
replicatedAggregation(member);
+ assertTrue(idempotent.isInMemory());
+
+ // decided when asked: a second member joins, and the default backup
count of 1 keeps a copy on it
+ newMember(memberConfig());
+ await().atMost(30, TimeUnit.SECONDS).until(() ->
member.getCluster().getMembers().size() == 2);
+
+ assertFalse(idempotent.isInMemory());
+ assertFalse(keyValue.isInMemory());
+ assertFalse(aggregation.isInMemory());
+ assertFalse(replicated.isInMemory());
+ }
+
+ @Test
+ void noBackupWithOtherMembersIsInMemory() {
+ Config config = memberConfig();
+ config.addMapConfig(new
MapConfig("ids").setBackupCount(0).setAsyncBackupCount(0));
+ HazelcastInstance member = newMember(config);
+ newMember(memberConfig().addMapConfig(new
MapConfig("ids").setBackupCount(0).setAsyncBackupCount(0)));
+ await().atMost(30, TimeUnit.SECONDS).until(() ->
member.getCluster().getMembers().size() == 2);
+
+ assertTrue(idempotent(member).isInMemory());
+ }
+
+ @Test
+ void mapStoreIsNotInMemory() {
+ Config config = memberConfig();
+ MapConfig mapConfig = new MapConfig("ids");
+ mapConfig.getMapStoreConfig().setEnabled(true).setImplementation(new
MapStoreAdapter<String, Boolean>());
+ config.addMapConfig(mapConfig);
+ HazelcastInstance member = newMember(config);
+
+ assertFalse(idempotent(member).isInMemory());
+ // another map of the same member has no map store
+ assertTrue(keyValue(member).isInMemory());
+ }
+
+ @Test
+ void clientIsNotInMemory() {
+ HazelcastInstance member = newMember(memberConfig());
+ HazelcastInstance client = newClient(member);
+
+ assertFalse(idempotent(client).isInMemory());
+ assertFalse(keyValue(client).isInMemory());
+ assertFalse(aggregation(client).isInMemory());
+ }
+
+ @Test
+ void notStartedCannotTell() {
+ HazelcastInstance member = newMember(memberConfig());
+
+ assertFalse(new HazelcastIdempotentRepository(member,
"ids").isInMemory());
+ assertFalse(new HazelcastKeyValueRepository(member,
"entries").isInMemory());
+ assertFalse(new HazelcastAggregationRepository("aggregates",
member).isInMemory());
+ assertFalse(new ReplicatedHazelcastAggregationRepository("replicated",
member).isInMemory());
+ }
+
+ private HazelcastIdempotentRepository idempotent(HazelcastInstance
instance) {
+ return started(new HazelcastIdempotentRepository(instance, "ids"));
+ }
+
+ private HazelcastKeyValueRepository keyValue(HazelcastInstance instance) {
+ return started(new HazelcastKeyValueRepository(instance, "entries"));
+ }
+
+ private HazelcastAggregationRepository aggregation(HazelcastInstance
instance) {
+ return started(new HazelcastAggregationRepository("aggregates",
instance));
+ }
+
+ private ReplicatedHazelcastAggregationRepository
replicatedAggregation(HazelcastInstance instance) {
+ return started(new
ReplicatedHazelcastAggregationRepository("replicated", instance));
+ }
+
+ private <T extends ServiceSupport> T started(T repository) {
+ repository.start();
+ repositories.add(repository);
+ return repository;
+ }
+
+ private HazelcastInstance newMember(Config config) {
+ HazelcastInstance member = Hazelcast.newHazelcastInstance(config);
+ instances.add(member);
+ return member;
+ }
+
+ private HazelcastInstance newClient(HazelcastInstance member) {
+ Address address = member.getCluster().getLocalMember().getAddress();
+ ClientConfig config = new ClientConfig();
+ config.setClusterName(clusterName);
+ config.getNetworkConfig().addAddress(address.getHost() + ":" +
address.getPort());
+
config.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(30000);
+ HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
+ instances.add(client);
+ return client;
+ }
+
+ private Config memberConfig() {
+ Config config = new Config();
+ config.setClusterName(clusterName);
+ config.setProperty("hazelcast.phone.home.enabled", "false");
+ config.setProperty("hazelcast.local.localAddress", "127.0.0.1");
+
config.getNetworkConfig().getInterfaces().setEnabled(true).addInterface("127.0.0.1");
+ config.getMetricsConfig().setEnabled(false);
+
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
+
config.getNetworkConfig().getJoin().getAutoDetectionConfig().setEnabled(false);
+ // the members of a test find each other on the loopback address, the
cluster name keeps other tests out
+
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true).addMember("127.0.0.1");
+ return config;
+ }
+}
diff --git
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedAggregationRepository.java
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedAggregationRepository.java
index ac674e9fd02a..3de2bffafaa1 100644
---
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedAggregationRepository.java
+++
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedAggregationRepository.java
@@ -20,6 +20,7 @@ import java.util.function.Supplier;
import org.apache.camel.component.infinispan.InfinispanAggregationRepository;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.DefaultExchangeHolder;
import org.apache.camel.support.service.ServiceHelper;
@@ -31,7 +32,7 @@ import org.infinispan.commons.api.BasicCache;
description = "Aggregation repository that uses embedded Infinispan
to store exchanges.",
annotations = {
"interfaceName=org.apache.camel.spi.AggregationRepository" })
@Configurer(metadataOnly = true)
-public class InfinispanEmbeddedAggregationRepository extends
InfinispanAggregationRepository {
+public class InfinispanEmbeddedAggregationRepository extends
InfinispanAggregationRepository implements InMemoryStrategy {
private Supplier<BasicCache<String, DefaultExchangeHolder>> cache;
private InfinispanEmbeddedManager manager;
@@ -95,6 +96,14 @@ public class InfinispanEmbeddedAggregationRepository extends
InfinispanAggregati
return cache.get();
}
+ /**
+ * Whether the aggregates are kept only in memory; see {@link
InfinispanEmbeddedUtil#isInMemory(BasicCache)}.
+ */
+ @Override
+ public boolean isInMemory() {
+ return isStarted() && InfinispanEmbeddedUtil.isInMemory(getCache());
+ }
+
public InfinispanEmbeddedConfiguration getConfiguration() {
return configuration;
}
diff --git
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedIdempotentRepository.java
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedIdempotentRepository.java
index 28daab8a23e0..021654f29d80 100644
---
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedIdempotentRepository.java
+++
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedIdempotentRepository.java
@@ -18,9 +18,11 @@ package org.apache.camel.component.infinispan.embedded;
import java.util.function.Supplier;
+import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.component.infinispan.InfinispanIdempotentRepository;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.util.ObjectHelper;
@@ -33,7 +35,7 @@ import org.infinispan.manager.EmbeddedCacheManager;
annotations = {
"interfaceName=org.apache.camel.spi.IdempotentRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "Infinispan Embedded message id repository")
-public class InfinispanEmbeddedIdempotentRepository extends
InfinispanIdempotentRepository {
+public class InfinispanEmbeddedIdempotentRepository extends
InfinispanIdempotentRepository implements InMemoryStrategy {
private Supplier<BasicCache<String, Boolean>> cache;
private InfinispanEmbeddedManager manager;
@@ -76,6 +78,15 @@ public class InfinispanEmbeddedIdempotentRepository extends
InfinispanIdempotent
return cache.get();
}
+ /**
+ * Whether the keys are kept only in memory; see {@link
InfinispanEmbeddedUtil#isInMemory(BasicCache)}.
+ */
+ @Override
+ @ManagedAttribute(description = "Whether the keys are kept only in memory
(lost when the application stops)")
+ public boolean isInMemory() {
+ return isStarted() && InfinispanEmbeddedUtil.isInMemory(getCache());
+ }
+
public void setCacheName(String cacheName) {
this.cacheName = cacheName;
}
diff --git
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedUtil.java
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedUtil.java
index 0e15acdcf06a..c1f383200bc4 100644
---
a/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedUtil.java
+++
b/components/camel-infinispan/camel-infinispan-embedded/src/main/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedUtil.java
@@ -16,14 +16,21 @@
*/
package org.apache.camel.component.infinispan.embedded;
+import java.util.List;
+
import org.apache.camel.Message;
import org.apache.camel.component.infinispan.InfinispanConfiguration;
import org.apache.camel.component.infinispan.InfinispanConstants;
import org.apache.camel.component.infinispan.InfinispanQueryBuilder;
import org.apache.camel.component.infinispan.InfinispanUtil;
import org.infinispan.Cache;
+import org.infinispan.commons.api.BasicCache;
import org.infinispan.commons.api.query.Query;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.StoreConfiguration;
import org.infinispan.context.Flag;
+import org.infinispan.remoting.transport.Address;
public final class InfinispanEmbeddedUtil extends InfinispanUtil {
@@ -37,6 +44,30 @@ public final class InfinispanEmbeddedUtil extends
InfinispanUtil {
return flags == null || flags.length == 0 ? cache :
cache.getAdvancedCache().withFlags(flags);
}
+ /**
+ * Whether the cache keeps its entries only in the memory of this JVM, so
they are lost when the application stops.
+ * A cache store keeps them, unless it purges on startup. A replicated
cache, or a distributed one with more than
+ * one owner, keeps copies on the other nodes of the cluster, when there
are any. A local cache without a store
+ * loses them, which is the default.
+ */
+ public static boolean isInMemory(BasicCache<?, ?> cache) {
+ if (!(cache instanceof Cache<?, ?> embedded)) {
+ return false;
+ }
+ Configuration configuration = embedded.getCacheConfiguration();
+ for (StoreConfiguration store : configuration.persistence().stores()) {
+ if (!store.purgeOnStartup()) {
+ return false;
+ }
+ }
+ CacheMode mode = configuration.clustering().cacheMode();
+ if (mode.isReplicated() || (mode.isDistributed() &&
configuration.clustering().hash().numOwners() > 1)) {
+ List<Address> members = embedded.getCacheManager().getMembers();
+ return members == null || members.size() <= 1;
+ }
+ return true;
+ }
+
public static Query<?> buildQuery(
InfinispanConfiguration configuration, Cache<Object, Object>
cache, Message message) {
diff --git
a/components/camel-infinispan/camel-infinispan-embedded/src/test/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedRepositoriesInMemoryTest.java
b/components/camel-infinispan/camel-infinispan-embedded/src/test/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedRepositoriesInMemoryTest.java
new file mode 100644
index 000000000000..62dec3baf08b
--- /dev/null
+++
b/components/camel-infinispan/camel-infinispan-embedded/src/test/java/org/apache/camel/component/infinispan/embedded/InfinispanEmbeddedRepositoriesInMemoryTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.support.service.ServiceSupport;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.testing.TestResourceTracker;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The embedded Infinispan repositories tell from the configuration of their
cache whether they keep their data only in
+ * memory.
+ */
+class InfinispanEmbeddedRepositoriesInMemoryTest {
+
+ @TempDir
+ Path dir;
+
+ private final List<ServiceSupport> repositories = new ArrayList<>();
+ private final List<EmbeddedCacheManager> cacheManagers = new ArrayList<>();
+
+ @BeforeAll
+ static void testStarted() {
+ // the clustered cache managers of the Infinispan test framework need
a test name
+
TestResourceTracker.testStarted(InfinispanEmbeddedRepositoriesInMemoryTest.class.getName());
+ }
+
+ @AfterAll
+ static void testFinished() {
+
TestResourceTracker.testFinished(InfinispanEmbeddedRepositoriesInMemoryTest.class.getName());
+ }
+
+ @AfterEach
+ void stop() {
+ repositories.forEach(ServiceSupport::stop);
+ cacheManagers.forEach(EmbeddedCacheManager::stop);
+ }
+
+ @Test
+ void localCacheIsInMemory() {
+ EmbeddedCacheManager cacheManager = localCacheManager();
+ cacheManager.defineConfiguration("local", new
ConfigurationBuilder().build());
+
+ assertTrue(idempotent(cacheManager, "local").isInMemory());
+ assertTrue(aggregation(cacheManager, "local").isInMemory());
+ }
+
+ @Test
+ void fileStoreIsNotInMemory() {
+ EmbeddedCacheManager cacheManager = localCacheManager();
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+ builder.persistence().addSoftIndexFileStore()
+ .dataLocation("data")
+ .indexLocation("index");
+ cacheManager.defineConfiguration("file", builder.build());
+
+ assertFalse(idempotent(cacheManager, "file").isInMemory());
+ assertFalse(aggregation(cacheManager, "file").isInMemory());
+ }
+
+ @Test
+ void fileStoreThatPurgesOnStartupIsInMemory() {
+ EmbeddedCacheManager cacheManager = localCacheManager();
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+ builder.persistence().addSoftIndexFileStore()
+ .dataLocation("data")
+ .indexLocation("index")
+ .purgeOnStartup(true);
+ cacheManager.defineConfiguration("purged", builder.build());
+
+ assertTrue(idempotent(cacheManager, "purged").isInMemory());
+ assertTrue(aggregation(cacheManager, "purged").isInMemory());
+ }
+
+ @Test
+ void replicatedCacheWithTwoNodesIsNotInMemory() {
+ EmbeddedCacheManager cacheManager =
clusteredCacheManagers(CacheMode.REPL_SYNC);
+
+ assertFalse(idempotent(cacheManager, "clustered").isInMemory());
+ assertFalse(aggregation(cacheManager, "clustered").isInMemory());
+ }
+
+ @Test
+ void distributedCacheWithOneOwnerIsInMemory() {
+ // each entry is on one node only, so the entries of this node are
lost when it stops
+ EmbeddedCacheManager cacheManager =
clusteredCacheManagers(CacheMode.DIST_SYNC);
+
+ assertTrue(idempotent(cacheManager, "clustered").isInMemory());
+ }
+
+ @Test
+ void notStartedCannotTell() {
+ assertFalse(new
InfinispanEmbeddedIdempotentRepository("local").isInMemory());
+ assertFalse(new
InfinispanEmbeddedAggregationRepository("local").isInMemory());
+ }
+
+ private EmbeddedCacheManager localCacheManager() {
+ GlobalConfigurationBuilder global = new
GlobalConfigurationBuilder().nonClusteredDefault();
+ // the locations of the file stores are relative to the persistent
location
+ global.globalState().enable().persistentLocation(dir.toString());
+ EmbeddedCacheManager cacheManager = new
DefaultCacheManager(global.build());
+ cacheManagers.add(cacheManager);
+ return cacheManager;
+ }
+
+ private EmbeddedCacheManager clusteredCacheManagers(CacheMode mode) {
+ InfinispanEmbeddedClusteredTestSupport.ClusteredCacheSupport cluster
+ = new
InfinispanEmbeddedClusteredTestSupport.ClusteredCacheSupport(mode, 2);
+ cluster.cacheName = "clustered";
+ cluster.createCacheManagers();
+ cacheManagers.addAll(cluster.getCacheManagers());
+ return cacheManagers.get(0);
+ }
+
+ private InfinispanEmbeddedIdempotentRepository
idempotent(EmbeddedCacheManager cacheManager, String cacheName) {
+ InfinispanEmbeddedIdempotentRepository repository = new
InfinispanEmbeddedIdempotentRepository(cacheName);
+ repository.setCacheContainer(cacheManager);
+ return started(repository);
+ }
+
+ private InfinispanEmbeddedAggregationRepository
aggregation(EmbeddedCacheManager cacheManager, String cacheName) {
+ InfinispanEmbeddedConfiguration configuration = new
InfinispanEmbeddedConfiguration();
+ configuration.setCacheContainer(cacheManager);
+ InfinispanEmbeddedAggregationRepository repository = new
InfinispanEmbeddedAggregationRepository(cacheName);
+ repository.setConfiguration(configuration);
+ return started(repository);
+ }
+
+ private <T extends ServiceSupport> T started(T repository) {
+ repository.start();
+ repositories.add(repository);
+ return repository;
+ }
+}
diff --git
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheHelper.java
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheHelper.java
index 680ef35073e2..997aa5b4b4e5 100644
---
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheHelper.java
+++
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheHelper.java
@@ -18,14 +18,47 @@ package org.apache.camel.component.jcache;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.Set;
+
+import javax.cache.Cache;
+import javax.cache.configuration.CompleteConfiguration;
import org.apache.camel.CamelContext;
import org.apache.camel.support.CamelContextHelper;
public final class JCacheHelper {
+
+ /**
+ * The caching providers that keep the entries of a cache in the heap of
this JVM: the reference implementation and
+ * Caffeine. The others can keep them elsewhere, such as Hazelcast in its
cluster, or Ehcache and Infinispan on
+ * disk, and the JCache API cannot ask a cache for that.
+ */
+ private static final Set<String> IN_MEMORY_PROVIDERS
+ = Set.of("org.jsr107.ri.spi.RICachingProvider",
JCacheProviders.caffeine.className());
+
private JCacheHelper() {
}
+ /**
+ * Whether the cache keeps its entries only in the memory of this JVM, so
they are lost when the application stops:
+ * when its caching provider is one that keeps them in the heap, and the
cache does not write them through to a
+ * cache writer. False when the cache is not known yet, as the repository
is not started.
+ */
+ public static boolean isInMemory(Cache<?, ?> cache) {
+ if (cache == null || cache.isClosed()) {
+ return false;
+ }
+ String provider =
cache.getCacheManager().getCachingProvider().getClass().getName();
+ // a provider that may keep the entries elsewhere is not asked for the
configuration of the cache
+ return IN_MEMORY_PROVIDERS.contains(provider)
+ && isInMemory(provider,
cache.getConfiguration(CompleteConfiguration.class).isWriteThrough());
+ }
+
+ static boolean isInMemory(String cachingProvider, boolean writeThrough) {
+ // a write-through cache keeps its entries in the store of its cache
writer too
+ return IN_MEMORY_PROVIDERS.contains(cachingProvider) && !writeThrough;
+ }
+
public static <K, V> JCacheManager<K, V> createManager(CamelContext
camelContext, JCacheConfiguration configuration) {
JCacheManagerFactory factory =
CamelContextHelper.findSingleByType(camelContext, JCacheManagerFactory.class);
if (factory == null) {
diff --git
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/JCacheKeyValueRepository.java
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/JCacheKeyValueRepository.java
index 2bbeba7599ed..57bd888faa5b 100644
---
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/JCacheKeyValueRepository.java
+++
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/JCacheKeyValueRepository.java
@@ -33,6 +33,7 @@ import org.apache.camel.component.jcache.JCacheConfiguration;
import org.apache.camel.component.jcache.JCacheHelper;
import org.apache.camel.component.jcache.JCacheManager;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.KeyValueRepository;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.KeyValueRepositoryHelper;
@@ -57,7 +58,8 @@ import org.apache.camel.util.ObjectHelper;
annotations = {
"interfaceName=org.apache.camel.spi.KeyValueRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "JCache based key-value repository")
-public class JCacheKeyValueRepository extends ServiceSupport implements
CamelContextAware, KeyValueRepository {
+public class JCacheKeyValueRepository extends ServiceSupport
+ implements CamelContextAware, KeyValueRepository, InMemoryStrategy {
private CamelContext camelContext;
private Cache<String, KeyValueTtlValue> cache;
@@ -239,6 +241,15 @@ public class JCacheKeyValueRepository extends
ServiceSupport implements CamelCon
cache.clear();
}
+ /**
+ * Whether the entries are kept only in memory; see {@link
JCacheHelper#isInMemory(Cache)}.
+ */
+ @Override
+ @ManagedAttribute(description = "Whether the entries are kept only in
memory (lost when the application stops)")
+ public boolean isInMemory() {
+ return JCacheHelper.isInMemory(cache);
+ }
+
@Override
@ManagedAttribute(description = "The number of entries in the repository")
public int size() {
diff --git
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/aggregate/JCacheAggregationRepository.java
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/aggregate/JCacheAggregationRepository.java
index b0785f5571a6..283534cda322 100644
---
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/aggregate/JCacheAggregationRepository.java
+++
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/aggregate/JCacheAggregationRepository.java
@@ -30,6 +30,7 @@ import org.apache.camel.component.jcache.JCacheConfiguration;
import org.apache.camel.component.jcache.JCacheHelper;
import org.apache.camel.component.jcache.JCacheManager;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.OptimisticLockingAggregationRepository;
import org.apache.camel.support.DefaultExchange;
@@ -44,7 +45,7 @@ import org.slf4j.LoggerFactory;
annotations = {
"interfaceName=org.apache.camel.spi.AggregationRepository" })
@Configurer(metadataOnly = true)
public class JCacheAggregationRepository extends ServiceSupport
- implements CamelContextAware, OptimisticLockingAggregationRepository {
+ implements CamelContextAware, OptimisticLockingAggregationRepository,
InMemoryStrategy {
private static final Logger LOG =
LoggerFactory.getLogger(JCacheAggregationRepository.class);
@@ -98,6 +99,14 @@ public class JCacheAggregationRepository extends
ServiceSupport
this.cache = cache;
}
+ /**
+ * Whether the aggregates are kept only in memory; see {@link
JCacheHelper#isInMemory(Cache)}.
+ */
+ @Override
+ public boolean isInMemory() {
+ return JCacheHelper.isInMemory(cache);
+ }
+
public boolean isOptimistic() {
return optimistic;
}
diff --git
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/idempotent/JCacheIdempotentRepository.java
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/idempotent/JCacheIdempotentRepository.java
index 58472d9b43c8..729c1891c5dc 100644
---
a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/idempotent/JCacheIdempotentRepository.java
+++
b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/processor/idempotent/JCacheIdempotentRepository.java
@@ -28,6 +28,7 @@ import org.apache.camel.component.jcache.JCacheHelper;
import org.apache.camel.component.jcache.JCacheManager;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceSupport;
import org.apache.camel.util.ObjectHelper;
@@ -37,7 +38,8 @@ import org.apache.camel.util.ObjectHelper;
annotations = {
"interfaceName=org.apache.camel.spi.IdempotentRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "JCache based message id repository")
-public class JCacheIdempotentRepository extends ServiceSupport implements
CamelContextAware, IdempotentRepository {
+public class JCacheIdempotentRepository extends ServiceSupport
+ implements CamelContextAware, IdempotentRepository, InMemoryStrategy {
private CamelContext camelContext;
private Cache<String, Boolean> cache;
@@ -109,6 +111,15 @@ public class JCacheIdempotentRepository extends
ServiceSupport implements CamelC
return configuration.getCacheName();
}
+ /**
+ * Whether the keys are kept only in memory; see {@link
JCacheHelper#isInMemory(Cache)}.
+ */
+ @Override
+ @ManagedAttribute(description = "Whether the keys are kept only in memory
(lost when the application stops)")
+ public boolean isInMemory() {
+ return JCacheHelper.isInMemory(cache);
+ }
+
@Override
public boolean confirm(String key) {
return cache.replace(key, false, true);
diff --git
a/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheRepositoriesInMemoryTest.java
b/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheRepositoriesInMemoryTest.java
new file mode 100644
index 000000000000..67d8069d3efd
--- /dev/null
+++
b/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheRepositoriesInMemoryTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.jcache;
+
+import org.apache.camel.component.jcache.processor.JCacheKeyValueRepository;
+import
org.apache.camel.component.jcache.processor.aggregate.JCacheAggregationRepository;
+import
org.apache.camel.component.jcache.processor.idempotent.JCacheIdempotentRepository;
+import org.apache.camel.component.jcache.support.HazelcastTest;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The JCache repositories tell from the caching provider and the
configuration of their cache whether they keep their
+ * data only in memory. The JCache API cannot ask a cache whether it persists
its entries, so only the providers that
+ * keep them in the heap count.
+ */
+@HazelcastTest
+class JCacheRepositoriesInMemoryTest extends CamelTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Test
+ void providerThatCannotTellIsNotInMemory() {
+ // the caching provider of the tests is Hazelcast, which keeps the
entries in its cluster
+ JCacheIdempotentRepository idempotent = new
JCacheIdempotentRepository();
+ idempotent.setCamelContext(context);
+ idempotent.setCacheName("in-memory-idempotent");
+ JCacheKeyValueRepository keyValue = new JCacheKeyValueRepository();
+ keyValue.setCamelContext(context);
+ keyValue.setCacheName("in-memory-key-value");
+ JCacheAggregationRepository aggregation = new
JCacheAggregationRepository();
+ aggregation.setCamelContext(context);
+ aggregation.setCacheName("in-memory-aggregation");
+ try {
+ idempotent.start();
+ keyValue.start();
+ aggregation.start();
+
+ assertFalse(idempotent.isInMemory());
+ assertFalse(keyValue.isInMemory());
+ assertFalse(aggregation.isInMemory());
+ } finally {
+ idempotent.stop();
+ keyValue.stop();
+ aggregation.stop();
+ }
+ }
+
+ @Test
+ void notStartedCannotTell() {
+ assertFalse(new JCacheIdempotentRepository().isInMemory());
+ assertFalse(new JCacheKeyValueRepository().isInMemory());
+ assertFalse(new JCacheAggregationRepository().isInMemory());
+ }
+
+ @Test
+ void heapProvidersAreInMemoryUnlessWriteThrough() {
+
assertTrue(JCacheHelper.isInMemory("org.jsr107.ri.spi.RICachingProvider",
false));
+
assertTrue(JCacheHelper.isInMemory(JCacheProviders.caffeine.className(),
false));
+ // a cache writer keeps the entries elsewhere too
+
assertFalse(JCacheHelper.isInMemory(JCacheProviders.caffeine.className(),
true));
+ // these providers can keep the entries on disk or in a cluster
+
assertFalse(JCacheHelper.isInMemory(JCacheProviders.hazelcast.className(),
false));
+
assertFalse(JCacheHelper.isInMemory(JCacheProviders.ehcache.className(),
false));
+
assertFalse(JCacheHelper.isInMemory(JCacheProviders.ispnEmbedded.className(),
false));
+ }
+}
diff --git
a/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
b/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
index 6912771d433f..63233712334b 100644
---
a/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
+++
b/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
@@ -45,6 +45,7 @@ import org.apache.camel.spi.BodyType;
import org.apache.camel.spi.BodyType.Carrier;
import org.apache.camel.spi.BodyTypes;
import org.apache.camel.spi.BrowsableEndpoint;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
@@ -72,7 +73,8 @@ import org.slf4j.LoggerFactory;
description = "Unchanged for a message that
expects no reply (InOnly). A message that"
+ " expects one (InOut), or
waitForTaskToComplete=Always, waits for the"
+ " body the seda route ends
with"))
-public class SedaEndpoint extends DefaultEndpoint implements AsyncEndpoint,
BrowsableEndpoint, MultipleConsumersSupport {
+public class SedaEndpoint extends DefaultEndpoint
+ implements AsyncEndpoint, BrowsableEndpoint, MultipleConsumersSupport,
InMemoryStrategy {
private static final Logger LOG =
LoggerFactory.getLogger(SedaEndpoint.class);
@@ -425,6 +427,22 @@ public class SedaEndpoint extends DefaultEndpoint
implements AsyncEndpoint, Brow
this.size = size;
}
+ /**
+ * Whether the messages waiting in the queue are kept only in memory, so
they are lost when the application stops:
+ * the queues of the JDK, which the queue factories of Camel create, are.
A queue of another kind, given with the
+ * queue option, can keep them elsewhere.
+ */
+ @Override
+ @ManagedAttribute(description = "Whether the messages waiting in the queue
are kept only in memory (lost when the application stops)")
+ public boolean isInMemory() {
+ BlockingQueue<Exchange> current = queue;
+ if (current != null) {
+ return
current.getClass().getName().startsWith("java.util.concurrent.");
+ }
+ return queueFactory instanceof LinkedBlockingQueueFactory ||
queueFactory instanceof ArrayBlockingQueueFactory
+ || queueFactory instanceof PriorityBlockingQueueFactory;
+ }
+
@ManagedAttribute(description = "Current queue size")
public int getCurrentQueueSize() {
return queue.size();
diff --git
a/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentRepository.java
b/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentRepository.java
index cd1ab1b9d98b..854b48fcd0a6 100644
---
a/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentRepository.java
+++
b/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentRepository.java
@@ -21,17 +21,22 @@ import org.apache.camel.api.management.ManagedOperation;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceSupport;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
+import org.springframework.cache.concurrent.ConcurrentMapCache;
@Metadata(label = "bean",
description = "SpringCache based message id repository.",
annotations = {
"interfaceName=org.apache.camel.spi.IdempotentRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "SpringCache based message id repository")
-public class SpringCacheIdempotentRepository extends ServiceSupport implements
IdempotentRepository {
+public class SpringCacheIdempotentRepository extends ServiceSupport implements
IdempotentRepository, InMemoryStrategy {
+
+ // spring-context-support is not a dependency of camel-spring
+ private static final String CAFFEINE_CACHE =
"org.springframework.cache.caffeine.CaffeineCache";
@Metadata(required = true, description = "The Spring Cache Manager")
private CacheManager manager;
@@ -98,6 +103,16 @@ public class SpringCacheIdempotentRepository extends
ServiceSupport implements I
return cacheName;
}
+ /**
+ * Whether the keys are kept only in memory: a ConcurrentMapCache (the
default of Spring Boot) and a CaffeineCache
+ * keep them in the heap of this JVM. Other caches, such as a RedisCache,
keep them elsewhere or cannot tell.
+ */
+ @Override
+ @ManagedAttribute(description = "Whether the keys are kept only in memory
(lost when the application stops)")
+ public boolean isInMemory() {
+ return cache instanceof ConcurrentMapCache || cache != null &&
CAFFEINE_CACHE.equals(cache.getClass().getName());
+ }
+
@Override
public boolean confirm(String key) {
return true;
diff --git
a/components/camel-spring-parent/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentRepositoryInMemoryTest.java
b/components/camel-spring-parent/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentRepositoryInMemoryTest.java
new file mode 100644
index 000000000000..974da29c2750
--- /dev/null
+++
b/components/camel-spring-parent/camel-spring/src/test/java/org/apache/camel/spring/processor/idempotent/SpringCacheIdempotentRepositoryInMemoryTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.spring.processor.idempotent;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
+import org.springframework.cache.support.NoOpCacheManager;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The Spring cache repository tells from its cache whether it keeps the keys
only in memory.
+ */
+class SpringCacheIdempotentRepositoryInMemoryTest {
+
+ @Test
+ void concurrentMapCacheIsInMemory() {
+ SpringCacheIdempotentRepository repository
+ = new SpringCacheIdempotentRepository(new
ConcurrentMapCacheManager(), "ids");
+ repository.start();
+ try {
+ assertTrue(repository.isInMemory());
+ } finally {
+ repository.stop();
+ }
+ }
+
+ @Test
+ void otherCacheCannotTell() {
+ SpringCacheIdempotentRepository repository = new
SpringCacheIdempotentRepository(new NoOpCacheManager(), "ids");
+ repository.start();
+ try {
+ assertFalse(repository.isInMemory());
+ } finally {
+ repository.stop();
+ }
+ }
+
+ @Test
+ void notStartedCannotTell() {
+ assertFalse(new SpringCacheIdempotentRepository(new
ConcurrentMapCacheManager(), "ids").isInMemory());
+ }
+}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInMemoryTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInMemoryTest.java
new file mode 100644
index 000000000000..f548c3fb8798
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInMemoryTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.seda;
+
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The messages waiting in the queue of a seda endpoint are kept only in
memory, unless the queue is of another kind.
+ */
+public class SedaInMemoryTest extends ContextTestSupport {
+
+ @Test
+ public void testDefaultQueueIsInMemory() {
+ SedaEndpoint endpoint = resolveMandatoryEndpoint("seda:inMemory",
SedaEndpoint.class);
+ // before the queue is created, from the queue factory
+ assertTrue(endpoint.isInMemory());
+
+ endpoint.getQueue();
+ assertTrue(endpoint.isInMemory());
+ }
+
+ @Test
+ public void testQueueOfAnotherKindCannotTell() {
+ SedaEndpoint endpoint = resolveMandatoryEndpoint("seda:otherQueue",
SedaEndpoint.class);
+ endpoint.setQueue(new OtherQueue());
+
+ assertFalse(endpoint.isInMemory());
+ }
+
+ /**
+ * A queue that is not one of the JDK, such as a queue that keeps the
messages in a store.
+ */
+ private static final class OtherQueue extends
LinkedBlockingQueue<Exchange> {
+ }
+}