Search in sources :

Example 1 with DiscoverySpiTestListener

use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.

the class CacheLateAffinityAssignmentTest method testDelayAssignmentCacheDestroyCreate.

/**
 * Wait for rebalance, cache is destroyed and created again.
 *
 * @throws Exception If failed.
 */
@Test
public void testDelayAssignmentCacheDestroyCreate() throws Exception {
    Ignite ignite0 = startServer(0, 1);
    CacheConfiguration ccfg = cacheConfiguration();
    ccfg.setName(CACHE_NAME2);
    ignite0.createCache(ccfg);
    DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
    ((IgniteDiscoverySpi) ignite0.configuration().getDiscoverySpi()).setInternalListener(lsnr);
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
    blockSupplySend(spi, CACHE_NAME2);
    lsnr.blockCustomEvent(CacheAffinityChangeMessage.class);
    startServer(1, 2);
    startGrid(3);
    checkAffinity(3, topVer(3, 0), false);
    spi.stopBlock();
    lsnr.waitCustomEvent();
    ignite0.destroyCache(CACHE_NAME2);
    ccfg = cacheConfiguration();
    ccfg.setName(CACHE_NAME2);
    ccfg.setAffinity(affinityFunction(10));
    ignite0.createCache(ccfg);
    lsnr.stopBlockCustomEvents();
    checkAffinity(3, topVer(3, 1), false);
    checkAffinity(3, topVer(3, 2), false);
    idealAff.get(2L).remove(CU.cacheId(CACHE_NAME2));
    calculateAffinity(3);
    checkAffinity(3, topVer(3, 3), true);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) DiscoverySpiTestListener(org.apache.ignite.internal.DiscoverySpiTestListener) Ignite(org.apache.ignite.Ignite) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with DiscoverySpiTestListener

use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.

the class CacheLateAffinityAssignmentTest method testDelayAssignmentAffinityChanged2.

/**
 * Wait for rebalance, send affinity change message, but affinity already changed (new node joined).
 *
 * @throws Exception If failed.
 */
@Test
public void testDelayAssignmentAffinityChanged2() throws Exception {
    System.setProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1, "true");
    try {
        Ignite ignite0 = startServer(0, 1);
        DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
        ((IgniteDiscoverySpi) ignite0.configuration().getDiscoverySpi()).setInternalListener(lsnr);
        TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
        startClient(1, 2);
        checkAffinity(2, topVer(2, 0), true);
        startServer(2, 3);
        checkAffinity(3, topVer(3, 1), false);
        lsnr.blockCustomEvent(CacheAffinityChangeMessage.class);
        stopNode(2, 4);
        lsnr.waitCustomEvent();
        blockSupplySend(commSpi0, CACHE_NAME1);
        final IgniteInternalFuture<?> startedFuture = multithreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                startServer(3, 5);
                return null;
            }
        }, 1, "server-starter");
        Thread.sleep(2_000);
        lsnr.stopBlockCustomEvents();
        boolean started = GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return startedFuture.isDone();
            }
        }, 10_000);
        if (!started)
            startedFuture.cancel();
        assertTrue(started);
        checkAffinity(3, topVer(5, 0), false);
        checkNoExchange(3, topVer(5, 1));
        commSpi0.stopBlock();
        checkAffinity(3, topVer(5, 1), true);
        long nodeJoinTopVer = grid(3).context().discovery().localJoinEvent().topologyVersion();
        assertEquals(5, nodeJoinTopVer);
        List<GridDhtPartitionsExchangeFuture> exFutures = grid(3).context().cache().context().exchange().exchangeFutures();
        for (GridDhtPartitionsExchangeFuture f : exFutures) {
            // Shouldn't contains staled futures.
            assertTrue(f.initialVersion().topologyVersion() >= nodeJoinTopVer);
        }
    } finally {
        System.clearProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1);
    }
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) DiscoverySpiTestListener(org.apache.ignite.internal.DiscoverySpiTestListener) Ignite(org.apache.ignite.Ignite) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with DiscoverySpiTestListener

use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.

the class IgniteWalRecoveryTest method testBinaryRecoverBeforePMEWhenMiddleCheckpoint.

/**
 * Check binary recover completes successfully when node stopped at the middle of checkpoint. Destroy cache_data.bin
 * file for particular cache to emulate missing {@link DynamicCacheDescriptor} file (binary recovery should complete
 * successfully in this case).
 *
 * @throws Exception if failed.
 */
