以下集成测试方法 testLocalPaging 使用 HSQL 内存数据库,Stock 表中有 100 个条目。存储库类是使用 Spring Data JPA 实现的,它只是一个扩展 PagingAndSortingRepository 的接口。但是,当页数设置为 15 或以下时,测试将“冻结”在第六页。我意识到从数据库中读取大约 6 页后测试会卡住。但是,如果我使用更大的页面大小,例如 20,则测试运行得很好,五页后从数据库中读取的所有 100 个条目都没有问题。我想知道某个地方的 Spring Data JPA 是否存在错误?我注意到导致问题的行在 org.springframework.aop.framework.JdkDynamicAopProxy 的第 202 行。我正在使用 spring-data-jpa-1.4.1.RELEASE,spring-aop-3.1.4。RELEASE 和 hibernate-core-3.6.10.Final 等。有人可以指出我的测试中是否有问题,或者 Spring 或 Hibernate 中是否有问题?我对测试结果感到很困惑。
StockDaoJpa:
import org.springframework.data.repository.PagingAndSortingRepository;
public interface StockDaoJpa extends PagingAndSortingRepository<Stock, Long>{
}
测试方法:
@Test
public void testLocalPaging()
{
log.info("testLocalPaging()...");
int size = 10;
Page<Stock> page = null;
Pageable request = new PageRequest(0, size, new Sort(new Order("StockId")));
do
{
if(page == null)
page = stockRepository.findAll(request);
else
{
request = page.nextPageable();
log.info(request);
//TODO: It freezes at the sixth request whatever the pagesize is.
page = stockRepository.findAll(request);
}
log.info(page);
for(Stock s : page)
log.info(String.format("Id = %s", s.getStockId()));
log.info(page.hasNextPage());
} while(page.hasNextPage());
}
测试停留在的 JdkDynamicAopProxy 类中的代码:
...
else {
// We need to create a method invocation...
invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
// Proceed to the joinpoint through the interceptor chain.
retVal = invocation.proceed();
}
...
从 testLocalPaing 输出:
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 63 | testLocalPaging()...
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 78 | Page 0 of 10 containing jstat.sample.Stock instances
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 1
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 2
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 3
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 4
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 5
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 6
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 7
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 8
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 9
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 80 | Id = 10
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 81 | true
[INFO ] | 20:38:22 | [mainhread] | ConfigTest 74 | Page request [number: 1, size 10, sort: StockId: ASC]
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 78 | Page 1 of 10 containing jstat.sample.Stock instances
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 11
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 12
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 13
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 14
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 15
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 16
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 17
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 18
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 19
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 80 | Id = 20
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 81 | true
[INFO ] | 20:38:26 | [mainhread] | ConfigTest 74 | Page request [number: 2, size 10, sort: StockId: ASC]
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 78 | Page 2 of 10 containing jstat.sample.Stock instances
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 21
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 22
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 23
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 24
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 25
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 26
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 27
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 28
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 29
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 80 | Id = 30
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 81 | true
[INFO ] | 20:38:28 | [mainhread] | ConfigTest 74 | Page request [number: 3, size 10, sort: StockId: ASC]
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 78 | Page 3 of 10 containing jstat.sample.Stock instances
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 31
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 32
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 33
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 34
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 35
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 36
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 37
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 38
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 39
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 80 | Id = 40
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 81 | true
[INFO ] | 20:38:29 | [mainhread] | ConfigTest 74 | Page request [number: 4, size 10, sort: StockId: ASC]
[INFO ] | 20:39:09 | [mainhread] | ConfigTest 78 | Page 4 of 10 containing jstat.sample.Stock instances
[INFO ] | 20:39:10 | [mainhread] | ConfigTest 80 | Id = 41
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 42
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 43
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 44
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 45
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 46
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 47
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 48
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 49
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 80 | Id = 50
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 81 | true
[INFO ] | 20:39:12 | [mainhread] | ConfigTest 74 | Page request [number: 5, size 10, sort: StockId: ASC]
[INFO ] | 20:39:31 | [mainhread] | ConfigTest 78 | Page 5 of 10 containing jstat.sample.Stock instances
[INFO ] | 20:39:35 | [mainhread] | ConfigTest 80 | Id = 51
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 52
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 53
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 54
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 55
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 56
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 57
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 58
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 59
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 80 | Id = 60
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 81 | true
[INFO ] | 20:39:38 | [mainhread] | ConfigTest 74 | Page request [number: 6, size 10, sort: StockId: ASC]