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

The following examples show how to use org.apache.ignite.internal.IgniteEx#destroyCache() . 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: IgniteCacheGroupsWithRestartsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNodeRestartBetweenCacheStop() throws Exception {
    IgniteEx ex = startGrids(3);

    prepareCachesAndData(ex);

    stopGrid(2, true);

    ex.destroyCache(getCacheName(0));

    assertNull(ex.cachex(getCacheName(0)));

    try {
        startGrid(2);

        fail();
    }
    catch (Exception e) {
        List<Throwable> list = X.getThrowableList(e);

        assertTrue(list.stream().
            anyMatch(x -> x.getMessage().
                contains("Joining node has caches with data which are not presented on cluster")));
    }

    removeCacheDir(getTestIgniteInstanceName(2), "cacheGroup-group");

    IgniteEx node2 = startGrid(2);

    assertEquals(3, node2.cluster().nodes().size());
}
 
Example 2
Source File: CacheMetricsAddRemoveTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private void destroyCache() throws InterruptedException {
    IgniteEx client = grid("client");

    for (String name : client.cacheNames())
        client.destroyCache(name);

    awaitPartitionMapExchange();
}
 
Example 3
Source File: IgniteCacheGroupsWithRestartsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Ignore("https://issues.apache.org/jira/browse/IGNITE-8717")
@Test
public void testNodeRestartRightAfterCacheStop() throws Exception {
    IgniteEx ex = startGrids(3);

    prepareCachesAndData(ex);

    ex.destroyCache(getCacheName(0));

    assertNull(ex.cachex(getCacheName(0)));

    stopGrid(2, true);

    startGrid(2);

    assertNull(ex.cachex(getCacheName(0)));

    IgniteCache<Object, Object> cache = ex.createCache(getCacheConfiguration(0));

    awaitPartitionMapExchange();

    assertEquals(0, cache.size());
}
 
Example 4
Source File: IgniteWalRecoveryTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDestroyCache() throws Exception {
    IgniteEx ignite = startGrid(1);

    ignite.cluster().active(true);

    IgniteCache<Object, Object> cache = ignite.getOrCreateCache("test");

    cache.put(1, new IndexedObject(1));

    ignite.destroyCache("test");

    cache = ignite.getOrCreateCache("test");

    // No entry available after cache destroy.
    assertNull(cache.get(1));
}
 
Example 5
Source File: IgniteServiceDynamicCachesSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testDeployCalledBeforeCacheStart() throws Exception {
    String cacheName = "cache";

    CacheConfiguration ccfg = new CacheConfiguration(cacheName);
    ccfg.setBackups(1);

    IgniteEx ig = grid(0);

    final IgniteServices svcs = ig.services();

    final String svcName = "myService";

    ig.createCache(ccfg);

    Object key = primaryKey(ig.cache(cacheName));

    ig.destroyCache(cacheName);

    awaitPartitionMapExchange();

    if (ig.context().service() instanceof GridServiceProcessor) {
        svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);

        assertNull(svcs.service(svcName));

        ig.createCache(ccfg);
    }
    else if (ig.context().service() instanceof IgniteServiceProcessor) {
        GridTestUtils.assertThrowsWithCause(() -> {
            svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);

            return null;
        }, ServiceDeploymentException.class);

        ig.createCache(ccfg);

        svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);
    }
    else
        fail("Unexpected service implementation.");

    try {
        boolean res = GridTestUtils.waitForCondition(new PA() {
            @Override public boolean apply() {
                return svcs.service(svcName) != null;
            }
        }, 10 * 1000);

        assertTrue("Service was not deployed", res);

        info("stopping cache: " + cacheName);

        ig.destroyCache(cacheName);

        res = GridTestUtils.waitForCondition(new PA() {
            @Override public boolean apply() {
                return svcs.service(svcName) == null;
            }
        }, 10 * 1000);

        assertTrue("Service was not undeployed", res);
    }
    finally {
        ig.services().cancelAll();

        ig.destroyCache(cacheName);
    }
}
 
