@Test
public void get_witValueLoaderAndNonExistingValue_createsValueFromValueLoaderAndStoresItInCache() throws Exception {
//Arrange
MemcachedClientIF client = mock(MemcachedClientIF.class);
SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test");
cache.setExpiration(42);
when(client.set("myKey", 42, "createdValue")).thenReturn(new AsyncResult<>(true));
//Act
String value = cache.get("myKey", () -> "createdValue");
//Assert
assertEquals("createdValue", value);
}
java类org.springframework.scheduling.annotation.AsyncResult的实例源码
SimpleSpringMemcachedTest.java 文件源码
项目:spring-cloud-aws
阅读 15
收藏 0
点赞 0
评论 0
TaskService.java 文件源码
项目:apidoc
阅读 29
收藏 0
点赞 0
评论 0
@Async
public Future<Integer> test(int i, int size, Date start) {
try
{
Thread.sleep(33);
}
catch(Exception e)
{
e.printStackTrace();
}
if (0 == i %2) {
throw new RuntimeException("test");
}
System.out.println(i);
return new AsyncResult<Integer>(i);
}
DataService.java 文件源码
项目:canal-mongo
阅读 24
收藏 0
点赞 0
评论 0
@Async("myTaskAsyncPool")
public Future<Integer> doAsyncTask(String tableName, List<EventData> dataList, String destination) {
try {
MDC.put("destination", destination);
logger.info("thread: " + Thread.currentThread().getName() + " is doing job :" + tableName);
for (EventData eventData : dataList) {
SpringUtil.doEvent(eventData.getPath(), eventData.getDbObject());
}
} catch (Exception e) {
logger.error("thread:" + Thread.currentThread().getName() + " get Exception", e);
return new AsyncResult(0);
}
return new AsyncResult(1);
}
EmployeeServiceImpl.java 文件源码
项目:Spring-5.0-Cookbook
阅读 27
收藏 0
点赞 0
评论 0
@Async
public Future<Employee> readEmployee(Integer empId) {
try {
System.out.println("service:readEmployee(empid) task executor: " + Thread.currentThread().getName());
System.out.println("processing for 2000 ms");
System.out.println("readEmployee @Async login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return new AsyncResult<>(employeeDaoImpl.getEmployee(empId));
}
EmployeeServiceImpl.java 文件源码
项目:Spring-5.0-Cookbook
阅读 25
收藏 0
点赞 0
评论 0
@Async
public Future<Employee> readEmployee(Integer empId) {
try {
System.out.println("service:readEmployee(empid) task executor: " + Thread.currentThread().getName());
System.out.println("processing for 2000 ms");
System.out.println("readEmployee @Async login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return new AsyncResult<>(employeeDaoImpl.getEmployee(empId));
}
EmployeeServiceImpl.java 文件源码
项目:Spring-5.0-Cookbook
阅读 27
收藏 0
点赞 0
评论 0
@Async
public Future<Employee> readEmployee(Integer empId) {
try {
System.out.println("service:readEmployee(empid) task executor: " + Thread.currentThread().getName());
System.out.println("processing for 2000 ms");
System.out.println("readEmployee @Async login: " + SecurityContextHolder.getContext().getAuthentication().getPrincipal());
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return new AsyncResult<>(employeeDaoImpl.getEmployee(empId));
}
AsyncTest.java 文件源码
项目:My-Blog
阅读 35
收藏 0
点赞 0
评论 0
@Async
Future<String> doTaskOne() throws Exception {
System.out.println("开始做任务一");
long start = System.currentTimeMillis();
Thread.sleep(random.nextInt(10000));
long end = System.currentTimeMillis();
System.out.println("完成任务一,耗时:" + (end - start) + "毫秒");
return new AsyncResult<>("任务一OK");
}
AsyncTest.java 文件源码
项目:My-Blog
阅读 32
收藏 0
点赞 0
评论 0
@Async
Future<String> doTaskTwo() throws Exception {
System.out.println("开始做任务二");
long start = System.currentTimeMillis();
Thread.sleep(random.nextInt(10000));
long end = System.currentTimeMillis();
System.out.println("完成任务二,耗时:" + (end - start) + "毫秒");
return new AsyncResult<>("任务二OK");
}
AsyncTest.java 文件源码
项目:My-Blog
阅读 29
收藏 0
点赞 0
评论 0
@Async
Future<String> doTaskThree() throws Exception {
System.out.println("开始做任务三");
long start = System.currentTimeMillis();
Thread.sleep(random.nextInt(10000));
long end = System.currentTimeMillis();
System.out.println("完成任务三,耗时:" + (end - start) + "毫秒");
return new AsyncResult<>("任务三OK");
}
ProcessModelServiceImpl.java 文件源码
项目:IPPR2016
阅读 16
收藏 0
点赞 0
评论 0
@Override
@Async
public Future<List<ProcessModelDTO>> findActiveProcessModels(final Pageable pageable) {
final List<ProcessModelImpl> results = processModelRepository.findActiveProcesses();
final List<ProcessModelDTO> processModels = createProcessModelDTO(results);
return new AsyncResult<List<ProcessModelDTO>>(processModels);
}