use of org.apache.ignite.cache.CacheEntryProcessor in project ignite by apache.
the class IgniteClientReconnectApiExceptionTest method cacheOperationsTest.
/**
* @throws Exception If failed.
*/
private void cacheOperationsTest() throws Exception {
final Ignite client = startClientGrid(serverCount());
final IgniteCache<Object, Object> dfltCache = client.cache(DEFAULT_CACHE_NAME);
assertNotNull(dfltCache);
doTestIgniteOperationOnDisconnect(client, Arrays.asList(// Check put and get operation.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
dfltCache.getAndPut(9999, 9999);
} catch (CacheException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return dfltCache.getAndPut(9999, 9999);
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNull(o);
assertEquals(9999, dfltCache.get(9999));
return true;
}
}), // Check put operation.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
dfltCache.put(10000, 10000);
} catch (CacheException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
dfltCache.put(10000, 10000);
return true;
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertTrue((Boolean) o);
assertEquals(10000, dfltCache.get(10000));
return true;
}
}), // Check get operation.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
dfltCache.get(10001);
} catch (CacheException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return dfltCache.get(10001);
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNull(o);
return true;
}
}), // Check put and invoke operation.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
dfltCache.put(CACHE_PUT_INVOKE_KEY, 10000);
dfltCache.invoke(CACHE_PUT_INVOKE_KEY, new CacheEntryProcessor<Object, Object, Object>() {
@Override
public Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
assertTrue(entry.exists());
return (int) entry.getValue() * 2;
}
});
} catch (CacheException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
dfltCache.put(CACHE_PUT_INVOKE_KEY, 10000);
return dfltCache.invoke(CACHE_PUT_INVOKE_KEY, new CacheEntryProcessor<Object, Object, Object>() {
@Override
public Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
assertTrue(entry.exists());
return (int) entry.getValue() * 2;
}
});
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
assertEquals(20000, (int) o);
return true;
}
}), // Check put async operation.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
dfltCache.putAsync(10002, 10002).get();
} catch (CacheException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return dfltCache.putAsync(10002, 10002).get();
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNull(o);
assertEquals(10002, dfltCache.get(10002));
return true;
}
}), // Check transaction.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.transactions();
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.transactions();
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
IgniteTransactions txs = (IgniteTransactions) o;
assertNotNull(txs);
return true;
}
}), // Check get cache.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.cache(DEFAULT_CACHE_NAME);
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.cache(DEFAULT_CACHE_NAME);
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
IgniteCache<Object, Object> cache0 = (IgniteCache<Object, Object>) o;
assertNotNull(cache0);
cache0.put(1, 1);
assertEquals(1, cache0.get(1));
return true;
}
}), // Check streamer.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.dataStreamer(DEFAULT_CACHE_NAME);
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.dataStreamer(DEFAULT_CACHE_NAME);
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
IgniteDataStreamer<Object, Object> streamer = (IgniteDataStreamer<Object, Object>) o;
streamer.addData(2, 2);
streamer.close();
assertEquals(2, client.cache(DEFAULT_CACHE_NAME).get(2));
return true;
}
}), // Check create cache.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.createCache("test_cache");
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.createCache("test_cache");
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
IgniteCache<Object, Object> cache = (IgniteCache<Object, Object>) o;
assertNotNull(cache);
cache.put(1, 1);
assertEquals(1, cache.get(1));
return true;
}
})));
}
use of org.apache.ignite.cache.CacheEntryProcessor in project ignite by apache.
the class GridCacheAbstractMetricsSelfTest method testGetMetricsDisable.
/**
* @throws Exception If failed.
*/
@Test
public void testGetMetricsDisable() throws Exception {
// Disable statistics.
for (int i = 0; i < gridCount(); i++) {
Ignite g = grid(i);
IgniteCache cache = g.cache(DEFAULT_CACHE_NAME);
cache.enableStatistics(false);
}
IgniteCache<Object, Object> jcache = grid(0).cache(DEFAULT_CACHE_NAME);
// Write to cache.
for (int i = 0; i < KEY_CNT; i++) jcache.put(i, i);
// Invoke update on cache.
for (int i = 0; i < KEY_CNT; i++) jcache.invoke(i, new CacheEntryProcessor<Object, Object, Object>() {
@Override
public Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
Object key = entry.getKey();
entry.setValue(key);
return null;
}
});
// Read-only invoke on cache.
for (int i = 0; i < KEY_CNT; i++) jcache.invoke(i, new CacheEntryProcessor<Object, Object, Object>() {
@Override
public Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
entry.getKey();
return null;
}
});
// Remove invoke on cache.
for (int i = 0; i < KEY_CNT; i++) jcache.invoke(i, new CacheEntryProcessor<Object, Object, Object>() {
@Override
public Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
entry.remove();
return null;
}
});
// Get from cache.
for (int i = 0; i < KEY_CNT; i++) jcache.get(i);
// Remove from cache.
for (int i = 0; i < KEY_CNT; i++) jcache.remove(i);
// Assert that statistics is clear.
for (int i = 0; i < gridCount(); i++) {
CacheMetrics m = grid(i).cache(DEFAULT_CACHE_NAME).localMetrics();
assertEquals(m.getCacheGets(), 0);
assertEquals(m.getCachePuts(), 0);
assertEquals(m.getCacheRemovals(), 0);
assertEquals(m.getCacheHits(), 0);
assertEquals(m.getCacheMisses(), 0);
assertEquals(m.getAverageGetTime(), 0f);
assertEquals(m.getAverageRemoveTime(), 0f);
assertEquals(m.getAveragePutTime(), 0f);
assertEquals(m.getAverageTxCommitTime(), 0f);
assertEquals(m.getAverageTxRollbackTime(), 0f);
assertEquals(m.getEntryProcessorPuts(), 0);
assertEquals(m.getEntryProcessorRemovals(), 0);
assertEquals(m.getEntryProcessorReadOnlyInvocations(), 0);
assertEquals(m.getEntryProcessorMinInvocationTime(), 0f);
assertEquals(m.getEntryProcessorMaxInvocationTime(), 0f);
assertEquals(m.getEntryProcessorAverageInvocationTime(), 0f);
assertEquals(m.getEntryProcessorInvocations(), 0);
}
}
use of org.apache.ignite.cache.CacheEntryProcessor in project ignite by apache.
the class P2PStreamingClassLoaderTest method processTest.
/**
* @throws Exception if error occur
*/
@SuppressWarnings("unchecked")
private void processTest() throws Exception {
try {
startGrid("server");
Ignite client = startClientGrid("client");
ClassLoader ldr = getExternalClassLoader();
Class<?> epCls = ldr.loadClass(ENTRY_PROCESSOR_CLASS_NAME);
Constructor<?> epCtr = epCls.getConstructor();
CacheEntryProcessor ep = (CacheEntryProcessor) epCtr.newInstance();
IgniteCache<Integer, String> cache = client.createCache(CACHE_NAME);
try (IgniteDataStreamer<Integer, String> streamer = client.dataStreamer(CACHE_NAME)) {
streamer.receiver(StreamTransformer.from(ep));
streamer.addData(1, "1");
}
assertEquals("1", cache.get(1));
} finally {
stopAllGrids();
}
}
Aggregations