Search in sources :

Example 36 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.
 */
@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);
}
Also used : IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) CacheException(javax.cache.CacheException) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 37 with IgniteDataStreamer

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

Example 38 with IgniteDataStreamer

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));
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Test(org.junit.Test)

Example 39 with IgniteDataStreamer

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));
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 40 with IgniteDataStreamer

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;
        }
    })));
}
Also used : CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCache(org.apache.ignite.IgniteCache) IgniteTransactions(org.apache.ignite.IgniteTransactions) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) CacheEntryProcessor(org.apache.ignite.cache.CacheEntryProcessor) Ignite(org.apache.ignite.Ignite) MutableEntry(javax.cache.processor.MutableEntry) T2(org.apache.ignite.internal.util.typedef.T2)

Aggregations

IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)47 Ignite (org.apache.ignite.Ignite)25 Test (org.junit.Test)21 IgniteCache (org.apache.ignite.IgniteCache)19 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)18 IgniteEx (org.apache.ignite.internal.IgniteEx)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)10 List (java.util.List)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)8 Ignition (org.apache.ignite.Ignition)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Random (java.util.Random)6 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)6 UUID (java.util.UUID)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5