From 63f5de364ee7383ac60933a7fb29b03c856b6e19 Mon Sep 17 00:00:00 2001 From: godotg Date: Thu, 23 May 2024 17:01:40 +0800 Subject: [PATCH] test[orm]: entity cache test --- .../com/zfoo/orm/cache/EntityCachesTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/orm/src/test/java/com/zfoo/orm/cache/EntityCachesTest.java b/orm/src/test/java/com/zfoo/orm/cache/EntityCachesTest.java index c7a04030..43d920bd 100644 --- a/orm/src/test/java/com/zfoo/orm/cache/EntityCachesTest.java +++ b/orm/src/test/java/com/zfoo/orm/cache/EntityCachesTest.java @@ -23,6 +23,8 @@ import org.junit.Ignore; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; +import java.util.ArrayList; + /** * @author godotg @@ -35,6 +37,13 @@ public class EntityCachesTest { public void test() { var context = new ClassPathXmlApplicationContext("application.xml"); + // 每次运行前先删除数据库 + var collection = OrmContext.getOrmManager().getCollection(UserEntity.class); + collection.drop(); + + // 再插入 + batchInsert(); + // 动态去拿到UserEntity的EntityCaches @SuppressWarnings("unchecked") var userEntityCaches = (IEntityCache) OrmContext.getOrmManager().getEntityCaches(UserEntity.class); @@ -62,4 +71,13 @@ public class EntityCachesTest { ThreadUtils.sleep(Long.MAX_VALUE); } + public void batchInsert() { + var listUser = new ArrayList(); + for (var i = 1; i <= 10; i++) { + var userEntity = new UserEntity(i, (byte) 1, (short) i, i, true, "helloOrm" + i, "helloOrm" + i); + listUser.add(userEntity); + } + OrmContext.getAccessor().batchInsert(listUser); + } + }