Example 6
Source File: IgniteDynamicCacheStartSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testStartStopCacheAddNode() throws Exception {
    final IgniteEx kernal = grid(0);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    ccfg.setCacheMode(CacheMode.REPLICATED);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

    ccfg.setName(DYNAMIC_CACHE_NAME);

    kernal.createCache(ccfg);

    info(">>>>>>> Deployed dynamic cache");

    startGrid(nodeCount());

    try {
        // Check that cache got deployed on new node.
        IgniteCache<Object, Object> cache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);

        cache.put("1", "1");

        for (int g = 0; g < nodeCount() + 1; g++) {
            assertEquals("1", grid(g).cache(DYNAMIC_CACHE_NAME).get("1"));

            Collection<ClusterNode> nodes = grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(0);

            assertEquals(nodeCount() + 1, nodes.size());
        }

        // Undeploy cache.
        kernal.destroyCache(DYNAMIC_CACHE_NAME);

        startGrid(nodeCount() + 1);

        awaitPartitionMapExchange();

        // Check that cache is not deployed on new node after undeploy.
        for (int g = 0; g < nodeCount() + 2; g++) {
            final IgniteKernal kernal0 = (IgniteKernal)grid(g);

            assertNull(kernal0.cache(DYNAMIC_CACHE_NAME));
        }
    }
    finally {
        stopGrid(nodeCount() + 1);
        stopGrid(nodeCount());
    }
}
 
Example 7
Source File: IgniteDynamicCacheStartSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeployFilter() throws Exception {
    try {
        testAttribute = false;

        startGrid(nodeCount());

        final IgniteEx kernal = grid(0);

        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

        ccfg.setName(DYNAMIC_CACHE_NAME);

        ccfg.setNodeFilter(NODE_FILTER);

        kernal.createCache(ccfg);

        startGrid(nodeCount() + 1);

        for (int i = 0; i < 100; i++)
            grid(0).cache(DYNAMIC_CACHE_NAME).put(i, i);

        for (int i = 0; i < 100; i++)
            assertEquals(i, grid(1).cache(DYNAMIC_CACHE_NAME).get(i));

        info("Affinity nodes: " + grid(0).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(0));

        for (int g = 0; g < nodeCount(); g++) {
            for (int i = 0; i < 100; i++) {
                assertFalse(grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(i)
                    .contains(grid(nodeCount()).cluster().localNode()));

                assertFalse(grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(i)
                    .contains(grid(nodeCount() + 1).cluster().localNode()));
            }
        }

        awaitPartitionMapExchange();

        // Check that cache is not deployed on new node after undeploy.
        for (int g = 0; g < nodeCount() + 2; g++) {
            final IgniteKernal kernal0 = (IgniteKernal)grid(g);

            if (g < nodeCount())
                assertNotNull(grid(g).cache(DYNAMIC_CACHE_NAME));
            else
                GridTestUtils.assertThrows(log, new Callable<Object>() {
                    @Override public Object call() throws Exception {
                        return kernal0.getCache(DYNAMIC_CACHE_NAME);
                    }
                }, IllegalArgumentException.class, null);
        }

        kernal.destroyCache(DYNAMIC_CACHE_NAME);

        stopGrid(nodeCount() + 1);
        stopGrid(nodeCount());
    }
    finally {
        testAttribute = true;
    }
}
 
Example 8
Source File: IgniteDynamicCacheStartSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testClientCache() throws Exception {
    try {
        testAttribute = false;

        startGrid(nodeCount());

        final IgniteEx kernal = grid(0);

        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

        ccfg.setName(DYNAMIC_CACHE_NAME);

        ccfg.setNodeFilter(NODE_FILTER);

        kernal.createCache(ccfg);

        GridTestUtils.assertThrows(log, new Callable<Object>() {
            @Override public Object call() throws Exception {
                IgniteKernal ignite = (IgniteKernal)grid(nodeCount());

                return ignite.getCache(DYNAMIC_CACHE_NAME);
            }
        }, IllegalArgumentException.class, null);

        // Should obtain client cache on new node.
        IgniteCache<Object, Object> clientCache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);

        clientCache.put("1", "1");

        for (int g = 0; g < nodeCount() + 1; g++)
            assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1"));

        kernal.destroyCache(DYNAMIC_CACHE_NAME);
    }
    finally {
        stopGrid(nodeCount());
    }
}
 
Example 9
Source File: IgniteDynamicCacheStartSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testStartFromClientNode() throws Exception {
    try {
        testAttribute = false;

        startGrid(nodeCount());

        final IgniteEx kernal = grid(0);

        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

        ccfg.setName(DYNAMIC_CACHE_NAME);

        ccfg.setNodeFilter(NODE_FILTER);

        final IgniteKernal started = (IgniteKernal)grid(nodeCount());

        started.createCache(ccfg);

        GridCacheAdapter<Object, Object> cache = started.internalCache(DYNAMIC_CACHE_NAME);

        assertNotNull(cache);
        assertFalse(cache.context().affinityNode());

        // Should obtain client cache on new node.
        IgniteCache<Object, Object> clientCache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);

        clientCache.put("1", "1");

        for (int g = 0; g < nodeCount() + 1; g++)
            assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1"));

        kernal.destroyCache(DYNAMIC_CACHE_NAME);
    }
    finally {
        stopGrid(nodeCount());
    }
}
 
