use of org.apache.ignite.cache.CacheInterceptor in project ignite by apache.
the class IgniteTxStateImpl method hasInterceptor.
/**
* {@inheritDoc}
*/
@Override
public boolean hasInterceptor(GridCacheSharedContext cctx) {
for (int i = 0; i < activeCacheIds.size(); i++) {
int cacheId = activeCacheIds.get(i);
CacheInterceptor interceptor = cctx.cacheContext(cacheId).config().getInterceptor();
if (interceptor != null)
return true;
}
return false;
}
use of org.apache.ignite.cache.CacheInterceptor in project ignite by apache.
the class GridCacheInterceptorAbstractSelfTest method testCancelUpdate.
/**
* @param key Key.
* @param op Operation type.
* @throws Exception If failed.
*/
private void testCancelUpdate(String key, Operation op) throws Exception {
// Interceptor returns null to disabled update.
CacheInterceptor retInterceptor = new NullPutInterceptor();
interceptor.retInterceptor = retInterceptor;
// Execute update when value is null, it should not change cache value.
log.info("Update 1 " + op);
update(0, op, key, 1, null);
checkCacheValue(key, null);
// Check values passed to interceptor.
assertEquals(1, interceptor.beforePutMap.size());
IgniteBiTuple t = interceptor.beforePutMap.get(key);
assertEquals(null, t.get1());
assertEquals(1, t.get2());
// Disable interceptor and update cache.
interceptor.reset();
interceptor.disabled = true;
clearCaches();
jcache(0).put(key, 1);
checkCacheValue(key, 1);
// Execute update when value is not null, it should not change cache value.
interceptor.disabled = false;
interceptor.retInterceptor = retInterceptor;
log.info("Update 2 " + op);
update(0, op, key, 2, 1);
checkCacheValue(key, 1);
// Check values passed to interceptor.
assertEquals(1, interceptor.beforePutMap.size());
t = interceptor.beforePutMap.get(key);
assertEquals(1, t.get1());
assertEquals(2, t.get2());
}
use of org.apache.ignite.cache.CacheInterceptor in project ignite by apache.
the class GridCacheInterceptorAbstractSelfTest method testModifyUpdate.
/**
* @param key Key.
* @param op Operation type.
* @throws Exception If failed.
*/
private void testModifyUpdate(String key, Operation op) throws Exception {
// Interceptor returns incremented new value.
CacheInterceptor retInterceptor = new PutIncrementInterceptor();
// Execute update when value is null.
interceptor.retInterceptor = retInterceptor;
log.info("Update 1 " + op);
update(0, op, key, 1, null);
checkCacheValue(key, 2);
// Check values passed to interceptor.
assertEquals(1, interceptor.beforePutMap.size());
IgniteBiTuple t = interceptor.beforePutMap.get(key);
assertEquals(null, t.get1());
assertEquals(1, t.get2());
assertEquals(1, interceptor.afterPutMap.size());
assertEquals(2, interceptor.afterPutMap.get(key));
// Execute update when value is not null.
interceptor.reset();
interceptor.retInterceptor = retInterceptor;
log.info("Update 2 " + op);
update(0, op, key, 3, 2);
checkCacheValue(key, 4);
// Check values passed to interceptor.
assertEquals(1, interceptor.beforePutMap.size());
t = interceptor.beforePutMap.get(key);
assertEquals(2, t.get1());
assertEquals(3, t.get2());
assertEquals(1, interceptor.afterPutMap.size());
assertEquals(4, interceptor.afterPutMap.get(key));
}
Aggregations