fuyou001 commented on code in PR #5306: URL: https://github.com/apache/rocketmq/pull/5306#discussion_r994545963
########## proxy/src/test/java/org/apache/rocketmq/proxy/service/route/ClusterTopicRouteServiceTest.java: ########## @@ -67,4 +77,45 @@ public void testGetTopicRouteForProxy() throws Throwable { assertEquals(1, proxyTopicRouteData.getBrokerDatas().size()); assertEquals(addressList, proxyTopicRouteData.getBrokerDatas().get(0).getBrokerAddrs().get(MixAll.MASTER_ID)); } + + @Test + public void testTopicRouteCaffeineCache() throws InterruptedException { + String key = "abc"; + String value = key; + final AtomicBoolean throwException = new AtomicBoolean(); + ThreadPoolExecutor cacheRefreshExecutor = ThreadPoolMonitor.createAndMonitor( + 10, 10, 30L, TimeUnit.SECONDS, "test", 10); + LoadingCache<String /* topicName */, String> topicCache = Caffeine.newBuilder().maximumSize(30). + refreshAfterWrite(2, TimeUnit.SECONDS).executor(cacheRefreshExecutor).build(new CacheLoader<String, String>() { + @Override public @Nullable String load(@NonNull String key) throws Exception { + try { + if (throwException.get()) { + throw new RuntimeException(); + } else { + throwException.set(true); + return value; + } + } catch (Exception e) { + if (TopicRouteHelper.isTopicNotExistError(e)) { + return ""; + } + throw e; + } + } + + @Override + public @Nullable String reload(@NonNull String key, @NonNull String oldValue) throws Exception { + try { + return load(key); + } catch (Exception e) { + return oldValue; + } + } + }); + + System.out.println(topicCache.get(key)); Review Comment: > Use logging system rather than standard output in java done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@rocketmq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org