lhotari commented on code in PR #25246:
URL: https://github.com/apache/pulsar/pull/25246#discussion_r2811601984


##########
pulsar-metadata/src/test/java/org/apache/pulsar/metadata/MetadataCacheTest.java:
##########
@@ -739,4 +741,18 @@ public void testNoBackoffMetadataCacheConfig() {
         assertTrue(backoff.isMandatoryStopMade());
         assertEquals(backoff.getFirstBackoffTimeInMillis(), 0);
     }
+
+    @Test
+    public void testRefreshRace() throws Exception {
+        @Cleanup final var store = new 
LocalMemoryMetadataStore("memory:local", MetadataStoreConfig.builder().build());
+        final var cache = store.getMetadataCache(String.class);
+        for (int i = 0; i < 500; i++) {
+            final var key = "/key" + i;
+            assertTrue(cache.get(key).get().isEmpty());
+
+            store.put(key, "\"value\"".getBytes(StandardCharsets.UTF_8), 
Optional.empty()).get();
+            
Awaitility.await().pollInterval(Duration.ofMillis(1)).atMost(Duration.ofSeconds(3)).untilAsserted(()
 ->

Review Comment:
   btw. Wait could be avoided when `cache.put` is used. Internally, it will 
wait until the update has completed and then refresh the cache by reading from 
the store again. However I don't think it's necessary to add this test in this 
PR since I'd like to get 4.0.9 release candidate 2 and 4.1.3 release candidate 
2 started asap.
   
   ```java
       @Test
       public void testRefreshRaceCacheOnly() throws Exception {
           @Cleanup final var store = new 
LocalMemoryMetadataStore("memory:local", MetadataStoreConfig.builder().build());
           final var cache = store.getMetadataCache(String.class);
           for (int i = 0; i < 500; i++) {
               final var key = "/key" + i;
               assertTrue(cache.get(key).get().isEmpty());
   
               cache.put(key, "\"value\"", 
EnumSet.noneOf(CreateOption.class)).get();
               assertTrue(cache.get(key).get().isPresent(), "Failed at key " + 
key);
           }
       }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to