use of org.apache.ignite.IgniteDataStreamer in project ignite by apache.
the class DataStreamerTimeoutTest method testTimeoutOnCloseMethod.
/**
* Test timeout on {@code DataStreamer.addData()} method
* @throws Exception If fail.
*/
@Test
public void testTimeoutOnCloseMethod() throws Exception {
failOn = 1;
Ignite ignite = startGrid(1);
boolean thrown = false;
try (IgniteDataStreamer ldr = ignite.dataStreamer(CACHE_NAME)) {
ldr.timeout(TIMEOUT);
ldr.receiver(new TestDataReceiver());
ldr.perNodeBufferSize(ENTRY_AMOUNT);
for (int i = 0; i < ENTRY_AMOUNT; i++) ldr.addData(i, i);
} catch (CacheException | IgniteDataStreamerTimeoutException ignored) {
thrown = true;
} finally {
stopAllGrids();
}
assertTrue(thrown);
}
use of org.apache.ignite.IgniteDataStreamer in project ignite by apache.
the class CircledRebalanceTest method loadData.
/**
* Load keys for preloading significant more than for updates and covers all cache partitions.
*
* @param preload True for preloading keys, false otherwise.
*/
public void loadData(boolean preload) {
Random random = new Random();
Ignite ignite = G.allGrids().get(0);
try (IgniteDataStreamer streamer = ignite.dataStreamer(DEFAULT_CACHE_NAME)) {
streamer.allowOverwrite(true);
for (int i = 0; i < (preload ? 100 * PARTS : 100); i++) {
Integer ranDomKey = random.nextInt(10_000);
streamer.addData(preload ? i : ranDomKey, "Val " + ranDomKey);
}
}
}
use of org.apache.ignite.IgniteDataStreamer in project ignite by apache.
the class GracefulShutdownTest method testNotIdealOwners.
/**
* Try to stop node when not all backups are matching of ideal assignment.
*
* @throws Exception If failed.
*/
@Test
public void testNotIdealOwners() throws Exception {
backups = 1;
Ignite ignite0 = startGrid(0);
ignite0.cluster().active(true);
for (int i = 1; i <= 3; i++) {
IgniteCache cache = ignite0.cache("cache" + i);
assertNotNull(cache);
try (IgniteDataStreamer streamer = ignite0.dataStreamer("cache" + i)) {
for (int j = 0; j < 100; j++) streamer.addData(j, j);
}
}
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite0);
spi.blockMessages((node, msg) -> {
String nodeName = (String) node.attributes().get(ATTR_IGNITE_INSTANCE_NAME);
if (msg instanceof GridDhtPartitionSupplyMessage) {
GridDhtPartitionSupplyMessage supplyMsg = (GridDhtPartitionSupplyMessage) msg;
if (supplyMsg.groupId() != CU.cacheId(GridCacheUtils.UTILITY_CACHE_NAME) && getTestIgniteInstanceName(1).equals(nodeName))
return true;
}
return false;
});
startGrid(1);
Ignite ignite2 = startGrid(2);
resetBaselineTopology();
spi.waitForBlocked();
for (CacheGroupContext grp : ((IgniteEx) ignite2).context().cache().cacheGroups()) {
GridTestUtils.waitForCondition(() -> !grp.topology().partitionMap(false).get(((IgniteEx) ignite2).localNode().id()).hasMovingPartitions(), 30_000);
}
LogListener lnsr = LogListener.matches("This node is waiting for backups of local partitions for group").build();
listeningLog.registerListener(lnsr);
IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
ignite2.close();
});
assertTrue(GridTestUtils.waitForCondition(lnsr::check, 30_000));
assertFalse(fut.isDone());
spi.stopBlock();
assertTrue(GridTestUtils.waitForCondition(fut::isDone, 30_000));
}
use of org.apache.ignite.IgniteDataStreamer in project ignite by apache.
the class GracefulShutdownTest method tesStartCacheWhenNodeStopping.
/**
* Stopping node and start cache which does not allow it.
*
* @throws Exception If failed.
*/
@Test
public void tesStartCacheWhenNodeStopping() throws Exception {
backups = 2;
Ignite ignite0 = startGrid(0);
ignite0.cluster().active(true);
for (int i = 1; i <= 3; i++) {
IgniteCache cache = ignite0.cache("cache" + i);
assertNotNull(cache);
try (IgniteDataStreamer streamer = ignite0.dataStreamer("cache" + i)) {
for (int j = 0; j < 100; j++) streamer.addData(j, j);
}
}
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite0);
spi.blockMessages((node, msg) -> {
String nodeName = (String) node.attributes().get(ATTR_IGNITE_INSTANCE_NAME);
if (msg instanceof GridDhtPartitionSupplyMessage) {
GridDhtPartitionSupplyMessage supplyMsg = (GridDhtPartitionSupplyMessage) msg;
if (supplyMsg.groupId() != CU.cacheId(GridCacheUtils.UTILITY_CACHE_NAME) && getTestIgniteInstanceName(1).equals(nodeName))
return true;
}
return false;
});
Ignite ignite1 = startGrid(1);
Ignite ignite2 = startGrid(2);
resetBaselineTopology();
spi.waitForBlocked();
for (CacheGroupContext grp : ((IgniteEx) ignite2).context().cache().cacheGroups()) {
grp.preloader().rebalanceFuture().get();
}
ignite2.close();
LogListener lnsr = LogListener.matches("This node is waiting for completion of rebalance for group").build();
listeningLog.registerListener(lnsr);
IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
ignite1.close();
});
assertTrue(GridTestUtils.waitForCondition(lnsr::check, 30_000));
listeningLog.unregisterListener(lnsr);
assertFalse(fut.isDone());
ignite0.getOrCreateCache(new CacheConfiguration(DEFAULT_CACHE_NAME).setBackups(1));
spi.stopBlock();
lnsr = LogListener.matches("This node is waiting for backups of local partitions for group").build();
listeningLog.registerListener(lnsr);
assertTrue(GridTestUtils.waitForCondition(lnsr::check, 30_000));
}
use of org.apache.ignite.IgniteDataStreamer 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;
}
})));
}
Aggregations