Java Code Examples for org.apache.ignite.internal.IgniteEx#close()

The following examples show how to use org.apache.ignite.internal.IgniteEx#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RunningQueriesTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Check cleanup running queries on node stop.
 *
 * @throws Exception Exception in case of failure.
 */
@Test
public void testCloseRunningQueriesOnNodeStop() throws Exception {
    IgniteEx ign = startGrid(super.getConfiguration("TST"));

    IgniteCache<Integer, Integer> cache = ign.getOrCreateCache(new CacheConfiguration<Integer, Integer>()
        .setName("TST")
        .setQueryEntities(Collections.singletonList(new QueryEntity(Integer.class, Integer.class)))
    );

    for (int i = 0; i < 10000; i++)
        cache.put(i, i);

    cache.query(new SqlFieldsQuery("SELECT * FROM Integer order by _key"));

    Assert.assertEquals("Should be one running query",
        1,
        ign.context().query().runningQueries(-1).size());

    ign.close();

    Assert.assertEquals(0, ign.context().query().runningQueries(-1).size());
}
 
Example 2
Source File: IgniteStandByClusterTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception if fail.
 */
@Test
public void testJoinDaemonAndDaemonStop() throws Exception {
    IgniteEx ig = startGrid(0);

    IgniteEx daemon = startClientGrid(
        getConfiguration("daemon")
            .setDaemon(true)
    );

    Collection<ClusterNode> daemons = ig.cluster().forDaemons().nodes();

    Assert.assertEquals(1, daemons.size());
    assertEquals(daemon.localNode().id(), daemons.iterator().next().id());

    daemon.close();
}
 
Example 3
Source File: ServiceDeploymentProcessAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Stops given node depend on {@link #failNode()} flag.
 *
 * @param ignite Node to stop.
 * @see #failNode()
 */
protected void stopNode(IgniteEx ignite) {
    if (!failNode())
        ignite.close();
    else
        ((TestTcpDiscoverySpi)ignite.context().discovery().getInjectedDiscoverySpi()).simulateNodeFailure();
}
 
Example 4
Source File: MetricsConfigurationTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** Executes provided closures after cluster start and after cluster restart. */
public void checkOnStartAndRestart(IgniteBiInClosureX<IgniteEx, IgniteEx> afterStart,
    IgniteBiInClosureX<IgniteEx, IgniteEx> afterRestart) throws Exception {

    IgniteEx g0 = startGrid("persistent-0");
    IgniteEx g1 = startGrid("persistent-1");

    try {
        g0.cluster().active(true);

        afterStart.apply(g0, g1);

        g0.close();
        g1.close();

        g0 = startGrid("persistent-0");
        g1 = startGrid("persistent-1");

        g0.cluster().active(true);

        afterRestart.apply(g0, g1);
    }
    finally {
        g0.close();
        g1.close();
    }
}
 
Example 5
Source File: IgniteWalRecoveryTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception if failed.
 */
@Test
public void testAbsentDeadlock_Iterator_RollOver_Archivation() throws Exception {
    walSegments = 2;

    walSegmentSize = 512 * 1024;

    IgniteEx ignite0 = (IgniteEx)startGrid("node0");

    ignite0.active(true);

    IgniteCache<Object, Object> cache0 = ignite0.cache(CACHE_NAME);

    for (int i = 0; i < 100; i++)
        cache0.put(i, new IndexedObject(i));

    GridCacheSharedContext<Object, Object> sharedCtx = ignite0.context().cache().context();

    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)sharedCtx.database();

    db.waitForCheckpoint("test");
    db.enableCheckpoints(false).get();

    // Log something to know where to start.
    WALPointer ptr = sharedCtx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis()));

    info("Replay marker: " + ptr);

    for (int i = 100; i < 200; i++)
        cache0.put(i, new IndexedObject(i));

    CountDownLatch insertFinished = new CountDownLatch(1);
    GridTestUtils.runAsync(
        () -> {
            try (WALIterator it = sharedCtx.wal().replay(ptr)) {
                if (it.hasNext()) {
                    it.next();

                    insertFinished.await();
                }
            }

            return null;
        }
    );

    IgniteInternalFuture<Object> future = GridTestUtils.runAsync(
        () -> {
            for (int i = 0; i < 10000; i++)
                cache0.put(i, new IndexedObject(i));

            return null;
        }
    );

    future.get();

    insertFinished.countDown();

    ignite0.close();
}
 
