Search in sources :

Example 1 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class MetaStorageCompatibilityTest method testMigrationToNewBaselineSetNewBaselineAfterMigration.

/**
 * Tests that BLT can be changed and persisted after metastorage migration.
 */
@Test
@WithSystemProperty(key = IGNITE_DISABLE_WAL_DURING_REBALANCING, value = "false")
public void testMigrationToNewBaselineSetNewBaselineAfterMigration() throws Exception {
    try {
        U.delete(new File(U.defaultWorkDirectory()));
        startGrid(1, IGNITE_VERSION, new ConfigurationClosure(CONSISTENT_ID_1), new ActivateAndStopClosure());
        stopAllGrids();
        try (Ignite ig0 = IgnitionEx.start(prepareConfig(getConfiguration(), CONSISTENT_ID_1))) {
            try (Ignite ig1 = IgnitionEx.start(prepareConfig(getConfiguration(), CONSISTENT_ID_2))) {
                ig0.cluster().setBaselineTopology(ig1.cluster().topologyVersion());
            }
        }
        assertFalse(metastorageFileExists(INDEX_BIN_FILE));
        assertFalse(metastorageFileExists(PART_FILE));
        try (Ignite ig0 = IgnitionEx.start(prepareConfig(getConfiguration(), CONSISTENT_ID_1))) {
            try (Ignite ig1 = IgnitionEx.start(prepareConfig(getConfiguration(), CONSISTENT_ID_2))) {
                assertTrue(GridTestUtils.waitForCondition(() -> ig1.cluster().state() == ACTIVE, 10_000));
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) File(java.io.File) GridCacheAbstractFullApiSelfTest(org.apache.ignite.internal.processors.cache.GridCacheAbstractFullApiSelfTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 2 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class IgniteExchangeLatchManagerDiscoHistoryTest method testProperException.

/**
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = IGNITE_DISCOVERY_HISTORY_SIZE, value = DISCO_HISTORY_SIZE)
public void testProperException() throws Exception {
    final IgniteEx crd = startGrid(0);
    final CountDownLatch exchangeLatch = new CountDownLatch(1);
    final CountDownLatch startSrvsLatch = new CountDownLatch(1);
    final AtomicReference<Exception> err = new AtomicReference<>();
    // Lifecycle bean that is used to register PartitionsExchangeAware listener.
    lifecycleBean = new LifecycleBean() {

        /**
         * Ignite instance.
         */
        @IgniteInstanceResource
        IgniteEx ignite;

        /**
         * {@inheritDoc}
         */
        @Override
        public void onLifecycleEvent(LifecycleEventType evt) throws IgniteException {
            if (evt == LifecycleEventType.BEFORE_NODE_START) {
                // The goal is registering PartitionsExchangeAware listener before the discovery manager is started.
                ignite.context().internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() {

                    @Override
                    public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
                        ignite.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

                            /**
                             * {@inheritDoc}
                             */
                            @Override
                            public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
                                try {
                                    // Let's start nodes.
                                    startSrvsLatch.countDown();
                                    // Blocks the initial exchange and waits for other nodes.
                                    exchangeLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
                                } catch (Exception e) {
                                    err.compareAndSet(null, e);
                                }
                            }
                        });
                    }
                });
            }
        }
    };
    // Start server node with short topology history.
    victim = true;
    GridTestUtils.runAsync(() -> startGrid(1));
    // Waits for the initial exchange.
    startSrvsLatch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
    victim = false;
    lifecycleBean = null;
    List<IgniteInternalFuture> srvFuts = new ArrayList<>(TOPOLOGY_HISTORY_SIZE);
    try {
        // Major topology version that is corresponding to the start of the node with short topology history.
        final long topVer = 2;
        // Starting server nodes to exhaust the topology history.
        for (int i = 2; i < 3 * TOPOLOGY_HISTORY_SIZE && !disco.isEmptyTopologyHistory(topVer); ++i) {
            final int currNodeIdx = i;
            final int joinedNodesCnt = disco.totalJoinedNodes();
            srvFuts.add(GridTestUtils.runAsync(() -> startGrid(currNodeIdx)));
            assertTrue("Failed to wait for a new server node [joinedNodesCnt=" + joinedNodesCnt + "]", GridTestUtils.waitForCondition(() -> disco.totalJoinedNodes() >= (joinedNodesCnt + 1), DEFAULT_TIMEOUT));
        }
        assertTrue("Disco cache history is not empty for the topology [majorTopVer=" + topVer + ']', disco.isEmptyTopologyHistory(topVer));
        // Let's continue the ongoing exchange.
        exchangeLatch.countDown();
        boolean failureHnd = GridTestUtils.waitForCondition(() -> cpFailureCtx.get() != null, DEFAULT_TIMEOUT);
        assertNull("Unexpected exception (probably, the topology history still exists [err=" + err + ']', err.get());
        assertTrue("Failure handler was not triggered.", failureHnd);
        // Check that IgniteException was thrown instead of NullPointerException.
        assertTrue("IgniteException must be thrown.", X.hasCause(cpFailureCtx.get().error(), IgniteException.class));
        // Check that message contains a hint to fix the issue.
        GridTestUtils.assertContains(log, cpFailureCtx.get().error().getMessage(), "Consider increasing IGNITE_DISCOVERY_HISTORY_SIZE property. Current value is " + DISCO_HISTORY_SIZE);
    } finally {
        IgnitionEx.stop(getTestIgniteInstanceName(1), true, ShutdownPolicy.IMMEDIATE, true);
        srvFuts.forEach(f -> {
            try {
                f.get(DEFAULT_TIMEOUT);
            } catch (IgniteCheckedException e) {
                err.compareAndSet(null, e);
            }
        });
    }
    assertNull("Unexpected exception [err=" + err.get() + ']', err.get());
}
Also used : ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) LifecycleBean(org.apache.ignite.lifecycle.LifecycleBean) DistributedMetastorageLifecycleListener(org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener) LifecycleEventType(org.apache.ignite.lifecycle.LifecycleEventType) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 3 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class GridCachePartitionExchangeManagerWarningsTest method testLongRunningCacheFutures.

