Skip to content

Commit 45a4cb0

Browse files
committed
code coverage
1 parent b31f1f5 commit 45a4cb0

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

metadata-io/src/test/java/com/linkedin/metadata/search/client/CacheEvictionServiceTest.java

+47-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Map;
1515
import java.util.concurrent.Callable;
1616
import java.util.concurrent.TimeUnit;
17+
import org.javatuples.Octet;
1718
import org.javatuples.Septet;
1819
import org.jetbrains.annotations.NotNull;
1920
import org.springframework.cache.CacheManager;
@@ -33,8 +34,8 @@ public class CacheEvictionServiceTest {
3334

3435
int cacheKeyCount;
3536
// We cant use the spring Caffeine cache Manager in metadata-io due to a java 11 dependency --
36-
// this is not a problem
37-
// with the gms, but an issue with just the metadata-io jar and the associated unit tests.
37+
// this is not a problem with the gms, but an issue with just the metadata-io jar and the
38+
// associated unit tests.
3839
final Map<String, Cache> nativeCacheMapForCaffeine = new HashMap<>();
3940

4041
final String UNSUPPORTED_CACHE_NAME = "SampleUnsupportedCacheName";
@@ -53,6 +54,8 @@ void setupCacheManagers() {
5354
nativeCacheMapForCaffeine.put(
5455
ENTITY_SEARCH_SERVICE_SEARCH_CACHE_NAME, caffeine.build());
5556
nativeCacheMapForCaffeine.put(UNSUPPORTED_CACHE_NAME, caffeine.build());
57+
nativeCacheMapForCaffeine.put(
58+
ENTITY_SEARCH_SERVICE_SCROLL_CACHE_NAME, caffeine.build());
5659
}
5760

5861
@Override
@@ -119,7 +122,7 @@ void setupCacheManager() {
119122
Map<
120123
@NotNull Septet<Object, List<String>, String, String, Object, Object, Object>,
121124
@NotNull String>
122-
cacheData =
125+
searchCacheData =
123126
Map.of(
124127
Septet.with(
125128
null, // opContext
@@ -181,15 +184,49 @@ void setupCacheManager() {
181184
Cache cache =
182185
(Cache) cacheManager.getCache(ENTITY_SEARCH_SERVICE_SEARCH_CACHE_NAME).getNativeCache();
183186
cache.invalidateAll();
184-
for (Map.Entry entry : cacheData.entrySet()) {
187+
for (Map.Entry entry : searchCacheData.entrySet()) {
185188
cache.put(entry.getKey(), entry.getValue());
186189
}
187190

188-
cacheKeyCount = cacheData.size();
191+
Map<
192+
@NotNull Octet<
193+
Object, List<String>, String, String, Object, String, List<String>, Integer>,
194+
@NotNull String>
195+
scrollCacheData =
196+
Map.of(
197+
Octet.with(
198+
null, // opContext
199+
Arrays.asList("container", "dataset"), // entity matches but no urn in filter.
200+
"*", // query
201+
"{\"or\":[{\"and\":[{\"condition\":\"EQUAL\",\"negated\":false,\"field\":\"_entityType\",\"value\":\"\",\"values\":[\"CONTAINER\"]}]}]}",
202+
// filters
203+
null, // sort criteria
204+
"scrollid",
205+
Arrays.asList("some facet json"),
206+
1 /* querySize*/),
207+
"allcontainers",
208+
Octet.with(
209+
null, // opContext
210+
Arrays.asList("container", "dataset"), // entity matches but no urn in filter.
211+
"*", // query
212+
null, // filters
213+
null, // sort criteria
214+
"scrollid",
215+
Arrays.asList("some facet json"),
216+
1 /* querySize*/),
217+
"allcontainers-null-filter");
218+
219+
cacheKeyCount = searchCacheData.size();
220+
221+
cache = (Cache) cacheManager.getCache(ENTITY_SEARCH_SERVICE_SCROLL_CACHE_NAME).getNativeCache();
222+
cache.invalidateAll();
223+
for (Map.Entry entry : scrollCacheData.entrySet()) {
224+
cache.put(entry.getKey(), entry.getValue());
225+
}
189226

190227
cache = (Cache) cacheManager.getCache(UNSUPPORTED_CACHE_NAME).getNativeCache();
191228
cache.invalidateAll();
192-
for (Map.Entry entry : cacheData.entrySet()) {
229+
for (Map.Entry entry : searchCacheData.entrySet()) {
193230
cache.put(
194231
entry.getKey(),
195232
entry.getValue()); // oK to have the same values, this shouldn't even be looked up.
@@ -303,10 +340,12 @@ void testInvalidCache() {
303340
void testDisabledFlags() throws URISyntaxException {
304341
CacheEvictionService service = new CacheEvictionService(null, true, false);
305342
service.invalidateAll(); // should be no op though
306-
evictionService.evict(List.of(Urn.createFromString("urn:li:container:bar")));
343+
service.invalidate("anycache"); // should be no op
344+
service.evict(List.of(Urn.createFromString("urn:li:container:bar")));
307345

308346
service = new CacheEvictionService(null, false, true);
309347
service.invalidateAll(); // should be no op though
310-
evictionService.evict(List.of(Urn.createFromString("urn:li:container:bar")));
348+
service.invalidate("anycache"); // should be no op
349+
service.evict(List.of(Urn.createFromString("urn:li:container:bar")));
311350
}
312351
}

0 commit comments

Comments
 (0)