我正在运行基于Infinispan单元测试之一的简单测试用例。在我的测试中,我希望CacheException
在集群中的复制超时时收到。
我使用悲观事务锁定,并且在这种情况下由于某种原因不会引发异常。如果我评论悲观锁定,我会按预期得到异常。
@Test(groups = "functional", testName = "replication.ReplicationExceptionTest")
public class ReplicationExceptionTest extends MultipleCacheManagersTest {
protected void createCacheManagers() {
ConfigurationBuilder configuration = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true);
configuration.locking()
.lockAcquisitionTimeout(60000l)
.transaction().transactionManagerLookup(new DummyTransactionManagerLookup());
// uncomment this line and exception is not thrown for some reason
//.lockingMode(LockingMode.PESSIMISTIC);
createClusteredCaches(2, configuration);
waitForClusterToForm();
}
@Test(groups = "functional", expectedExceptions = { CacheException.class })
public void testSyncReplTimeout() {
AdvancedCache cache1 = cache(0).getAdvancedCache();
AdvancedCache cache2 = cache(1).getAdvancedCache();
cache2.addInterceptor(new CommandInterceptor() {
@Override
protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd)
throws Throwable {
// Add a delay
Thread.sleep(100);
return super.handleDefault(ctx, cmd);
}
}, 0);
cache1.getCacheConfiguration().clustering().sync().replTimeout(10);
cache2.getCacheConfiguration().clustering().sync().replTimeout(10);
TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
cache1.put("k", "v");
}
}
有人可以帮我理解为什么它在启用悲观锁定的情况下隐藏异常以及如何解决这个问题?
更新:我正在使用 Infinispan 5.3.0.Final。