#1227 - NPE when using L2 Query cache with findOne() or findOneOrEmpty()

This commit is contained in:
Rob Bygrave
2017-12-13 22:19:25 +13:00
parent e07bd8f736
commit 4a4134ee93
6 changed files with 56 additions and 18 deletions
+39 -1
View File
@@ -3,12 +3,17 @@ package org.tests.cache;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.EbeanServer;
import org.tests.model.basic.EBasicVer;
import io.ebean.cache.ServerCache;
import io.ebean.cache.ServerCacheStatistics;
import org.junit.Test;
import org.tests.model.basic.EBasicVer;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class TestQueryCacheInsert extends BaseTestCase {
@@ -30,4 +35,37 @@ public class TestQueryCacheInsert extends BaseTestCase {
assertEquals(alist0.size() + 1, alist1.size());
}
@Test
public void findOne() {
EBasicVer doda = new EBasicVer("doda");
doda.setDescription("OddButUniqueSillyExample");
Ebean.save(doda);
ServerCache queryCache = Ebean.getServerCacheManager().getQueryCache(EBasicVer.class);
Optional<EBasicVer> found0 = Ebean.find(EBasicVer.class)
.where().eq("description", "OddButUniqueSillyExample")
.setUseQueryCache(true)
.findOneOrEmpty();
assertTrue(found0.isPresent());
assertHitMiss(0, 1, queryCache);
EBasicVer found1 = Ebean.find(EBasicVer.class)
.where().eq("description", "OddButUniqueSillyExample")
.setUseQueryCache(true)
.findOne();
assertNotNull(found1);
assertHitMiss(1, 0, queryCache);
}
private void assertHitMiss(int hits, int miss, ServerCache queryCache) {
ServerCacheStatistics stats = queryCache.getStatistics(true);
assertEquals(hits, stats.getHitCount());
assertEquals(miss, stats.getMissCount());
}
}