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

The following examples show how to use org.apache.ignite.Ignite#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: IgniteCountDownLatchAbstractSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testLatchBroadcast() throws Exception {
    Ignite ignite = grid(0);
    ClusterGroup srvsGrp = ignite.cluster().forServers();

    int numOfSrvs = srvsGrp.nodes().size();

    ignite.destroyCache("testCache");
    IgniteCache<Object, Object> cache = ignite.createCache("testCache");

    for (ClusterNode node : srvsGrp.nodes())
        cache.put(String.valueOf(node.id()), 0);

    for (int i = 0; i < 500; i++) {
        IgniteCountDownLatch latch1 = createLatch1(ignite, numOfSrvs);
        IgniteCountDownLatch latch2 = createLatch2(ignite, numOfSrvs);

        ignite.compute(srvsGrp).broadcast(new IgniteRunnableJob(latch1, latch2, i));
        assertTrue(latch2.await(10000));
    }
}
 
Example 2
Source File: DataStreamerUpdateAfterLoadTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testUpdateAfterLoad() throws Exception {
    Ignite ignite0 = ignite(0);

    for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
        int key = 0;

        try (IgniteCache<Integer, Integer> cache = ignite0.createCache(ccfg)) {
            key = testLoadAndUpdate(cache.getName(), key, false);

            testLoadAndUpdate(cache.getName(), key, true);

            ignite0.destroyCache(cache.getName());
        }
    }
}
 
Example 3
Source File: IgniteTxCachePrimarySyncTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testTxSyncMode() throws Exception {
    Ignite ignite = ignite(0);

    List<IgniteCache<Object, Object>> caches = new ArrayList<>();

    try {

        caches.add(createCache(ignite, cacheConfiguration("fullSync1", FULL_SYNC, 1, false, false)));
        caches.add(createCache(ignite, cacheConfiguration("fullSync2", FULL_SYNC, 1, false, false)));
        caches.add(createCache(ignite, cacheConfiguration("fullAsync1", FULL_ASYNC, 1, false, false)));
        caches.add(createCache(ignite, cacheConfiguration("fullAsync2", FULL_ASYNC, 1, false, false)));
        caches.add(createCache(ignite, cacheConfiguration("primarySync1", PRIMARY_SYNC, 1, false, false)));
        caches.add(createCache(ignite, cacheConfiguration("primarySync2", PRIMARY_SYNC, 1, false, false)));

        for (int i = 0; i < NODES; i++) {
            checkTxSyncMode(ignite(i), true);
            checkTxSyncMode(ignite(i), false);
        }
    }
    finally {
        for (IgniteCache<Object, Object> cache : caches)
            ignite.destroyCache(cache.getName());
    }
}
 
Example 4
Source File: IgniteDbDynamicCacheSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCreate() throws Exception {
    int iterations = 200;

    startGrids(3);

    Ignite ignite = ignite(0);

    ignite.active(true);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setName("cache1");
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));

    if (MvccFeatureChecker.forcedMvcc())
        ccfg.setRebalanceDelay(Long.MAX_VALUE);
    else
        ccfg.setRebalanceMode(CacheRebalanceMode.NONE);

    for (int k = 0; k < iterations; k++) {
        System.out.println("Iteration: " + k);

        IgniteCache cache = ignite.createCache(ccfg);

        awaitPartitionMapExchange();

        ignite.destroyCache(ccfg.getName());

        awaitPartitionMapExchange();
    }
}
 
Example 5
Source File: CacheQueryNewClientSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testQueryFromNewClient() throws Exception {
    Ignite srv = startGrid("server");

    for (int iter = 0; iter < 2; iter++) {
        log.info("Iteration: " + iter);

        IgniteCache<Integer, Integer> cache1 = srv.createCache(new CacheConfiguration<Integer, Integer>().
            setName("cache1").setIndexedTypes(Integer.class, Integer.class));
        IgniteCache<Integer, Integer> cache2 = srv.createCache(new CacheConfiguration<Integer, Integer>().
            setName("cache2").setIndexedTypes(Integer.class, Integer.class));

        for (int i = 0; i < 10; i++) {
            cache1.put(i, i);
            cache2.put(i, i);
        }

        Ignite client = (iter == 0) ? startClientGrid("client") : grid("client");

        IgniteCache<Integer, Integer> cache = client.cache("cache1");

        List<List<?>> res = cache.query(new SqlFieldsQuery(
            "select i1._val, i2._val from Integer i1 cross join \"cache2\".Integer i2")).getAll();

        assertEquals(100, res.size());

        srv.destroyCache(cache1.getName());
        srv.destroyCache(cache2.getName());
    }
}
 
