InvalidateLocalCacheMessageListener implements RedisChannelListener { @Override public void onMessage(byte[] message) throws IOException { InvalidateLocalCacheMessage invalidateMessage = reader.fromJSON(message); if (!Network.LOCAL_HOST_ADDRESS.equals(invalidateMessage.clientIP)) { logger.info("invalidate local cache, keys={}", invalidateMessage.keys); localCache.delete(invalidateMessage.keys.toArray(String[]::new)); } } InvalidateLocalCacheMessageListener(LocalCacheStore localCache); @Override void onSubscribe(); @Override void onMessage(byte[] message);  }
@Test void onMessage() throws IOException { var message = new InvalidateLocalCacheMessage(); message.clientIP = "remoteIP"; message.keys = List.of("key1", "key2"); listener.onMessage(Strings.bytes(JSON.toJSON(message))); verify(cacheStore).delete("key1", "key2"); }
@Test void onMessageWithSameClientIP() throws IOException { var message = new InvalidateLocalCacheMessage(); message.clientIP = Network.LOCAL_HOST_ADDRESS; message.keys = List.of("key1"); listener.onMessage(Strings.bytes(JSON.toJSON(message))); verify(cacheStore, never()).delete("key1"); }