From 750e0211faabd526057976ea74aedfe105672f32 Mon Sep 17 00:00:00 2001
From: Alok Joshi <ajoshi19@slb.com>
Date: Fri, 8 Jan 2021 08:52:35 -0500
Subject: [PATCH] fix list api cache not updating upon creation and deletion

---
 .../osdu/partition/service/CachedPartitionServiceImpl.java    | 2 ++
 .../partition/service/CachedPartitionServiceImplTest.java     | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java b/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java
index 44a25c201..d5a897da4 100644
--- a/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java
+++ b/partition-core/src/main/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImpl.java
@@ -50,6 +50,7 @@ public class CachedPartitionServiceImpl implements IPartitionService {
 
         if (pi != null) {
             partitionServiceCache.put(partitionId, partitionInfo);
+            partitionListCache.clearAll();
         }
 
         return pi;
@@ -86,6 +87,7 @@ public class CachedPartitionServiceImpl implements IPartitionService {
         if (partitionService.deletePartition(partitionId)) {
             if (partitionServiceCache.get(partitionId) != null) {
                 partitionServiceCache.delete(partitionId);
+                partitionListCache.clearAll();
             }
 
             return true;
diff --git a/partition-core/src/test/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImplTest.java b/partition-core/src/test/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImplTest.java
index 596dac8dd..7d2680573 100644
--- a/partition-core/src/test/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImplTest.java
+++ b/partition-core/src/test/java/org/opengroup/osdu/partition/service/CachedPartitionServiceImplTest.java
@@ -52,11 +52,11 @@ public class CachedPartitionServiceImplTest {
         PartitionInfo retPi = PartitionInfo.builder().build();
 
         when(partitionServiceImpl.createPartition(partId, newPi)).thenReturn(retPi);
-
         cachedPartitionServiceImpl.createPartition(partId, newPi);
 
         verify(partitionServiceImpl, times(1)).createPartition(partId, newPi);
         verify(partitionServiceCache, times(1)).put(partId, retPi);
+        verify(partitionListCache, times(1)).clearAll();
     }
 
     @Test
@@ -71,6 +71,7 @@ public class CachedPartitionServiceImplTest {
 
         verify(partitionServiceImpl, times(1)).createPartition(partId, newPi);
         verify(partitionServiceCache, times(0)).put(any(), any());
+        verify(partitionListCache, times(0)).clearAll();
         verify(partitionServiceCache, times(1)).get(any());
     }
 
@@ -131,6 +132,7 @@ public class CachedPartitionServiceImplTest {
         verify(partitionServiceImpl, times(1)).deletePartition(partId);
         verify(partitionServiceCache, times(1)).delete(partId);
         verify(partitionServiceCache, times(1)).get(partId);
+        verify(partitionListCache, times(1)).clearAll();
     }
 
     @Test
-- 
GitLab