This commit is contained in:
kamhung
2015-11-18 16:19:17 +08:00
parent 4e62627ebc
commit 84eda6b9d5
2 changed files with 119 additions and 8 deletions

View File

@@ -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<CacheTestBean> cache = new EntityCache(CacheTestBean.class, Creator.create(CacheTestBean.class), idattr, null);
EntityCache<CacheTestBean> 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() {

View File

@@ -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<TestEntity> 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<TestEntity> 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);
}
}
}