Example 6
Source File: CacheSerializableTransactionsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheName Cache name.
 */
private void destroyCache(String cacheName) {
    storeMap.clear();

    for (Ignite ignite : G.allGrids()) {
        try {
            ignite.destroyCache(cacheName);
        }
        catch (IgniteException ignore) {
            // No-op.
        }
    }
}
 
Example 7
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Atomicity mode.
 * @param backups Number of backups.
 * @param heapCache On heap cache flag.
 * @param nearSrv {@code True} if near cache should be used on a server side.
 * @param nearClient {@code True} if near cache should be used on a client side.
 * @throws Exception If failed.
 */
private void cacheApiTest(CacheMode cacheMode,
    CacheAtomicityMode atomicityMode,
    int backups,
    boolean heapCache,
    boolean nearSrv,
    boolean nearClient) throws Exception {
    Ignite srv0 = ignite(0);

    NearCacheConfiguration nearCfg = nearSrv ? new NearCacheConfiguration() : null;

    srv0.createCache(cacheConfiguration(GROUP1, "cache-0", cacheMode, atomicityMode, backups, heapCache)
        .setNearConfiguration(nearCfg));

    srv0.createCache(cacheConfiguration(GROUP1, "cache-1", cacheMode, atomicityMode, backups, heapCache));

    srv0.createCache(cacheConfiguration(GROUP2, "cache-2", cacheMode, atomicityMode, backups, heapCache)
        .setNearConfiguration(nearCfg));

    srv0.createCache(cacheConfiguration(null, "cache-3", cacheMode, atomicityMode, backups, heapCache));

    if (nearClient) {
        Ignite clientNode = ignite(4);

        clientNode.createNearCache("cache-0", new NearCacheConfiguration());
        clientNode.createNearCache("cache-2", new NearCacheConfiguration());
    }

    try {
        for (final Ignite node : Ignition.allGrids()) {
            List<Callable<?>> ops = new ArrayList<>();

            for (int i = 0; i < 4; i++)
                ops.add(testSet(node.cache("cache-" + i), cacheMode, atomicityMode, backups, heapCache, node));

            // Async operations.
            GridTestUtils.runMultiThreaded(ops, "cacheApiTest");
        }
    }
    finally {
        for (int i = 0; i < 4; i++)
            srv0.destroyCache("cache-" + i);
    }
}
 
Example 8
Source File: CacheNearReaderUpdateTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param ignite Node.
 * @param cacheName Cache name.
 */
private void destroyCache(Ignite ignite, String cacheName) {
    storeMap.clear();

    ignite.destroyCache(cacheName);
}
 
Example 9
Source File: BasicJavaTypesIndexTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Executes test scenario: <ul>
 * <li>Create cache</li>
 * <li>Populate cache with random data</li>
 * <li>Verify range query on created table</li>
 * <li>Verify that table stores the same data as the generated dataset</li>
 * <li>Destroy cache</li>
 * </ul>
 *
 * @param idxCls Index type class.
 * @param comp Comparator to sort data set to perform range check.
 * If {@code null} range check will not be performed.
 * @param keyCls Key type class. Will be used to generate KEY object
 * for cache operations. If {@code null} idxCls will be used.
 * @param <Key> Type of the key in terms of the cache.
 * @param <Idx> Type of the indexed field.
 */