Example 10
Source File: SchemaExchangeSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Make sure that new metadata can be propagated after destroy.
 *
 * @throws Exception If failed.
 */
@Test
public void testDynamicRestarts() throws Exception {
    IgniteEx node1 = start(1, KeyClass.class, ValueClass.class);
    IgniteEx node2 = startNoCache(2);
    IgniteEx node3 = startClientNoCache(3);
    IgniteEx node4 = startClientNoCache(4);

    assertTypes(node1, ValueClass.class);
    assertTypes(node2, ValueClass.class);
    assertCacheStarted(CACHE_NAME, node1, node2);

    assertTypes(node3, ValueClass.class);
    assertCacheNotStarted(CACHE_NAME, node3);

    node3.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node3);

    // Check restarts from the first node.
    destroySqlCache(node1);

    node1.getOrCreateCache(cacheConfiguration());

    assertTypes(node1);
    assertTypes(node2);
    assertTypes(node3);

    node1.destroyCache(CACHE_NAME);

    node1.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class,
        KeyClass2.class, ValueClass2.class));

    assertTypes(node1, ValueClass.class, ValueClass2.class);
    assertTypes(node2, ValueClass.class, ValueClass2.class);
    assertTypes(node3, ValueClass.class, ValueClass2.class);

    assertCacheStarted(CACHE_NAME, node1, node2);

    assertCacheNotStarted(CACHE_NAME, node3);

    node3.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node3);

    // Check restarts from the second node.
    node2.destroyCache(CACHE_NAME);

    node2.getOrCreateCache(cacheConfiguration());

    assertTypes(node1);
    assertTypes(node2);
    assertTypes(node3);

    node2.destroyCache(CACHE_NAME);

    node2.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class,
        KeyClass2.class, ValueClass2.class));

    assertTypes(node1, ValueClass.class, ValueClass2.class);
    assertTypes(node2, ValueClass.class, ValueClass2.class);
    assertTypes(node3, ValueClass.class, ValueClass2.class);
    assertTypes(node4, ValueClass.class, ValueClass2.class);

    assertCacheStarted(CACHE_NAME, node1, node2);

    assertCacheNotStarted(CACHE_NAME, node3);

    node3.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node3);

    assertCacheNotStarted(CACHE_NAME, node4);

    node4.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node4);

    // Make sure that joining node observes correct state.
    assertTypes(start(5), ValueClass.class, ValueClass2.class);
    assertTypes(startNoCache(6), ValueClass.class, ValueClass2.class);

    assertTypes(startClient(7), ValueClass.class, ValueClass2.class);

    IgniteEx node8 = startClientNoCache(8);

    assertTypes(node8, ValueClass.class, ValueClass2.class);

    assertCacheNotStarted(CACHE_NAME, node8);

    node8.cache(CACHE_NAME);

    assertCacheStarted(CACHE_NAME, node8);
}
 
Example 11
Source File: IgniteDynamicCacheStartSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testStartNearCacheFromClientNode() throws Exception {
    try {
        testAttribute = false;

        startGrid(nodeCount());

        final IgniteEx kernal = grid(0);

        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

        ccfg.setName(DYNAMIC_CACHE_NAME);

        ccfg.setNodeFilter(NODE_FILTER);

        final IgniteKernal started = (IgniteKernal)grid(nodeCount());

        NearCacheConfiguration nearCfg = new NearCacheConfiguration();

        started.createCache(ccfg, nearCfg);

        GridCacheAdapter<Object, Object> cache = started.internalCache(DYNAMIC_CACHE_NAME);

        assertNotNull(cache);
        assertFalse(cache.context().affinityNode());
        assertTrue(cache.context().isNear());

        // Should obtain client cache on new node.
        IgniteCache<Object, Object> clientCache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);

        clientCache.put("1", "1");

        for (int g = 0; g < nodeCount() + 1; g++)
            assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1"));

        kernal.destroyCache(DYNAMIC_CACHE_NAME);
    }
    finally {
        stopGrid(nodeCount());
    }
}