diff --git a/orm/src/test/java/com/zfoo/orm/cache/OrmTest.java b/orm/src/test/java/com/zfoo/orm/cache/OrmTest.java deleted file mode 100644 index 386f8c60..00000000 --- a/orm/src/test/java/com/zfoo/orm/cache/OrmTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2020 The zfoo Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - */ - -package com.zfoo.orm.cache; - -import com.zfoo.protocol.util.ThreadUtils; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * @author godotg - */ -@Ignore -public class OrmTest { - - @Test - public void test() { - var context = new ClassPathXmlApplicationContext("application.xml"); - - // 通过注解自动注入的方式去拿到UserEntity的EntityCaches - var userEntityCaches = context.getBean(UserManager.class).userEntityCaches; - - for (int i = 1; i <= 10; i++) { - var entity = userEntityCaches.load((long) i); - entity.setE("update" + i); - entity.setC(i); - userEntityCaches.update(entity); - } - - ThreadUtils.sleep(Long.MAX_VALUE); - } - -} diff --git a/orm/src/test/java/com/zfoo/orm/cache/UserManager.java b/orm/src/test/java/com/zfoo/orm/cache/UserManager.java index a2304637..a788fe03 100644 --- a/orm/src/test/java/com/zfoo/orm/cache/UserManager.java +++ b/orm/src/test/java/com/zfoo/orm/cache/UserManager.java @@ -15,6 +15,8 @@ package com.zfoo.orm.cache; import com.zfoo.orm.anno.EntityCacheAutowired; import com.zfoo.orm.entity.UserEntity; +import com.zfoo.orm.entity.wrapper.*; +import org.bson.types.ObjectId; import org.springframework.stereotype.Component; /** @@ -25,5 +27,17 @@ public class UserManager { @EntityCacheAutowired public IEntityCache userEntityCaches; + @EntityCacheAutowired + public IEntityCache intEntityCaches; + @EntityCacheAutowired + public IEntityCache longEntityCaches; + @EntityCacheAutowired + public IEntityCache floatEntityCaches; + @EntityCacheAutowired + public IEntityCache doubleEntityCaches; + @EntityCacheAutowired + public IEntityCache stringEntityCaches; + @EntityCacheAutowired + public IEntityCache objectIdEntityCaches; } diff --git a/orm/src/test/java/com/zfoo/orm/cache/WrapperTest.java b/orm/src/test/java/com/zfoo/orm/cache/WrapperTest.java new file mode 100644 index 00000000..c6f2a943 --- /dev/null +++ b/orm/src/test/java/com/zfoo/orm/cache/WrapperTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2020 The zfoo Authors + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + */ + +package com.zfoo.orm.cache; + +import com.zfoo.orm.OrmContext; +import com.zfoo.orm.entity.wrapper.*; +import com.zfoo.protocol.util.StringUtils; +import com.zfoo.protocol.util.ThreadUtils; +import com.zfoo.scheduler.util.TimeUtils; +import org.bson.types.ObjectId; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; + + +/** + * @author godotg + */ +@Ignore +public class WrapperTest { + + @Test + public void wrapperTest() { + var context = new ClassPathXmlApplicationContext("application.xml"); + + // 每次运行前先删除数据库 + OrmContext.getOrmManager().getCollection(IntEntity.class).drop(); + OrmContext.getOrmManager().getCollection(LongEntity.class).drop(); + OrmContext.getOrmManager().getCollection(FloatEntity.class).drop(); + OrmContext.getOrmManager().getCollection(DoubleEntity.class).drop(); + OrmContext.getOrmManager().getCollection(StringEntity.class).drop(); + OrmContext.getOrmManager().getCollection(ObjectIdEntity.class).drop(); + + var userManager = OrmContext.getApplicationContext().getBean(UserManager.class); + var intEntityCaches = userManager.intEntityCaches; + var longEntityCaches = userManager.longEntityCaches; + var floatEntityCaches = userManager.floatEntityCaches; + var doubleEntityCaches = userManager.doubleEntityCaches; + var stringEntityCaches = userManager.stringEntityCaches; + var objectIdEntityCaches = userManager.objectIdEntityCaches; + + for (var i = 1; i < 10; i++) { + for (var j = 1; j < 10; j++) { + var intEntity = intEntityCaches.loadOrCreate(j); + intEntity.setMessage(StringUtils.format("update-{}-{}", i, j)); + intEntityCaches.update(intEntity); + + var longEntity = longEntityCaches.loadOrCreate((long) j); + longEntity.setMessage(StringUtils.format("update-{}-{}", i, j)); + longEntityCaches.update(longEntity); + + var floatEntity = floatEntityCaches.loadOrCreate(Float.valueOf(i + "." + j)); + floatEntity.setMessage(StringUtils.format("update-{}-{}", i, j)); + floatEntityCaches.update(floatEntity); + + var doubleEntity = doubleEntityCaches.loadOrCreate(Double.valueOf(i + "." + j)); + doubleEntity.setMessage(StringUtils.format("update-{}-{}", i, j)); + doubleEntityCaches.update(doubleEntity); + + var stringEntity = stringEntityCaches.loadOrCreate(String.valueOf(j)); + stringEntity.setMessage(StringUtils.format("update-{}-{}", i, j)); + stringEntityCaches.update(stringEntity); + + var objectIdEntity = objectIdEntityCaches.loadOrCreate(new ObjectId(String.valueOf(j).repeat(24))); + objectIdEntity.setMessage(StringUtils.format("update-{}-{}", i, j)); + objectIdEntityCaches.update(objectIdEntity); + } + + ThreadUtils.sleep(60 * TimeUtils.MILLIS_PER_SECOND); + } + + ThreadUtils.sleep(60 * TimeUtils.MILLIS_PER_SECOND); + } + +}