Details
Description
Expiry Policy specified in Ignite cache operation context is not applied to the cache after the cache serialization/deserialization.
Steps to Reproduce
- Run an Ignite server with a cache without expiry policy
- A client node joins the server, gets the cache proxy and applies expiry policy to the cache proxy
- The client executes a Compute task taking the cache proxy as a parameter on the server.
- The Compute task puts an entry to the cache using the cache proxy received from the client.
- The client sleeps for a time period longer than the TTL specified for the expiry policy
- The client checks if the entry that the Compute task added still exists
Expected
The entry does not exist since it must expire
Actual
The entry still exists in the cache.
Reproducer
public class IgniteCacheSerializationTest { /** Expiry Policy specified in Ignite cache operation context is enabled after the cache serialization. */ @Test public void igniteCacheWithExpiryPolicySerialization() throws InterruptedException { var cacheName = "cache1"; var ttl = 1000; Supplier<IgniteConfiguration> igniteCfgFactory = () -> new IgniteConfiguration() .setDiscoverySpi( new TcpDiscoverySpi() .setIpFinder( new TcpDiscoveryVmIpFinder().setAddresses(Collections.singleton("127.0.0.1:47500")) ) ) .setCacheConfiguration(new CacheConfiguration<>(cacheName)); try (var ignored = Ignition.start(igniteCfgFactory.get().setIgniteInstanceName("server"))) { try (var ignite = Ignition.start( igniteCfgFactory.get().setIgniteInstanceName("test").setClientMode(true)) ) { // Apply a 1-second expiry policy to the cache var expiryPolicy = TouchedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, ttl)).create(); var cache = ignite.<Integer, String>cache(cacheName).withExpiryPolicy(expiryPolicy); // Run a Compute Task that serializes the cache with the 1-second expiry policy applied. // The task adds a key 1 to the cache ignite.compute().affinityRun(cacheName, 1, new Put1(cache)); // Sleep for a time twice longer than the TTL Thread.sleep(ttl * 2); // The key 1 must expiry by this time assertFalse(cache.containsKey(1), "The entry still exists in the cache"); } } } private static final class Put1 implements IgniteRunnable { private final IgniteCache<Integer, String> cache; public Put1(IgniteCache<Integer, String> cache) { this.cache = cache; } @Override public void run() { cache.put(1, "ignored"); } } }