private <Key extends ClassWrapper, Idx> void createPopulateAndVerify(Class<Idx> idxCls,
    @Nullable Comparator<Idx> comp, @Nullable Class<Key> keyCls) {
    Ignite ign = grid(0);

    String tblName = idxCls.getSimpleName().toUpperCase() + "_TBL" + TBL_ID.incrementAndGet();

    try {
        // Create cache
        LinkedHashMap<String, String> fields = new LinkedHashMap<>(2);

        fields.put("idxVal", idxCls.getName());
        fields.put("val", Integer.class.getName());

        QueryEntity qe = new QueryEntity(keyCls == null ? idxCls.getName() : keyCls.getName(), Integer.class.getName())
            .setTableName(tblName)
            .setValueFieldName("val")
            .setFields(fields);

        String idxName;
        String idxFieldName;

        if (keyCls == null) {
            qe.setKeyFieldName("idxVal");

            idxName = PK_IDX_NAME;
            idxFieldName = KEY_FIELD_NAME;
        }
        else {
            idxFieldName = "idxVal";

            qe.setKeyFields(Collections.singleton(idxFieldName));

            if (keyCls.equals(TestKeyWithAff.class))
                idxName = AFFINITY_KEY_IDX_NAME;
            else {
                idxName = "IDXVAL_IDX";

                qe.setIndexes(Collections.singleton(new QueryIndex(idxFieldName, true, idxName)));
            }
        }

        IgniteCache<Object, Integer> cache = ign.createCache(
            new CacheConfiguration<Object, Integer>(tblName + "_CACHE")
                .setKeyConfiguration(new CacheKeyConfiguration((keyCls != null ? keyCls : idxCls).getName(), "idxVal"))
                .setQueryEntities(Collections.singletonList(qe)).setSqlSchema("PUBLIC"));

        // Then populate it with random data
        Map<Idx, Integer> data = new TreeMap<>(comp);

        if (keyCls == null)
            populateTable(data, cache, idxCls);
        else
            populateTable(data, cache, keyCls, idxCls);

        // Perform necessary verifications
        if (comp != null)
            verifyRange(data, tblName, idxFieldName, idxName, comp);

        verifyEach(data, tblName, idxFieldName, idxName);
    }
    finally {
        // Destroy cache
        ign.destroyCache(tblName + "_CACHE");
    }
}
 
Example 10
Source File: IgniteCacheDistributedJoinQueryConditionsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testJoinQuery4() throws Exception {
    Ignite client = grid(2);

    try {
        CacheConfiguration ccfg1 =
            cacheConfiguration(PERSON_CACHE).setQueryEntities(F.asList(personEntity(true, false)));

        IgniteCache<Object, Object> pCache = client.createCache(ccfg1);

        ClusterNode node0 = ignite(0).cluster().localNode();
        ClusterNode node1 = ignite(1).cluster().localNode();

        Affinity<Object> aff = client.affinity(PERSON_CACHE);

        AtomicInteger pKey = new AtomicInteger();

        Integer pId0 = keyForNode(aff, pKey, node0);

        pCache.put(pId0, new Person(0, "p0"));

        for (int i = 0; i < 3; i++) {
            Integer pId = keyForNode(aff, pKey, node1);

            pCache.put(pId, new Person(0, "p"));
        }

        checkQuery("select p1._key, p1.name, p2._key, p2.name " +
            "from Person p1, Person p2 " +
            "where p2._key > p1._key", pCache, 6);

        checkQuery("select p1._key, p1.name, p2._key, p2.name " +
            "from Person p1, Person p2 " +
            "where p2._key > p1._key and p1._key=" + pId0, pCache, 3);

        checkQuery("select p1._key, p1.name, p2._key, p2.name " +
            "from Person p1, Person p2 " +
            "where p2._key > p1._key and p1.name='p0'", pCache, 3);

        checkQuery("select p1._key, p1.name, p2._key, p2.name " +
            "from Person p1, Person p2 " +
            "where p1.name > p2.name", pCache, 3);
    }
    finally {
        client.destroyCache(PERSON_CACHE);
        client.destroyCache(ORG_CACHE);
    }
}
 