/**
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, value = LONG_OPERATIONS_DUMP_TIMEOUT)
public void testLongRunningCacheFutures() throws Exception {
    long timeout = Long.parseLong(LONG_OPERATIONS_DUMP_TIMEOUT);
    testLog = new CustomTestLogger(false, log, "future");
    int longRunFuturesCnt = 1000;
    startGrids(2);
    Ignite client = startClientGrid(3);
    try (IgniteDataStreamer<Integer, Integer> streamer = client.dataStreamer(CACHE_NAME)) {
        streamer.allowOverwrite(true);
        for (int i = 0; i < longRunFuturesCnt; i++) streamer.addData(i, i);
    }
    doSleep(timeout * 2);
    stopAllGrids();
    assertTrue("Warnings were not found", testLog.warningsTotal() > 0);
    assertTrue("Too much warnings in the logs: " + testLog.warningsTotal(), testLog.warningsTotal() < longRunFuturesCnt);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 4 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class GridCachePartitionExchangeManagerWarningsTest method testLongRunningTransactions.

/**
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, value = LONG_OPERATIONS_DUMP_TIMEOUT)
public void testLongRunningTransactions() throws Exception {
    long timeout = Long.parseLong(LONG_OPERATIONS_DUMP_TIMEOUT);
    testLog = new CustomTestLogger(false, log, "transaction");
    int transactions = 100;
    ExecutorService excSvc = Executors.newFixedThreadPool(transactions);
    try (Ignite srv1 = startGrid(0)) {
        CountDownLatch txStarted = new CountDownLatch(transactions);
        CountDownLatch stopTx = new CountDownLatch(1);
        for (int i = 0; i < transactions; i++) excSvc.submit(new AsyncTransaction(srv1, TX_CACHE_NAME, i, txStarted, stopTx));
        if (!txStarted.await(10_000, TimeUnit.MILLISECONDS))
            fail("Unable to start transactions");
        doSleep(timeout * 2);
        stopTx.countDown();
    } finally {
        excSvc.shutdown();
        if (!excSvc.awaitTermination(10_000, TimeUnit.MILLISECONDS))
            fail("Unable to wait for thread pool termination.");
    }
    assertTrue("Warnings were not found", testLog.warningsTotal() > 0);
    assertTrue("Too much warnings in the logs: " + testLog.warningsTotal(), testLog.warningsTotal() < transactions);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 5 with WithSystemProperty

use of org.apache.ignite.testframework.junits.WithSystemProperty in project ignite by apache.

the class ConsistentIdImplicitlyExplicitlyTest method testConsistentIdConfiguredInIgniteCfgAndJvmProp.

/**
 * Consistent ID is configured in the {@link IgniteConfiguration} and in the JVM property.
 *
 * @throws Exception if failed.
 */
@Test
@WithSystemProperty(key = IGNITE_OVERRIDE_CONSISTENT_ID, value = "JvmProp consistent id")
public void testConsistentIdConfiguredInIgniteCfgAndJvmProp() throws Exception {
    defConsistentId = "IgniteCfg consistent id";
    String specificConsistentId = System.getProperty(IGNITE_OVERRIDE_CONSISTENT_ID);
    ;
    LogListener lsnr = expectLogEvent(WARN_MESSAGE, 0);
    Ignite ignite = startGrid(0);
    assertEquals(specificConsistentId, ignite.configuration().getConsistentId());
    assertEquals(specificConsistentId, ignite.cluster().localNode().consistentId());
    assertTrue(lsnr.check());
    info("Consistent ID: " + ignite.cluster().localNode().consistentId());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)71 Test (org.junit.Test)71 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)59 IgniteEx (org.apache.ignite.internal.IgniteEx)46 Ignite (org.apache.ignite.Ignite)20 LogListener (org.apache.ignite.testframework.LogListener)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)11 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)10 File (java.io.File)9 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)8 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)8 List (java.util.List)7 IgniteCache (org.apache.ignite.IgniteCache)7 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)7