Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
Expand All @@ -60,9 +60,9 @@ public class ConsulSyncDataService extends AbstractPathDataSyncService {
*/
private static final Logger LOG = LoggerFactory.getLogger(ConsulSyncDataService.class);

private final Map<String, Long> consulIndexes = new HashMap<>();
private final Map<String, Long> consulIndexes = new ConcurrentHashMap<>();

private final Map<String, List<ConsulData>> cacheConsulDataKeyMap = new HashMap<>();
private final Map<String, List<ConsulData>> cacheConsulDataKeyMap = new ConcurrentHashMap<>();

private final ScheduledThreadPoolExecutor executor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
Expand Down Expand Up @@ -131,8 +132,19 @@ public void testWatchConfigKeyValues() throws NoSuchMethodException, IllegalAcce
final Field consulIndexes = ConsulSyncDataService.class.getDeclaredField("consulIndexes");
consulIndexes.setAccessible(true);
final Map<String, Long> consulIndexesSource = (Map<String, Long>) consulIndexes.get(consulSyncDataService);
consulIndexesSource.put("/null", null);
consulIndexesSource.remove(watchPathRoot);
when(response.getConsulIndex()).thenReturn(2L);
Assertions.assertDoesNotThrow(() -> watchConfigKeyValues.invoke(consulSyncDataService, watchPathRoot, updateHandler, deleteHandler));
}

@Test
public void testWatcherStateUsesConcurrentMaps() throws NoSuchFieldException, IllegalAccessException {
Field consulIndexesField = ConsulSyncDataService.class.getDeclaredField("consulIndexes");
consulIndexesField.setAccessible(true);
Field cacheDataField = ConsulSyncDataService.class.getDeclaredField("cacheConsulDataKeyMap");
cacheDataField.setAccessible(true);

Assertions.assertTrue(consulIndexesField.get(consulSyncDataService) instanceof ConcurrentHashMap);
Assertions.assertTrue(cacheDataField.get(consulSyncDataService) instanceof ConcurrentHashMap);
}
}
Loading