|
33 | 33 | import java.io.IOException; |
34 | 34 | import java.lang.reflect.Field; |
35 | 35 | import java.nio.charset.StandardCharsets; |
| 36 | +import java.time.Duration; |
36 | 37 | import java.util.ArrayList; |
37 | 38 | import java.util.EnumSet; |
38 | 39 | import java.util.List; |
|
69 | 70 | import org.apache.pulsar.metadata.api.Stat; |
70 | 71 | import org.apache.pulsar.metadata.api.extended.CreateOption; |
71 | 72 | import org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl; |
| 73 | +import org.apache.pulsar.metadata.impl.LocalMemoryMetadataStore; |
72 | 74 | import org.awaitility.Awaitility; |
73 | 75 | import org.mockito.stubbing.Answer; |
74 | 76 | import org.testng.annotations.Test; |
@@ -739,4 +741,18 @@ public void testNoBackoffMetadataCacheConfig() { |
739 | 741 | assertTrue(backoff.isMandatoryStopMade()); |
740 | 742 | assertEquals(backoff.getFirstBackoffTimeInMillis(), 0); |
741 | 743 | } |
| 744 | + |
| 745 | + @Test |
| 746 | + public void testRefreshRace() throws Exception { |
| 747 | + @Cleanup final var store = new LocalMemoryMetadataStore("memory:local", MetadataStoreConfig.builder().build()); |
| 748 | + final var cache = store.getMetadataCache(String.class); |
| 749 | + for (int i = 0; i < 500; i++) { |
| 750 | + final var key = "/key" + i; |
| 751 | + assertTrue(cache.get(key).get().isEmpty()); |
| 752 | + |
| 753 | + store.put(key, "\"value\"".getBytes(StandardCharsets.UTF_8), Optional.empty()).get(); |
| 754 | + Awaitility.await().pollInterval(Duration.ofMillis(1)).atMost(Duration.ofSeconds(3)).untilAsserted(() -> |
| 755 | + assertTrue(cache.get(key).get().isPresent(), "Failed at key " + key)); |
| 756 | + } |
| 757 | + } |
742 | 758 | } |
0 commit comments