|
7 | 7 | import org.redisson.api.*;
|
8 | 8 | import org.redisson.api.MapOptions.WriteMode;
|
9 | 9 | import org.redisson.api.map.event.*;
|
| 10 | +import org.redisson.client.RedisClient; |
| 11 | +import org.redisson.client.RedisClientConfig; |
| 12 | +import org.redisson.client.RedisConnection; |
10 | 13 | import org.redisson.client.codec.*;
|
| 14 | +import org.redisson.client.protocol.RedisCommands; |
11 | 15 | import org.redisson.codec.CompositeCodec;
|
12 | 16 | import org.redisson.config.Config;
|
13 | 17 | import org.redisson.eviction.EvictionScheduler;
|
@@ -1562,5 +1566,49 @@ public void testComputeIfAbsentWithTTL() throws Exception{
|
1562 | 1566 | map.destroy();
|
1563 | 1567 |
|
1564 | 1568 | }
|
| 1569 | + |
| 1570 | + @Test |
| 1571 | + public void testNameMapper() throws InterruptedException, ExecutionException { |
| 1572 | + Config config = new Config(); |
| 1573 | + config.useSingleServer() |
| 1574 | + .setNameMapper(new NameMapper() { |
| 1575 | + @Override |
| 1576 | + public String map(String name) { |
| 1577 | + return name + ":suffix:"; |
| 1578 | + } |
| 1579 | + |
| 1580 | + @Override |
| 1581 | + public String unmap(String name) { |
| 1582 | + return name.replace(":suffix:", ""); |
| 1583 | + } |
| 1584 | + }) |
| 1585 | + .setConnectionMinimumIdleSize(3) |
| 1586 | + .setConnectionPoolSize(3) |
| 1587 | + .setAddress(redisson.getConfig().useSingleServer().getAddress()); |
| 1588 | + |
| 1589 | + RedissonClient redisson = Redisson.create(config); |
| 1590 | + |
| 1591 | + AtomicBoolean executed = new AtomicBoolean(); |
| 1592 | + RMapCache<String, String> map = redisson.getMapCache("test"); |
| 1593 | + map.addListener(new EntryExpiredListener() { |
| 1594 | + @Override |
| 1595 | + public void onExpired(EntryEvent event) { |
| 1596 | + executed.set(true); |
| 1597 | + } |
| 1598 | + }); |
| 1599 | + map.put("1", "2", 1, TimeUnit.SECONDS); |
| 1600 | + |
| 1601 | + Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> assertThat(executed.get()).isTrue()); |
| 1602 | + |
| 1603 | + RedisClientConfig destinationCfg = new RedisClientConfig(); |
| 1604 | + destinationCfg.setAddress(redisson.getConfig().useSingleServer().getAddress()); |
| 1605 | + RedisClient client = RedisClient.create(destinationCfg); |
| 1606 | + RedisConnection destinationConnection = client.connect(); |
| 1607 | + List<String> channels = destinationConnection.sync(RedisCommands.PUBSUB_CHANNELS); |
| 1608 | + assertThat(channels).contains("redisson_map_cache_expired:{test:suffix:}"); |
| 1609 | + client.shutdown(); |
| 1610 | + |
| 1611 | + redisson.shutdown(); |
| 1612 | + } |
1565 | 1613 | }
|
1566 | 1614 |
|
0 commit comments