/**
*
*/
package com.alisoft.xplatform.asf.cache;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import com.alisoft.xplatform.asf.cache.memcached.CacheUtil;
import com.alisoft.xplatform.asf.cache.memcached.MemcacheStats;
import com.alisoft.xplatform.asf.cache.memcached.MemcacheStatsSlab;
import com.alisoft.xplatform.asf.cache.memcached.MemcachedCacheManager;
import com.alisoft.xplatform.asf.cache.memcached.MemcachedResponse;
import com.alisoft.xplatform.asf.cache.memcached.MemcacheStatsSlab.Slab;
/**
* @author wenchu.cenwc
*
*/
public class IMemcachedCacheTest
{
static ICacheManager<IMemcachedCache> manager;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception
{
manager = CacheUtil.getCacheManager(IMemcachedCache.class,
MemcachedCacheManager.class.getName());
manager.setConfigFile("memcached1.xml");
manager.setResponseStatInterval(5*1000);
manager.start();
}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception
{
manager.stop();
}
/**
* Test method for {@link com.alisoft.xplatform.asf.cache.ICache#get(java.lang.Object)}.
*/
@Test
public void testGet()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("key1");
cache.remove("key2你好");
cache.put("key1", "1");
cache.put("key2你好", "你好123");
Assert.assertEquals(cache.get("key1"),"1");
Assert.assertEquals(cache.get("key2你好"),"你好123");
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
/**
* Test method for {@link com.alisoft.xplatform.asf.cache.ICache#remove(java.lang.Object)}.
*/
@Test
public void testRemove()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("key1");
cache.put("key1", "value1");
Assert.assertEquals(cache.get("key1"),"value1");
cache.remove("key1");
Assert.assertNull(cache.get("key1"));
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
@Test
public void testKeysetValues()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.clear();
Thread.sleep(2000);
cache.put("key1", "value1");
cache.put("key2", "value2");
Set<String> keys = cache.keySet(false);
String[] c = new String[2];
keys.toArray(c);
if ((c[0].equals("key1")&&c[1].equals("key2"))
||(c[0].equals("key2")&&c[1].equals("key1")))
Assert.assertTrue(true);
else
Assert.assertTrue(false);
cache.values().toArray(c);
if ((c[0].equals("value1")&&c[1].equals("value2"))
||(c[0].equals("value1")&&c[1].equals("value2")))
Assert.assertTrue(true);
else
Assert.assertTrue(false);
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
@Test
public void testcontainsKey()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("key1");
cache.put("key1", "value1");
Assert.assertTrue(cache.containsKey("key1"));
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
/**
* Test method for {@link com.alisoft.xplatform.asf.cache.IMemcachedCache#get(java.lang.String, int)}.
*/
@Test
public void testGetStringInt()
{
try
{
IMemcachedCache cache1 = manager.getCache("mclient1");
IMemcachedCache cache2 = manager.getCache("mclient2");
cache1.remove("key1");
cache1.remove("key2");
cache2.remove("key1");
cache2.remove("key2");
cache1.put("key1", "value1");
cache1.put("key2", "value2");
Assert.assertEquals(cache1.get("key1",30),"value1");
Assert.assertEquals(cache1.get("key2"),"value2");
Assert.assertEquals(cache2.get("key1",30),"value1");
Assert.assertEquals(cache2.get("key2"),"value2");
cache1.put("key1", "value3");
Assert.assertEquals(cache1.get("key1",30),"value3");
Assert.assertEquals(cache2.get("key1",30),"value1");
Assert.assertEquals(cache2.get("key1"),"value3");
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
@Test
public void testgetMulti()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("key1");
cache.remove("key2");
cache.put("key1", "value1");
cache.put("key2", "value2");
Map<String,Object> result = cache.getMulti(new String[]{"key1","key2"});
Assert.assertEquals(result.get("key1"), "value1");
Assert.assertEquals(result.get("key2"), "value2");
Object[] values = cache.getMultiArray(new String[]{"key1","key2"});
if ((values[0].equals("value1") && values[1].equals("value2"))
||(values[0].equals("value1") && values[1].equals("value2")))
Assert.assertTrue(true);
else
Assert.assertTrue(false);
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
/**
* Test method for {@link com.alisoft.xplatform.asf.cache.IMemcachedCache#incr(java.lang.String, long)}.
*/
@Test
public void testIncr()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("counter");
cache.storeCounter("counter", 20);
Assert.assertEquals(cache.incr("counter", 11),31);
cache.remove("counter");
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
/**
* Test method for {@link com.alisoft.xplatform.asf.cache.IMemcachedCache#decr(java.lang.String, long)}.
*/
@Test
public void testDecr()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("counter");
cache.storeCounter("counter", 20);
Assert.assertEquals(cache.decr("counter", 11),9);
cache.remove("counter");
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
/**
* Test method for {@link com.alisoft.xplatform.asf.cache.IMemcachedCache#addOrIncr(java.lang.String, long)}.
*/
@Test
public void testAddOrIncr()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("counter");
Assert.assertEquals(cache.addOrIncr("counter", 20),20);
Assert.assertEquals(cache.addOrIncr("counter", 20),40);
cache.remove("counter");
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
/**
* Test method for {@link com.alisoft.xplatform.asf.cache.IMemcachedCache#addOrDecr(java.lang.String, long)}.
*/
@Test
public void testAddOrDecr()
{
try
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("counter");
Assert.assertEquals(cache.addOrDecr("counter", 20),20);
Assert.assertEquals(cache.addOrDecr("counter", 10),10);
cache.remove("counter");
}
catch(Exception ex)
{
ex.printStackTrace();
Assert.assertTrue(false);
}
}
/**
* Test method for {@link com.alisoft.xplatform.asf.cache.IMemcachedCache#statsSlabs()}.
*/
@Test
public void testStatsSlabs()
{
IMemcachedCache cache = manager.getCache("mclient0");
cache.remove("key1");
cache.remove("key2");
cache.remove("key3");
cache.remove("key4");
cache.remove("key5");
cache.remove("key6");
cache.put("key1", "value1");
cache.put("key2", "value
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
cache-demo-2.5.zip (55个子文件)
conf.test
memcached_cluster.xml 3KB
META-INF
services
.svn
all-wcprops 144B
prop-base
props
tmp
prop-base
props
text-base
text-base
entries 396B
format 2B
.svn
all-wcprops 134B
prop-base
props
tmp
prop-base
props
text-base
text-base
entries 315B
format 2B
memcached_cluster3.xml 3KB
memcached.xml 2KB
memcached_cluster2.xml 985B
memcached1.xml 2KB
.svn
all-wcprops 947B
prop-base
props
tmp
prop-base
props
text-base
text-base
memcached_cluster3.xml.svn-base 3KB
memcached.xml.svn-base 2KB
memcached1.xml.svn-base 2KB
memcached_cluster2.xml.svn-base 985B
memcached_cluster.xml.svn-base 3KB
entries 1012B
format 2B
java.test
com
alisoft
xplatform
asf
cache
MemcachedClusterTest.java 8KB
Node.java 769B
memcached
MemcachedCacheManagerTest.java 772B
.svn
all-wcprops 398B
prop-base
props
tmp
prop-base
props
text-base
text-base
MemcachedCacheManagerTest.java.svn-base 772B
entries 481B
format 2B
StressCacheTest.java 3KB
IMemcachedCacheTest.java 17KB
.svn
all-wcprops 954B
prop-base
props
tmp
prop-base
props
text-base
text-base
IMemcachedCacheTest.java.svn-base 17KB
StressCacheTest.java.svn-base 3KB
MemcachedClusterTest.java.svn-base 8KB
Node.java.svn-base 769B
entries 924B
format 2B
impl
DefaultCacheImplTest.java 3KB
.svn
all-wcprops 378B
prop-base
props
tmp
prop-base
props
text-base
text-base
DefaultCacheImplTest.java.svn-base 3KB
entries 471B
format 2B
.svn
all-wcprops 152B
prop-base
props
tmp
prop-base
props
text-base
text-base
entries 329B
format 2B
.svn
all-wcprops 148B
prop-base
props
tmp
prop-base
props
text-base
text-base
entries 323B
format 2B
.svn
all-wcprops 137B
prop-base
props
tmp
prop-base
props
text-base
text-base
entries 319B
format 2B
.svn
all-wcprops 129B
prop-base
props
tmp
prop-base
props
text-base
text-base
entries 309B
format 2B
.svn
all-wcprops 125B
prop-base
props
tmp
prop-base
props
text-base
text-base
entries 301B
format 2B
共 55 条
- 1
资源评论
我虽横行却不霸道
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功