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.
*/
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 DynamicIndexAbstractSelfTest method put.
/**
* Put key range.
*
* @param node Node.
* @param from From key.
* @param to To key.
*/
protected static void put(Ignite node, int from, int to) {
try (IgniteDataStreamer streamer = node.dataStreamer(CACHE_NAME)) {
streamer.allowOverwrite(true);
streamer.keepBinary(true);
for (int i = from; i < to; i++) {
BinaryObject key = key(node, i);
BinaryObject val = value(node, i);
streamer.addData(key, val);
}
streamer.flush();
}
}
use of org.apache.ignite.IgniteDataStreamer in project ignite by apache.
the class CacheIndexStreamerTest method checkStreamer.
/**
* @param atomicityMode Cache atomicity mode.
* @throws Exception If failed.
*/
public void checkStreamer(CacheAtomicityMode atomicityMode) throws Exception {
final Ignite ignite = startGrid(0);
final IgniteCache<Integer, String> cache = ignite.createCache(cacheConfiguration(atomicityMode));
final AtomicBoolean stop = new AtomicBoolean();
final int KEYS = 10_000;
try {
IgniteInternalFuture streamerFut = GridTestUtils.runAsync(new Callable() {
@Override
public Void call() throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (!stop.get()) {
try (IgniteDataStreamer<Integer, String> streamer = ignite.dataStreamer(DEFAULT_CACHE_NAME)) {
for (int i = 0; i < 1; i++) streamer.addData(rnd.nextInt(KEYS), String.valueOf(i));
}
}
return null;
}
}, "streamer-thread");
IgniteInternalFuture updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (!stop.get()) {
for (int i = 0; i < 100; i++) {
Integer key = rnd.nextInt(KEYS);
cache.put(key, String.valueOf(key));
cache.remove(key);
}
}
return null;
}
}, 1, "update-thread");
U.sleep(30_000);
stop.set(true);
streamerFut.get();
updateFut.get();
} finally {
stop.set(true);
stopAllGrids();
}
}
use of org.apache.ignite.IgniteDataStreamer in project ignite by apache.
the class IgniteCacheQueriesLoadTest1 method preLoading.
/**
* @throws Exception If fail.
*/
private void preLoading() throws Exception {
final Thread preloadAccount = new Thread() {
@Override
public void run() {
setName("preloadTraders");
Ignite ignite = ignite(0);
try (IgniteDataStreamer dataLdr = ignite.dataStreamer(TRADER_CACHE)) {
for (int i = 0; i < preloadAmount && !isInterrupted(); i++) {
String traderKey = "traderId=" + i;
dataLdr.addData(traderKey, createTrader(ignite, traderKey));
}
}
}
};
preloadAccount.start();
Thread preloadTrade = new Thread() {
@Override
public void run() {
setName("preloadDeposits");
Ignite ignite = ignite(0);
try (IgniteDataStreamer dataLdr = ignite.dataStreamer(DEPOSIT_CACHE)) {
for (int i = 0; i < preloadAmount && !isInterrupted(); i++) {
int traderId = nextRandom(preloadAmount);
String traderKey = "traderId=" + traderId;
String key = traderKey + "&depositId=" + i;
dataLdr.addData(key, createDeposit(ignite, key, traderKey, i));
}
}
}
};
preloadTrade.start();
preloadTrade.join();
preloadAccount.join();
}
Aggregations