Example 11
Source File: CacheLateAffinityAssignmentTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCacheStartDestroy() throws Exception {
    startGridsMultiThreaded(3, false);

    for (int i = 0; i < 3; i++)
        calculateAffinity(i + 1);

    checkAffinity(3, topVer(3, 1), true);

    Ignite client = startClient(3, 4);

    checkAffinity(4, topVer(4, 0), true);

    CacheConfiguration ccfg = cacheConfiguration();

    ccfg.setName(CACHE_NAME2);

    ignite(0).createCache(ccfg);

    calculateAffinity(4);

    checkAffinity(4, topVer(4, 1), true);

    client.cache(CACHE_NAME2);

    checkAffinity(4, topVer(4, 1), true);

    client.destroyCache(CACHE_NAME2);

    checkAffinity(4, topVer(4, 2), true);
}
 
Example 12
Source File: IgniteSemaphoreAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Implementation of ignite data structures internally uses special system caches, need make sure
 * that transaction on these system caches do not intersect with transactions started by user.
 *
 * @throws Exception If failed.
 */
@Test
public void testIsolation() throws Exception {
    Ignite ignite = grid(0);

    CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    cfg.setName("myCache");
    cfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setWriteSynchronizationMode(FULL_SYNC);

    IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(cfg);

    try {
        IgniteSemaphore semaphore = ignite.semaphore("testIsolation", 1, true, true);

        assertNotNull(semaphore);

        try (Transaction tx = ignite.transactions().txStart()) {
            cache.put(1, 1);

            assertEquals(1, semaphore.availablePermits());

            semaphore.acquire();

            tx.rollback();
        }

        assertEquals(0, cache.size());

        assertEquals(0, semaphore.availablePermits());

        semaphore.close();

        assertTrue(semaphore.removed());
    }
    finally {
        ignite.destroyCache(cfg.getName());
    }
}
 
Example 13
Source File: TcpDiscoverySelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDiscoveryEventsDiscard() throws Exception {
    try {
        TestEventDiscardSpi spi = new TestEventDiscardSpi();

        nodeSpi.set(spi);

        Ignite ignite0 = startGrid(0);

        startGrid(1);

        ignite0.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)); // Send custom message.

        ignite0.destroyCache(DEFAULT_CACHE_NAME); // Send custom message.

        stopGrid(1);

        log.info("Start new node.");

        spi.checkDuplicates = true;

        startGrid(1);

        spi.checkDuplicates = false;

        assertFalse(spi.failed);
    }
    finally {
        stopAllGrids();
    }
}
 
Example 14
Source File: CacheLateAffinityAssignmentTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Wait for rebalance, cache is destroyed.
 *
 * @throws Exception If failed.
 */
@Test
public void testDelayAssignmentCacheDestroy() throws Exception {
    Ignite ignite0 = startServer(0, 1);

    CacheConfiguration ccfg = cacheConfiguration();

    ccfg.setName(CACHE_NAME2);

    ignite0.createCache(ccfg);

    TestRecordingCommunicationSpi spi =
        (TestRecordingCommunicationSpi)ignite0.configuration().getCommunicationSpi();

    blockSupplySend(spi, CACHE_NAME2);

    startServer(1, 2);

    startServer(2, 3);

    checkAffinity(3, topVer(3, 0), false);

    ignite0.destroyCache(CACHE_NAME2);

    checkAffinity(3, topVer(3, 1), false);

    checkAffinity(3, topVer(3, 2), true);

    spi.stopBlock();
}
 
