Search in sources :

Example 21 with IgniteDataStreamer

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);
}
Also used : IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) CacheException(javax.cache.CacheException) Ignite(org.apache.ignite.Ignite)

Example 22 with IgniteDataStreamer

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();
    }
}
Also used : IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) BinaryObject(org.apache.ignite.binary.BinaryObject)

Example 23 with IgniteDataStreamer

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();
    }
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite)

Example 24 with IgniteDataStreamer

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();
}
Also used : IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) Ignite(org.apache.ignite.Ignite)

Aggregations

IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)24 Ignite (org.apache.ignite.Ignite)16 IgniteCache (org.apache.ignite.IgniteCache)10 List (java.util.List)6 CacheException (javax.cache.CacheException)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 Random (java.util.Random)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Ignition (org.apache.ignite.Ignition)5 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)4 ExampleNodeStartup (org.apache.ignite.examples.ExampleNodeStartup)4 ExamplesUtils (org.apache.ignite.examples.ExamplesUtils)4 Callable (java.util.concurrent.Callable)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 StreamTransformer (org.apache.ignite.stream.StreamTransformer)3 Serializable (java.io.Serializable)2 PreparedStatement (java.sql.PreparedStatement)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2