@Test
public void testBinaryRecoverBeforePMEWhenMiddleCheckpoint() throws Exception {
    startGrids(3);
    IgniteEx ig2 = grid(2);
    ig2.cluster().active(true);
    IgniteCache<Object, Object> cache = ig2.cache(CACHE_NAME);
    for (int i = 1; i <= 4_000; i++) cache.put(i, new BigObject(i));
    BigObject objToCheck;
    ig2.getOrCreateCache(CACHE_TO_DESTROY_NAME).put(1, objToCheck = new BigObject(1));
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ig2.context().cache().context().database();
    IgniteInternalFuture<?> cpFinishFut = dbMgr.forceCheckpoint("force checkpoint").futureFor(FINISHED);
    // Delete checkpoint END file to emulate node stopped at the middle of checkpoint.
    cpFinishFut.listen(new IgniteInClosureX<IgniteInternalFuture>() {

        @Override
        public void applyx(IgniteInternalFuture fut0) throws IgniteCheckedException {
            try {
                CheckpointEntry cpEntry = dbMgr.checkpointHistory().lastCheckpoint();
                String cpEndFileName = CheckpointMarkersStorage.checkpointFileName(cpEntry, CheckpointEntryType.END);
                Files.delete(Paths.get(dbMgr.checkpointDirectory().getAbsolutePath(), cpEndFileName));
                log.info("Checkpoint marker removed [cpEndFileName=" + cpEndFileName + ']');
            } catch (IOException e) {
                throw new IgniteCheckedException(e);
            }
        }
    });
    // Resolve cache directory. Emulating cache destroy in the middle of checkpoint.
    IgniteInternalCache<Object, Object> destoryCache = ig2.cachex(CACHE_TO_DESTROY_NAME);
    FilePageStoreManager pageStoreMgr = (FilePageStoreManager) destoryCache.context().shared().pageStore();
    File destroyCacheWorkDir = pageStoreMgr.cacheWorkDir(destoryCache.configuration());
    // Stop the whole cluster
    stopAllGrids();
    // Delete cache_data.bin file for this cache. Binary recovery should complete successfully after it.
    final File[] files = destroyCacheWorkDir.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(final File dir, final String name) {
            return name.endsWith(CACHE_DATA_FILENAME);
        }
    });
    assertTrue(files.length > 0);
    for (final File file : files) assertTrue("Can't remove " + file.getAbsolutePath(), file.delete());
    startGrids(2);
    // Preprare Ignite instance configuration with additional Discovery checks.
    final String ig2Name = getTestIgniteInstanceName(2);
    final IgniteConfiguration onJoinCfg = optimize(getConfiguration(ig2Name));
    // Check restore beeing called before PME and joining node to cluster.
    ((IgniteDiscoverySpi) onJoinCfg.getDiscoverySpi()).setInternalListener(new DiscoverySpiTestListener() {

        @Override
        public void beforeJoin(ClusterNode locNode, IgniteLogger log) {
            String nodeName = locNode.attribute(ATTR_IGNITE_INSTANCE_NAME);
            GridCacheSharedContext sharedCtx = ((IgniteEx) ignite(getTestIgniteInstanceIndex(nodeName))).context().cache().context();
            if (nodeName.equals(ig2Name)) {
                // Checkpoint history initialized on node start.
                assertFalse(((GridCacheDatabaseSharedManager) sharedCtx.database()).checkpointHistory().checkpoints().isEmpty());
            }
            super.beforeJoin(locNode, log);
        }
    });
    Ignite restoredIg2 = startGrid(ig2Name, onJoinCfg);
    awaitPartitionMapExchange();
    assertEquals(restoredIg2.cache(CACHE_TO_DESTROY_NAME).get(1), objToCheck);
}
Also used : FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) FilenameFilter(java.io.FilenameFilter) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DiscoverySpiTestListener(org.apache.ignite.internal.DiscoverySpiTestListener) Ignite(org.apache.ignite.Ignite) CheckpointEntry(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointEntry) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IOException(java.io.IOException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) IgniteLogger(org.apache.ignite.IgniteLogger) File(java.io.File) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 4 with DiscoverySpiTestListener

use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.

the class GridMessagingSelfTest method testAsyncOld.

/**
 * @throws Exception If failed.
 */