Example 15
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDiscoveryDataConsistency1() throws Exception {
    ccfgs = staticConfigurations1(true);
    Ignite srv0 = startGrid(0);

    ccfgs = staticConfigurations1(true);
    startGrid(1);

    checkCacheDiscoveryDataConsistent();

    ccfgs = null;
    startGrid(2);

    checkCacheDiscoveryDataConsistent();

    srv0.createCache(cacheConfiguration(null, "cache4", PARTITIONED, ATOMIC, 2, false));

    checkCacheDiscoveryDataConsistent();

    ccfgs = staticConfigurations1(true);
    startGrid(3);

    checkCacheDiscoveryDataConsistent();

    srv0.createCache(cacheConfiguration(GROUP1, "cache5", PARTITIONED, ATOMIC, 2, false));

    ccfgs = staticConfigurations1(true);
    startGrid(4);

    checkCacheDiscoveryDataConsistent();

    for (int i = 0; i < 5; i++)
        checkCacheGroup(i, GROUP1, true);

    srv0.destroyCache("cache1");
    srv0.destroyCache("cache2");
    srv0.destroyCache("cache3");

    checkCacheDiscoveryDataConsistent();

    ccfgs = staticConfigurations1(true);
    startGrid(5);

    checkCacheDiscoveryDataConsistent();

    for (int i = 0; i < 6; i++)
        checkCacheGroup(i, GROUP1, true);

    srv0.destroyCache("cache1");
    srv0.destroyCache("cache2");
    srv0.destroyCache("cache3");
    srv0.destroyCache("cache4");
    srv0.destroyCache("cache5");

    ccfgs = staticConfigurations1(true);
    startGrid(6);

    checkCacheDiscoveryDataConsistent();

    srv0.createCache(cacheConfiguration(null, "cache4", PARTITIONED, ATOMIC, 2, false));
    srv0.createCache(cacheConfiguration(GROUP1, "cache5", PARTITIONED, ATOMIC, 2, false));

    checkCacheDiscoveryDataConsistent();

    ccfgs = staticConfigurations1(false);
    startGrid(7);

    checkCacheDiscoveryDataConsistent();

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

    client = true;

    startGrid(4);

    for (CacheConfiguration ccfg : cacheConfigurations()) {
        IgniteCache<Object, Object> cache0 = srv0.createCache(ccfg);

        final Map<Integer, Integer> startVals = new HashMap<>();

        final int KEYS = 10;

        for (int i = 0; i < KEYS; i++)
            startVals.put(i, 0);

        for (final TransactionIsolation isolation : TransactionIsolation.values()) {
            for (final Ignite node : G.allGrids()) {
                info("Run test [node=" + node.name() + ", isolation=" + isolation + ']');

                try (Transaction tx = srv0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                    cache0.putAll(startVals);

                    tx.commit();
                }

                final CountDownLatch readStart = new CountDownLatch(1);

                final CountDownLatch readProceed = new CountDownLatch(1);

                IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Void>() {
                    @Override public Void call() throws Exception {
                        IgniteCache<Object, Object> cache = node.cache(DEFAULT_CACHE_NAME);

                        try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                            assertEquals(0, checkAndGet(false, cache, 0, SCAN, GET));

                            readStart.countDown();

                            assertTrue(readProceed.await(5, TimeUnit.SECONDS));

                            assertEquals(0, checkAndGet(true, cache, 1, GET, SCAN));

                            assertEquals(0, checkAndGet(true, cache, 2, GET, SCAN));

                            Map<Object, Object> res = checkAndGetAll(true, cache, startVals.keySet(), GET, SCAN);

                            assertEquals(startVals.size(), res.size());

                            for (Map.Entry<Object, Object> e : res.entrySet())
                                assertEquals("Invalid value for key: " + e.getKey(), 0, e.getValue());

                            tx.rollback();
                        }

                        return null;
                    }
                });

                assertTrue(readStart.await(5, TimeUnit.SECONDS));

                for (int i = 0; i < KEYS; i++) {
                    try (Transaction tx = srv0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                        if (i % 2 == 0)
                            cache0.put(i, 1);
                        else
                            cache0.remove(i);

                        tx.commit();
                    }
                }

                readProceed.countDown();

                fut.get();
            }
        }

        srv0.destroyCache(cache0.getName());
    }
}
 
Example 17
Source File: GridCacheQueueApiSelfAbstractTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Implementation of ignite data structures internally uses special system caches, need make sure
 * that transaction on these system caches do not intersect with transactions started by user.
 *
 * @throws Exception If failed.
 */
