abhishekrb19 commented on code in PR #17212:
URL: https://github.com/apache/druid/pull/17212#discussion_r1800527688
##########
extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/LoadingLookupTest.java:
##########
@@ -73,14 +75,24 @@ public void testUnapplyNull()
}
@Test
- public void testApply() throws ExecutionException
+ public void testApply()
{
- EasyMock.expect(lookupCache.get(EasyMock.eq("key"),
EasyMock.anyObject(Callable.class))).andReturn("value").once();
+
EasyMock.expect(lookupCache.getIfPresent(EasyMock.eq("key"))).andReturn("value").once();
EasyMock.replay(lookupCache);
Assert.assertEquals(ImmutableMap.of("key", "value"),
loadingLookup.applyAll(ImmutableSet.of("key")));
EasyMock.verify(lookupCache);
}
+ @Test
+ public void testApplyWithNullCase()
Review Comment:
```suggestion
public void testApplyWithNullValue()
```
##########
extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/LoadingLookupTest.java:
##########
@@ -73,14 +75,24 @@ public void testUnapplyNull()
}
@Test
- public void testApply() throws ExecutionException
+ public void testApply()
{
- EasyMock.expect(lookupCache.get(EasyMock.eq("key"),
EasyMock.anyObject(Callable.class))).andReturn("value").once();
+
EasyMock.expect(lookupCache.getIfPresent(EasyMock.eq("key"))).andReturn("value").once();
EasyMock.replay(lookupCache);
Assert.assertEquals(ImmutableMap.of("key", "value"),
loadingLookup.applyAll(ImmutableSet.of("key")));
EasyMock.verify(lookupCache);
}
+ @Test
+ public void testApplyWithNullCase()
+ {
+
EasyMock.expect(lookupCache.getIfPresent(EasyMock.eq("key"))).andReturn("value").once();
Review Comment:
I think you probably want this:
```suggestion
EasyMock.expect(lookupCache.getIfPresent(EasyMock.eq("key"))).andReturn(null).once();
```
##########
extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/LoadingLookupTest.java:
##########
@@ -73,14 +75,24 @@ public void testUnapplyNull()
}
@Test
- public void testApply() throws ExecutionException
+ public void testApply()
{
- EasyMock.expect(lookupCache.get(EasyMock.eq("key"),
EasyMock.anyObject(Callable.class))).andReturn("value").once();
+
EasyMock.expect(lookupCache.getIfPresent(EasyMock.eq("key"))).andReturn("value").once();
EasyMock.replay(lookupCache);
Assert.assertEquals(ImmutableMap.of("key", "value"),
loadingLookup.applyAll(ImmutableSet.of("key")));
EasyMock.verify(lookupCache);
}
+ @Test
+ public void testApplyWithNullCase()
+ {
+
EasyMock.expect(lookupCache.getIfPresent(EasyMock.eq("key"))).andReturn("value").once();
+ EasyMock.expect(dataFetcher.fetch("key")).andReturn(null).once();
+ EasyMock.replay(lookupCache, dataFetcher);
+ Assert.assertNull(loadingLookup.apply("key"));
Review Comment:
Since the `lookupCache` has `key` -> `value` mapping, this should _not_ be
null right?
##########
extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/LoadingLookupTest.java:
##########
@@ -73,14 +75,24 @@ public void testUnapplyNull()
}
@Test
- public void testApply() throws ExecutionException
+ public void testApply()
{
- EasyMock.expect(lookupCache.get(EasyMock.eq("key"),
EasyMock.anyObject(Callable.class))).andReturn("value").once();
+
EasyMock.expect(lookupCache.getIfPresent(EasyMock.eq("key"))).andReturn("value").once();
EasyMock.replay(lookupCache);
Assert.assertEquals(ImmutableMap.of("key", "value"),
loadingLookup.applyAll(ImmutableSet.of("key")));
EasyMock.verify(lookupCache);
}
+ @Test
+ public void testApplyWithNullCase()
+ {
+
EasyMock.expect(lookupCache.getIfPresent(EasyMock.eq("key"))).andReturn("value").once();
+ EasyMock.expect(dataFetcher.fetch("key")).andReturn(null).once();
+ EasyMock.replay(lookupCache, dataFetcher);
+ Assert.assertNull(loadingLookup.apply("key"));
+ EasyMock.verify(lookupCache, dataFetcher);
Review Comment:
Could you add a test to verify the following scenario:
1. apply("key"): cache miss and load "key" from the `dataFetcher`
2. apply("key"): cache hit and lot "key" directly from the `lookupCache`
Verifies that subsequent calls to `apply()` with the same key becomes a
cache hit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]