@Test
public void testAsyncOld() throws Exception {
    final AtomicInteger msgCnt = new AtomicInteger();
    IgniteDiscoverySpi discoSpi = (IgniteDiscoverySpi) ignite2.configuration().getDiscoverySpi();
    DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
    discoSpi.setInternalListener(lsnr);
    assertFalse(ignite2.message().isAsync());
    final IgniteMessaging msg = ignite2.message().withAsync();
    assertTrue(msg.isAsync());
    assertFalse(ignite2.message().isAsync());
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    lsnr.blockCustomEvent(StartRoutineDiscoveryMessage.class, StartRoutineDiscoveryMessageV2.class);
    final String topic = "topic";
    UUID id = msg.remoteListen(topic, new P2<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
            msgCnt.incrementAndGet();
            return true;
        }
    });
    Assert.assertNull(id);
    IgniteFuture<UUID> starFut = msg.future();
    Assert.assertNotNull(starFut);
    U.sleep(500);
    Assert.assertFalse(starFut.isDone());
    lsnr.stopBlockCustomEvents();
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    id = starFut.get();
    Assert.assertNotNull(id);
    Assert.assertTrue(starFut.isDone());
    lsnr.blockCustomEvent(StopRoutineDiscoveryMessage.class);
    message(ignite1.cluster().forRemotes()).send(topic, "msg1");
    GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return msgCnt.get() > 0;
        }
    }, 5000);
    assertEquals(1, msgCnt.get());
    msg.stopRemoteListen(id);
    IgniteFuture<?> stopFut = msg.future();
    Assert.assertNotNull(stopFut);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    U.sleep(500);
    Assert.assertFalse(stopFut.isDone());
    lsnr.stopBlockCustomEvents();
    stopFut.get();
    Assert.assertTrue(stopFut.isDone());
    message(ignite1.cluster().forRemotes()).send(topic, "msg2");
    U.sleep(1000);
    assertEquals(1, msgCnt.get());
}
Also used : IOException(java.io.IOException) PA(org.apache.ignite.internal.util.typedef.PA) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteMessaging(org.apache.ignite.IgniteMessaging) DiscoverySpiTestListener(org.apache.ignite.internal.DiscoverySpiTestListener) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with DiscoverySpiTestListener

use of org.apache.ignite.internal.DiscoverySpiTestListener in project ignite by apache.

the class GridMessagingSelfTest method testAsync.

/**
 * @throws Exception If failed.
 */
@Test
public void testAsync() throws Exception {
    final AtomicInteger msgCnt = new AtomicInteger();
    IgniteDiscoverySpi discoSpi = (IgniteDiscoverySpi) ignite2.configuration().getDiscoverySpi();
    DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();
    discoSpi.setInternalListener(lsnr);
    lsnr.blockCustomEvent(StartRoutineDiscoveryMessage.class, StartRoutineDiscoveryMessageV2.class);
    final String topic = "topic";
    IgniteFuture<UUID> starFut = ignite2.message().remoteListenAsync(topic, new P2<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
            msgCnt.incrementAndGet();
            return true;
        }
    });
    Assert.assertNotNull(starFut);
    U.sleep(500);
    Assert.assertFalse(starFut.isDone());
    lsnr.stopBlockCustomEvents();
    UUID id = starFut.get();
    Assert.assertNotNull(id);
    Assert.assertTrue(starFut.isDone());
    lsnr.blockCustomEvent(StopRoutineDiscoveryMessage.class);
    message(ignite1.cluster().forRemotes()).send(topic, "msg1");
    GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return msgCnt.get() > 0;
        }
    }, 5000);
    assertEquals(1, msgCnt.get());
    IgniteFuture<?> stopFut = ignite2.message().stopRemoteListenAsync(id);
    Assert.assertNotNull(stopFut);
    U.sleep(500);
    Assert.assertFalse(stopFut.isDone());
    lsnr.stopBlockCustomEvents();
    stopFut.get();
    Assert.assertTrue(stopFut.isDone());
    message(ignite1.cluster().forRemotes()).send(topic, "msg2");
    U.sleep(1000);
    assertEquals(1, msgCnt.get());
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DiscoverySpiTestListener(org.apache.ignite.internal.DiscoverySpiTestListener) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

DiscoverySpiTestListener (org.apache.ignite.internal.DiscoverySpiTestListener)8 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)8 Test (org.junit.Test)8 IgniteDiscoverySpi (org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi)7 Ignite (org.apache.ignite.Ignite)5 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)3 IOException (java.io.IOException)2 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 PA (org.apache.ignite.internal.util.typedef.PA)2 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 IgniteMessaging (org.apache.ignite.IgniteMessaging)1