Example 6
Source File: IgniteWalRecoveryTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Tests a scenario when a coordinator has failed after recovery during node join.
 */
@Test
@WithSystemProperty(key = "IGNITE_DISABLE_WAL_DURING_REBALANCING", value = "false")
public void testRecoveryAfterRestart_Join() throws Exception {
    IgniteEx crd = startGrid(1);
    crd.cluster().active(true);

    for (int i = 0; i < PARTS; i++) {
        crd.cache(CACHE_1).put(i, i);
        crd.cache(CACHE_2).put(i, i);
    }

    TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
        @Override public boolean apply(ClusterNode clusterNode, Message msg) {
            if (msg instanceof GridDhtPartitionSupplyMessage) {
                GridDhtPartitionSupplyMessage msg0 = (GridDhtPartitionSupplyMessage) msg;

                return msg0.groupId() == CU.cacheId(CACHE_2);
            }

            return false;
        }
    });

    IgniteEx g2 = startGrid(2);

    resetBaselineTopology();

    TestRecordingCommunicationSpi.spi(crd).waitForBlocked();

    forceCheckpoint(g2);

    g2.close();

    TestRecordingCommunicationSpi.spi(crd).stopBlock();

    waitForTopology(1);

    CountDownLatch l1 = new CountDownLatch(1);
    CountDownLatch l2 = new CountDownLatch(1);

    GridTestUtils.runAsync(new Callable<Void>() {
        @Override public Void call() throws Exception {
            startGrid(getPMEBlockingConfiguration(2, l1, l2));

            return null;
        }
    });

    assertTrue(U.await(l1, 10, TimeUnit.SECONDS));

    stopGrid(getTestIgniteInstanceName(1), true, false);

    l2.countDown();

    awaitPartitionMapExchange();
}
 
Example 7
Source File: DataStreamerImplSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testClientEventsNotCausingRemaps() throws Exception {
    Ignite ignite = startGrids(2);

    ignite.getOrCreateCache(DEFAULT_CACHE_NAME);

    IgniteDataStreamer<Object, Object> streamer = ignite.dataStreamer(DEFAULT_CACHE_NAME);

    ((DataStreamerImpl)streamer).maxRemapCount(3);

    streamer.addData(1, 1);

    for (int topChanges = 0; topChanges < 30; topChanges++) {
        IgniteEx node = startClientGrid(getConfiguration("flapping-client"));

        streamer.addData(1, 1);

        node.close();

        streamer.addData(1, 1);
    }

    streamer.flush();
    streamer.close();
}
 
Example 8
Source File: BaselineAutoAdjustTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception if failed.
 */
@Test
public void testBaselineAutoAdjustIgnoreClientNodes() throws Exception {
    IgniteEx ignite0 = startGrid(0);

    ignite0.cluster().baselineAutoAdjustEnabled(true);

    startGrid(1);

    ignite0.cluster().active(true);

    ignite0.cluster().baselineAutoAdjustTimeout(autoAdjustTimeout);

    assertTrue(ignite0.cluster().isBaselineAutoAdjustEnabled());

    stopGrid(1);

    doSleep(autoAdjustTimeout / 2);

    IgniteEx igniteClient = startClientGrid(getConfiguration(getTestIgniteInstanceName(2)));

    doSleep(autoAdjustTimeout / 2);

    igniteClient.close();

    assertTrue(isCurrentBaselineFromOneNode(ignite0));
}
 
Example 9
Source File: IgniteServiceReassignmentTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNodeRestart1() throws Exception {
    srvcCfg = serviceConfiguration();

    IgniteEx node1 = startGrid(1);

    waitForService(node1);

    assertEquals(42, serviceProxy(node1).foo());

    srvcCfg = serviceConfiguration();

    IgniteEx node2 = startGrid(2);

    node1.close();

    waitForService(node2);

    assertEquals(42, serviceProxy(node2).foo());

    srvcCfg = serviceConfiguration();

    IgniteEx node3 = startGrid(3);

    waitForService(node3);

    assertEquals(42, serviceProxy(node3).foo());

    srvcCfg = serviceConfiguration();

    node1 = startGrid(1);

    waitForService(node1);
    waitForService(node2);
    waitForService(node3);

    assertEquals(42, serviceProxy(node1).foo());
    assertEquals(42, serviceProxy(node2).foo());
    assertEquals(42, serviceProxy(node3).foo());

    node2.close();

    waitForService(node1);
    waitForService(node3);

    assertEquals(42, serviceProxy(node1).foo());
    assertEquals(42, serviceProxy(node3).foo());
}
 
