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

The following examples show how to use org.apache.ignite.Ignite#createCaches() . 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: IgnitePdsDestroyCacheAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ignite Ignite.
 */
protected void startCachesDynamically(Ignite ignite) {
    List<CacheConfiguration> ccfg = new ArrayList<>(CACHES);

    for (int i = 0; i < CACHES; i++)
        ccfg.add(new CacheConfiguration<>(cacheName(i))
                .setBackups(1)
                .setAffinity(new RendezvousAffinityFunction(false, 32)));

    ignite.createCaches(ccfg);
}
 
Example 2
Source File: IgnitePdsDestroyCacheAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ignite Ignite instance.
 * @param loc {@code True} for local caches.
 */
protected void startGroupCachesDynamically(Ignite ignite, boolean loc) {
    List<CacheConfiguration> ccfg = new ArrayList<>(CACHES);

    for (int i = 0; i < CACHES; i++)
        ccfg.add(new CacheConfiguration<>(cacheName(i)).setCacheMode(loc ? LOCAL : CacheMode.PARTITIONED)
            .setGroupName(i % 2 == 0 ? "grp-even" : "grp-odd")
            .setBackups(1)
            .setAffinity(new RendezvousAffinityFunction(false, 32)));

    ignite.createCaches(ccfg);
}
 
Example 3
Source File: IgnitePdsCacheConfigurationFileConsistencyCheckTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param ignite Ignite instance.
 */
private void startCaches(Ignite ignite) {
    List<CacheConfiguration> ccfg = new ArrayList<>(CACHES);

    for (int i = 0; i < CACHES; i++) {
        ccfg.add(new CacheConfiguration<>(cacheName(i))
                .setGroupName(i % 2 == 0 ? ODD_GROUP_NAME : EVEN_GROUP_NAME)
                .setBackups(1)
                .setAffinity(new RendezvousAffinityFunction(false, 32)));
    }

    ignite.createCaches(ccfg);
}
 
Example 4
Source File: IgniteClusterActivateDeactivateTestWithPersistence.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private Map<Integer, Integer> startGridsAndLoadData(int srvs, ClusterState activationMode) throws Exception {
    assertActive(activationMode);

    Ignite srv = startGrids(srvs);

    srv.cluster().state(ACTIVE);

    srv.createCaches(Arrays.asList(cacheConfigurations1()));

    srv.cluster().state(activationMode);

    Map<Integer, Integer> cacheData = new LinkedHashMap<>();

    for (CacheConfiguration ccfg : cacheConfigurations1()) {
        for (int i = 1; i <= 100; i++) {
            int key = -i;
            int val = i;

            if (activationMode == ACTIVE) {
                srv.cache(ccfg.getName()).put(key, val);

                cacheData.put(key, val);
            }
            else {
                assertThrowsWithCause(() -> srv.cache(ccfg.getName()).put(key, val), IgniteClusterReadOnlyException.class);

                cacheData.put(key, null);
            }
        }
    }

    return cacheData;
}
 
Example 5
Source File: IgnitePersistentStoreCacheGroupsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCreateDropCache1() throws Exception {
    CacheConfiguration ccfg1 = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1);

    CacheConfiguration ccfg2 = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1);

    Ignite ignite = startGrid();

    ignite.active(true);

    ignite.createCaches(Arrays.asList(ccfg1, ccfg2));

    ignite.cache("c1").destroy();

    ignite.cache("c2").destroy();

    ignite.createCache(ccfg1);
    ignite.createCache(ccfg2);

    stopGrid();
}
 
Example 6
Source File: IgnitePersistentStoreCacheGroupsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCreateDropCache2() throws Exception {
    CacheConfiguration ccfg1 = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1)
        .setIndexedTypes(Integer.class, Person.class);

    CacheConfiguration ccfg2 = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1)
        .setIndexedTypes(Integer.class, Person.class);

    Ignite ignite = startGrid();

    ignite.active(true);

    ignite.createCaches(Arrays.asList(ccfg1, ccfg2));

    ignite.cache("c1").destroy();

    ignite.createCache(ccfg1);

    stopGrid();
}
 
Example 7
Source File: GridCommandHandlerClusterByClassTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Very basic tests for running the command in different enviroment which other command are running in.
 */
@Test
public void testFindAndDeleteGarbage() {
    Ignite ignite = crd;

    injectTestSystemOut();

    ignite.createCaches(Arrays.asList(
        new CacheConfiguration<>("garbage1").setGroupName("groupGarbage"),
        new CacheConfiguration<>("garbage2").setGroupName("groupGarbage")));

    assertEquals(EXIT_CODE_OK, execute("--cache", "find_garbage", "--port", "11212"));

    assertContains(log, testOut.toString(), "garbage not found");

    assertEquals(EXIT_CODE_OK, execute("--cache", "find_garbage",
        ignite(0).localNode().id().toString(), "--port", "11212"));

    assertContains(log, testOut.toString(), "garbage not found");

    assertEquals(EXIT_CODE_OK, execute("--cache", "find_garbage",
        "groupGarbage", "--port", "11212"));

    assertContains(log, testOut.toString(), "garbage not found");
}
 
