From 84eda6b9d5f460198c22d807b900198a2956fc95 Mon Sep 17 00:00:00 2001 From: kamhung <22250530@qq.com> Date: Wed, 18 Nov 2015 16:19:17 +0800 Subject: [PATCH] --- .../redkale/test/source/CacheTestBean.java | 17 +-- .../redkale/test/source/TestSourceCache.java | 110 ++++++++++++++++++ 2 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 test/com/wentch/redkale/test/source/TestSourceCache.java diff --git a/test/com/wentch/redkale/test/source/CacheTestBean.java b/test/com/wentch/redkale/test/source/CacheTestBean.java index 6ba131166..2795ece58 100644 --- a/test/com/wentch/redkale/test/source/CacheTestBean.java +++ b/test/com/wentch/redkale/test/source/CacheTestBean.java @@ -9,13 +9,14 @@ import com.wentch.redkale.source.*; import com.wentch.redkale.source.DataSource.Reckon; import com.wentch.redkale.util.*; import java.util.*; +import javax.persistence.*; /** * * @author zhangjx */ public class CacheTestBean { - + @Id private long pkgid; private String name; @@ -31,15 +32,15 @@ public class CacheTestBean { Attribute idattr = Attribute.create(CacheTestBean.class, "pkgid"); Attribute nameattr = Attribute.create(CacheTestBean.class, "name"); Attribute priceattr = Attribute.create(CacheTestBean.class, "price"); - EntityCache cache = new EntityCache(CacheTestBean.class, Creator.create(CacheTestBean.class), idattr, null); + EntityCache cache = new EntityCache(EntityInfo.load(CacheTestBean.class, 0, true, null)); cache.fullLoad(list); - System.out.println(cache.getMapResult(idattr, Reckon.COUNT, nameattr, null)); - System.out.println(cache.getMapResult(idattr, Reckon.DISTINCTCOUNT, nameattr, null)); - System.out.println(cache.getMapResult(idattr, Reckon.AVG, priceattr, null)); - System.out.println(cache.getMapResult(idattr, Reckon.SUM, priceattr, null)); - System.out.println(cache.getMapResult(idattr, Reckon.MAX, priceattr, null)); - System.out.println(cache.getMapResult(idattr, Reckon.MIN, priceattr, null)); + System.out.println(cache.getMapResult("pkgid", Reckon.COUNT, "name", null,null)); + System.out.println(cache.getMapResult("pkgid", Reckon.DISTINCTCOUNT, "name", null,null)); + System.out.println(cache.getMapResult("pkgid", Reckon.AVG, "price", null,null)); + System.out.println(cache.getMapResult("pkgid", Reckon.SUM, "price", null,null)); + System.out.println(cache.getMapResult("pkgid", Reckon.MAX, "price", null,null)); + System.out.println(cache.getMapResult("pkgid", Reckon.MIN, "price", null,null)); } public CacheTestBean() { diff --git a/test/com/wentch/redkale/test/source/TestSourceCache.java b/test/com/wentch/redkale/test/source/TestSourceCache.java new file mode 100644 index 000000000..c7e193de8 --- /dev/null +++ b/test/com/wentch/redkale/test/source/TestSourceCache.java @@ -0,0 +1,110 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.wentch.redkale.test.source; + +import com.wentch.redkale.convert.json.*; +import com.wentch.redkale.source.*; +import com.wentch.redkale.util.*; +import java.util.concurrent.*; +import javax.persistence.*; + +/** + * + * @author zhangjx + */ +public class TestSourceCache { + + public static void main(String[] args) throws Exception { + final EntityInfo info = EntityInfo.load(TestEntity.class, 0, false, null); + TestEntity[] entitys = new TestEntity[10_0000]; + for (int i = 0; i < entitys.length; i++) { + entitys[i] = new TestEntity(i + 1, "用户_" + (i + 1)); + } + long s = System.currentTimeMillis(); + for (TestEntity en : entitys) { + info.getCache().insert(en); + } + long e = System.currentTimeMillis() - s; + System.out.println("插入十万条记录耗时: " + e / 1000.0 + " 秒"); + + s = System.currentTimeMillis(); + TestEntity one = info.getCache().find(9999); + e = System.currentTimeMillis() - s; + System.out.println("十万条数据中查询一条记录耗时: " + e / 1000.0 + " 秒 " + one); + + final Flipper flipper = new Flipper(2); + flipper.setSort("userid DESC, createtime DESC"); + final FilterNode node = FilterNode.create("userid", FilterExpress.GREATERTHAN, 1000).and("username", FilterExpress.LIKE, "用户"); + System.out.println("node = " + node); + Sheet sheet = info.getCache().querySheet(true, null, flipper, node, null); + final CountDownLatch cdl = new CountDownLatch(100); + s = System.currentTimeMillis(); + for (int i = 0; i < 100; i++) { + new Thread() { + @Override + public void run() { + for (int k = 0; k < 10; k++) { + info.getCache().querySheet(true, null, flipper, node, null); + } + cdl.countDown(); + } + }.start(); + } + cdl.await(); + e = System.currentTimeMillis() - s; + System.out.println("十万条数据中查询一页记录耗时: " + e / 1000.0 + " 秒 " + sheet); // CopyOnWriteArrayList 0.798 ConcurrentLinkedQueue 1.063 + } + + @VirtualEntity + @Cacheable + public static class TestEntity { + + @Id + private int userid; + + private String username; + + private long createtime = System.currentTimeMillis(); + + public TestEntity() { + + } + + public TestEntity(int userid, String username) { + this.userid = userid; + this.username = username; + } + + public int getUserid() { + return userid; + } + + public void setUserid(int userid) { + this.userid = userid; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public long getCreatetime() { + return createtime; + } + + public void setCreatetime(long createtime) { + this.createtime = createtime; + } + + @Override + public String toString() { + return JsonFactory.root().getConvert().convertTo(this); + } + } +}