@Test
public void testIsolation() throws Exception {
    Ignite ignite = grid(0);

    CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    cfg.setName("myCache");
    cfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setWriteSynchronizationMode(FULL_SYNC);

    IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(cfg);

    try {
        String queueName = UUID.randomUUID().toString();

        IgniteQueue<String> queue = initQueue(0, queueName, 0, config(false));

        try (Transaction tx = ignite.transactions().txStart()) {
            cache.put(1, 1);

            for (int i = 0; i < QUEUE_CAPACITY; i++)
                queue.put("Item-" + i);

            tx.rollback();
        }

        assertEquals(0, cache.size());

        assertEquals(QUEUE_CAPACITY, queue.size());

        queue.remove("Item-1");

        assertEquals(QUEUE_CAPACITY - 1, queue.size());

        assertEquals("Item-0", queue.peek());
        assertEquals("Item-0", queue.poll());
        assertEquals("Item-2", queue.poll());

        assertEquals(0, queue.size());

        queue.clear();

        assertTrue(queue.isEmpty());
    }
    finally {
        ignite.destroyCache(cfg.getName());
    }
}
 
Example 18
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDataCleanup() throws Exception {
    Ignite node = startGrid(0);

    IgniteCache cache0 = node.createCache(cacheConfiguration(GROUP1, "c0", PARTITIONED, ATOMIC, 1, false));

    for (int i = 0; i < 100; i++)
        assertNull(cache0.get(i));

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

    List<CacheConfiguration> ccfgs = new ArrayList<>();

    ccfgs.add(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, false));
    ccfgs.add(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1, true));
    ccfgs.add(cacheConfiguration(GROUP1, "c1", PARTITIONED, TRANSACTIONAL, 1, false));
    ccfgs.add(cacheConfiguration(GROUP1, "c1", PARTITIONED, TRANSACTIONAL, 1, true));

    for (CacheConfiguration ccfg : ccfgs) {
        IgniteCache cache = node.createCache(ccfg);

        for (int i = 0; i < 100; i++)
            assertNull(cache.get(i));

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

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

        node.destroyCache(ccfg.getName());

        cache = node.createCache(ccfg);

        for (int i = 0; i < 100; i++)
            assertNull(cache.get(i));

        node.destroyCache(ccfg.getName());
    }

    for (int i = 0; i < 100; i++)
        assertEquals(i, cache0.get(i));

    node.destroyCache(cache0.getName());

    cache0 = node.createCache(cacheConfiguration(GROUP1, "c0", PARTITIONED, ATOMIC, 1, false));

    for (int i = 0; i < 100; i++)
        assertNull(cache0.get(i));

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

    for (int i = 0; i < 100; i++)
        assertEquals(i, cache0.get(i));
}
 
Example 19
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @param srvs Number of server nodes.
 * @throws Exception If failed.
 */
private void createDestroyCaches(int srvs) throws Exception {
    startGridsMultiThreaded(srvs);

    checkCacheDiscoveryDataConsistent();

    Ignite srv0 = ignite(0);

    for (int i = 0; i < srvs; i++)
        checkCacheGroup(i, GROUP1, false);

    for (int iter = 0; iter < 3; iter++) {
        log.info("Iteration: " + iter);

        srv0.createCache(cacheConfiguration(GROUP1, CACHE1, PARTITIONED, ATOMIC, 2, false));

        checkCacheDiscoveryDataConsistent();

        for (int i = 0; i < srvs; i++) {
            checkCacheGroup(i, GROUP1, true);

            checkCache(i, CACHE1, 10);
        }

        srv0.createCache(cacheConfiguration(GROUP1, CACHE2, PARTITIONED, ATOMIC, 2, false));

        checkCacheDiscoveryDataConsistent();

        for (int i = 0; i < srvs; i++) {
            checkCacheGroup(i, GROUP1, true);

            checkCache(i, CACHE2, 10);
        }

        srv0.destroyCache(CACHE1);

        checkCacheDiscoveryDataConsistent();

        for (int i = 0; i < srvs; i++) {
            checkCacheGroup(i, GROUP1, true);

            checkCache(i, CACHE2, 10);
        }

        srv0.destroyCache(CACHE2);

        checkCacheDiscoveryDataConsistent();

        for (int i = 0; i < srvs; i++)
            checkCacheGroup(i, GROUP1, false);
    }
}
 
Example 20
Source File: CacheLateAffinityAssignmentTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}