伙计们!我有一个新问题要问你。我正在使用不同的缓存管理器将一些数据添加到缓存中,但我正面临着它的问题。我正在使用junit和spring来做。当我运行测试时,测试方法是随机执行的,但我需要它们按顺序执行。怎么做??这是一些代码和验证控制台输出:
服务等级:
@Service("HelloCache")
public class CacheServiceImpl implements CacheInterface {
@Autowired
@Qualifier("memcachedClient")
private MemcachedClient mBean;
public void Add(String key, Object object) {
mBean.set(key, 12, object);
}
public void Get(String key) {
mBean.get(key);
}
public void Delete(String key) {
mBean.delete(key);
}
}
这是测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "file:src/main/java/spring.xml")
public class UsingMemcachedTest extends TestCase {
@Autowired
@Qualifier("HelloCache")
private CacheInterface emcached;
private byte[][] i = new byte[2500][3000];
private String key = "j";
@Test
public void testAddBulkObjects() {
System.out.println("");
System.out.println("This is async BULK adding test");
long time = System.currentTimeMillis();
for (int k=1; k<=1000; k++) {
emcached.Add(key+k, i);
}
long time2 = System.currentTimeMillis();
long timeE=time2-time;
System.out.println("Vremya add BULK objects: " + timeE);
System.out.println("");
}
@Test
public void testGetBulkObjects() {
System.out.println("");
System.out.println("This is getting BULK objects test");
long time = System.currentTimeMillis();
for (int k=1; k<=1000; k++) {
emcached.Get(key+k);
}
long time2 = System.currentTimeMillis();
long timeE=time2-time;
System.out.println("Vremya Get object: " + timeE);
System.out.println("");
}
@Test
public void testDeleteBulkObjects() {
System.out.println("");
System.out.println("This is deleting BULK objects test");
long time = System.currentTimeMillis();
for (int k=1; k<=1000; k++) {
emcached.Delete(key+k);
}
long time2 = System.currentTimeMillis();
long timeE=time2-time;
System.out.println("Vremya delete object: " + timeE);
System.out.println("");
}
和输出:
This is deleting BULK objects test
Vremya delete object: 137
This is getting BULK objects test
Vremya Get object: 703
This is async BULK adding test
Vremya add BULK objects: 87681
请帮忙!!=)