Example 10
Source File: HistoricalReservationTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Execute some action before historical rebalance.
 *
 * @param someAction Some action, executing before rebalance.
 * @throws Exception If faild.
 */
public void historicalRebalance(IgniteRunnable someAction) throws Exception {
    String rebalancedNodeName = getTestIgniteInstanceName(CLUSTER_NODES) + "_rebalance";

    IgniteEx ignite0 = startGrids(CLUSTER_NODES);
    IgniteEx rebalancedNode = startGrid(rebalancedNodeName);

    ignite0.cluster().active(true);

    preloadData(ignite0, 0, 100);

    forceCheckpoint();

    awaitPartitionMapExchange();

    rebalancedNode.close();

    preloadData(ignite0, 100, 200);

    awaitPartitionMapExchange();

    someAction.run();

    AtomicBoolean hasFullRebalance = new AtomicBoolean();

    IgniteConfiguration cfg = getConfiguration(rebalancedNodeName);

    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi)cfg.getCommunicationSpi();

    spi.record((node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage) {
            GridDhtPartitionDemandMessage demandMsg = (GridDhtPartitionDemandMessage)msg;

            if (!F.isEmpty(demandMsg.partitions().fullSet()))
                hasFullRebalance.compareAndSet(false, true);
        }

        return false;
    });

    rebalancedNode = startGrid(cfg);

    rebalancedNode.cluster().active(true);

    awaitPartitionMapExchange();

    assertFalse("Full rebalance appeared where only the  historical one was expected.", hasFullRebalance.get());

    assertPartitionsSame(idleVerify(rebalancedNode, DEFAULT_CACHE_NAME));
}
 
Example 11
Source File: NotOptimizedRebalanceTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Trigger rebalance when node left topology.
 *
 * @param persistence Persistent flag.
 * @throws Exception If failed.
 */
public void testRebalance(boolean persistence, boolean serverJoin) throws Exception {
    persistenceEnabled = persistence;

    IgniteEx ignite0 = startGrids(NODES_CNT);

    ignite0.cluster().active(true);

    ignite0.cluster().baselineAutoAdjustEnabled(false);

    IgniteEx newNode = serverJoin ? startGrid(NODES_CNT) : startClientGrid(NODES_CNT);

    grid(1).close();

    for (String cache : ignite0.cacheNames())
        loadData(ignite0, cache);

    awaitPartitionMapExchange();

    TestRecordingCommunicationSpi commSpi1 = startNodeWithBlockingRebalance(getTestIgniteInstanceName(1));

    commSpi1.waitForBlocked();

    Map<CacheGroupContext, IgniteInternalFuture<Boolean>> futs = getAllRebalanceFuturesByGroup(grid(1));

    checkAllFuturesProcessing(futs);

    for (int i = 0; i < 3; i++) {
        newNode.close();

        checkTopology(NODES_CNT);

        newNode = serverJoin ? startGrid(NODES_CNT) : startClientGrid(NODES_CNT);

        checkTopology(NODES_CNT + 1);
    }

    if (serverJoin)
        checkAllFuturesCancelled(futs);
    else
        checkAllFuturesProcessing(futs);

    commSpi1.stopBlock();

    awaitPartitionMapExchange();

    Map<CacheGroupContext, IgniteInternalFuture<Boolean>> newFuts = getAllRebalanceFuturesByGroup(grid(1));

    for (Map.Entry<CacheGroupContext, IgniteInternalFuture<Boolean>> grpFut : futs.entrySet()) {
        IgniteInternalFuture<Boolean> fut = grpFut.getValue();
        IgniteInternalFuture<Boolean> newFut = newFuts.get(grpFut.getKey());

        if (serverJoin)
            assertTrue(futureInfoString(fut), fut.isDone() && !fut.get());
        else
            assertSame(fut, newFut);

        assertTrue(futureInfoString(newFut), newFut.isDone() && newFut.get());
    }
}