Example 8
Source File: GridCommandHandlerClusterByClassTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** */
private void testCacheConfig(String outputFormat, int nodesCnt, int cachesCnt) {
    assertTrue("Invalid number of nodes or caches", nodesCnt > 0 && cachesCnt > 0);

    Ignite ignite = crd;

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

    for (int i = 0; i < cachesCnt; i++) {
        ccfgs.add(
            new CacheConfiguration<>()
                .setAffinity(new RendezvousAffinityFunction(false, 32))
                .setBackups(1)
                .setName(DEFAULT_CACHE_NAME + i)
        );
    }

    ignite.createCaches(ccfgs);

    IgniteCache<Object, Object> cache1 = ignite.cache(DEFAULT_CACHE_NAME + 0);

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

    injectTestSystemOut();

    int exitCode;

    if (outputFormat == null)
        exitCode = execute("--cache", "list", ".*", "--config");
    else
        exitCode = execute("--cache", "list", ".*", "--config", "--output-format", outputFormat);

    assertEquals(EXIT_CODE_OK, exitCode);

    String outStr = testOut.toString();

    if (outputFormat == null || SINGLE_LINE.text().equals(outputFormat)) {
        for (int i = 0; i < cachesCnt; i++)
            assertContains(log, outStr, "name=" + DEFAULT_CACHE_NAME + i);

        assertContains(log, outStr, "partitions=32");
        assertContains(log, outStr, "function=o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction");
    }
    else if (MULTI_LINE.text().equals(outputFormat)) {
        for (int i = 0; i < cachesCnt; i++)
            assertContains(log, outStr, "[cache = '" + DEFAULT_CACHE_NAME + i + "']");

        assertContains(log, outStr, "Affinity Partitions: 32");
        assertContains(log, outStr, "Affinity Function: o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction");
    }
    else
        fail("Unknown output format: " + outputFormat);
}
 
Example 9
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @param cacheMode Cache mode.
 * @param atomicityMode Atomicity mode.
 * @throws Exception If failed.
 */
private void loadCache(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
    int keys = 100;

    boolean loc = cacheMode == LOCAL;

    Map<Integer, Integer> data1 = generateDataMap(keys);
    Map<Integer, Integer> data2 = generateDataMap(keys);

    Factory<? extends CacheStore<Integer, Integer>> fctr1 =
        FactoryBuilder.factoryOf(new MapBasedStore<>(data1));

    Factory<? extends CacheStore<Integer, Integer>> fctr2 =
        FactoryBuilder.factoryOf(new MapBasedStore<>(data2));

    CacheConfiguration ccfg1 = cacheConfiguration(GROUP1, CACHE1, cacheMode, atomicityMode, 1, false)
        .setCacheStoreFactory(fctr1);

    CacheConfiguration ccfg2 = cacheConfiguration(GROUP1, CACHE2, cacheMode, atomicityMode, 1, false)
        .setCacheStoreFactory(fctr2);

    Ignite node = startGrids(loc ? 1 : 4);

    node.createCaches(F.asList(ccfg1, ccfg2));

    IgniteCache<Integer, Integer> cache1 = node.cache(CACHE1);
    IgniteCache<Integer, Integer> cache2 = node.cache(CACHE2);

    cache1.loadCache(null);

    checkCacheData(data1, CACHE1);

    assertEquals(0, cache2.size());

    cache2.loadCache(null);

    checkCacheData(data2, CACHE2);
}
 
Example 10
Source File: IgnitePersistentStoreCacheGroupsTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
@Test
public void testClusterRestartCachesWithH2Indexes() throws Exception {
    CacheConfiguration[] ccfgs1 = new CacheConfiguration[5];

    // Several caches with the same indexed type (and index names).
    ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1).
        setIndexedTypes(Integer.class, Person.class);
    ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1).
        setIndexedTypes(Integer.class, Person.class);
    ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1).
        setIndexedTypes(Integer.class, Person.class);
    ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1).
        setIndexedTypes(Integer.class, Person.class);
    ccfgs1[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1).
        setIndexedTypes(Integer.class, Person.class);

    String[] caches = {"c1", "c2", "c3", "c4", "c5"};

    startGrids(3);

    Ignite node = ignite(0);

    node.active(true);

    node.createCaches(Arrays.asList(ccfgs1));

    putPersons(caches, node);

    checkPersons(caches, node);
    checkPersonsQuery(caches, node);

    stopAllGrids();

    startGrids(3);

    node = ignite(0);

    node.active(true);

    awaitPartitionMapExchange();

    checkPersons(caches, node);
    checkPersonsQuery(caches, node);

    Random rnd = ThreadLocalRandom.current();

    int idx = rnd.nextInt(caches.length);

    String cacheName = caches[idx];
    CacheConfiguration cacheCfg = ccfgs1[idx];

    node.destroyCache(cacheName);

    node.createCache(cacheCfg);

    putPersons(new String[]{cacheName}, node);

    checkPersons(caches, node);
    checkPersonsQuery(caches, node);
}