Skip to content
Snippets Groups Projects
Commit 8d022947 authored by Alok Joshi's avatar Alok Joshi
Browse files

revert to original change

parent f35758fa
No related branches found
No related tags found
3 merge requests!33Fix list cache,!32Fix list cache,!31fix list api cache not updating upon creation and deletion
Pipeline #21066 failed
...@@ -50,7 +50,7 @@ public class CachedPartitionServiceImpl implements IPartitionService { ...@@ -50,7 +50,7 @@ public class CachedPartitionServiceImpl implements IPartitionService {
if (pi != null) { if (pi != null) {
partitionServiceCache.put(partitionId, partitionInfo); partitionServiceCache.put(partitionId, partitionInfo);
partitionListCache.get(PARTITION_LIST_KEY).add(partitionId); partitionListCache.clearAll();
} }
return pi; return pi;
...@@ -87,7 +87,7 @@ public class CachedPartitionServiceImpl implements IPartitionService { ...@@ -87,7 +87,7 @@ public class CachedPartitionServiceImpl implements IPartitionService {
if (partitionService.deletePartition(partitionId)) { if (partitionService.deletePartition(partitionId)) {
if (partitionServiceCache.get(partitionId) != null) { if (partitionServiceCache.get(partitionId) != null) {
partitionServiceCache.delete(partitionId); partitionServiceCache.delete(partitionId);
partitionListCache.get(PARTITION_LIST_KEY).remove(partitionId); partitionListCache.clearAll();
} }
return true; return true;
......
...@@ -44,25 +44,19 @@ public class CachedPartitionServiceImplTest { ...@@ -44,25 +44,19 @@ public class CachedPartitionServiceImplTest {
@InjectMocks @InjectMocks
private CachedPartitionServiceImpl cachedPartitionServiceImpl; private CachedPartitionServiceImpl cachedPartitionServiceImpl;
private static final String PARTITION_LIST_KEY = "getAllPartitions";
@Test @Test
public void createPartitionSucceed() { public void createPartitionSucceed() {
String partId = "key"; String partId = "key";
List<String> partitions = new ArrayList<>();
PartitionInfo newPi = PartitionInfo.builder().build(); PartitionInfo newPi = PartitionInfo.builder().build();
PartitionInfo retPi = PartitionInfo.builder().build(); PartitionInfo retPi = PartitionInfo.builder().build();
when(partitionServiceImpl.createPartition(partId, newPi)).thenReturn(retPi); when(partitionServiceImpl.createPartition(partId, newPi)).thenReturn(retPi);
when(partitionListCache.get(PARTITION_LIST_KEY)).thenReturn(partitions);
cachedPartitionServiceImpl.createPartition(partId, newPi); cachedPartitionServiceImpl.createPartition(partId, newPi);
verify(partitionServiceImpl, times(1)).createPartition(partId, newPi); verify(partitionServiceImpl, times(1)).createPartition(partId, newPi);
verify(partitionServiceCache, times(1)).put(partId, retPi); verify(partitionServiceCache, times(1)).put(partId, retPi);
verify(partitionListCache, times(1)).get(PARTITION_LIST_KEY); verify(partitionListCache, times(1)).clearAll();
} }
@Test @Test
...@@ -77,7 +71,7 @@ public class CachedPartitionServiceImplTest { ...@@ -77,7 +71,7 @@ public class CachedPartitionServiceImplTest {
verify(partitionServiceImpl, times(1)).createPartition(partId, newPi); verify(partitionServiceImpl, times(1)).createPartition(partId, newPi);
verify(partitionServiceCache, times(0)).put(any(), any()); verify(partitionServiceCache, times(0)).put(any(), any());
verify(partitionListCache, times(0)).get(PARTITION_LIST_KEY); verify(partitionListCache, times(0)).clearAll();
verify(partitionServiceCache, times(1)).get(any()); verify(partitionServiceCache, times(1)).get(any());
} }
...@@ -130,18 +124,15 @@ public class CachedPartitionServiceImplTest { ...@@ -130,18 +124,15 @@ public class CachedPartitionServiceImplTest {
String partId = "key"; String partId = "key";
PartitionInfo retPi = PartitionInfo.builder().build(); PartitionInfo retPi = PartitionInfo.builder().build();
List<String> partitions = new ArrayList<>();
when(partitionServiceImpl.deletePartition(partId)).thenReturn(true); when(partitionServiceImpl.deletePartition(partId)).thenReturn(true);
when(partitionServiceCache.get(partId)).thenReturn(retPi); when(partitionServiceCache.get(partId)).thenReturn(retPi);
when(partitionListCache.get(PARTITION_LIST_KEY)).thenReturn(partitions);
cachedPartitionServiceImpl.deletePartition(partId); cachedPartitionServiceImpl.deletePartition(partId);
verify(partitionServiceImpl, times(1)).deletePartition(partId); verify(partitionServiceImpl, times(1)).deletePartition(partId);
verify(partitionServiceCache, times(1)).delete(partId); verify(partitionServiceCache, times(1)).delete(partId);
verify(partitionServiceCache, times(1)).get(partId); verify(partitionServiceCache, times(1)).get(partId);
verify(partitionListCache, times(1)).get(PARTITION_LIST_KEY); verify(partitionListCache, times(1)).clearAll();
} }
@Test @Test
...@@ -150,9 +141,10 @@ public class CachedPartitionServiceImplTest { ...@@ -150,9 +141,10 @@ public class CachedPartitionServiceImplTest {
when(partitionServiceImpl.getAllPartitions()).thenReturn(partitions); when(partitionServiceImpl.getAllPartitions()).thenReturn(partitions);
cachedPartitionServiceImpl.getAllPartitions(); cachedPartitionServiceImpl.getAllPartitions();
verify(partitionListCache, times(1)).get(PARTITION_LIST_KEY); String partKey = "getAllPartitions";
verify(partitionListCache, times(1)).get(partKey);
verify(partitionServiceImpl, times(1)).getAllPartitions(); verify(partitionServiceImpl, times(1)).getAllPartitions();
verify(partitionListCache, times(1)).put(PARTITION_LIST_KEY, partitions); verify(partitionListCache, times(1)).put(partKey, partitions);
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment