Java Code Examples for org.apache.ignite.IgniteCache#loadCache()

The following examples show how to use org.apache.ignite.IgniteCache#loadCache() . 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: IgniteCacheQueryLoadSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testLoadCache() throws Exception {
    IgniteCache<Integer, ValueObject> cache = grid().cache(DEFAULT_CACHE_NAME);

    cache.loadCache(null);

    assertEquals(PUT_CNT, cache.size());

    Collection<Cache.Entry<Integer, ValueObject>> res =
        cache.query(new SqlQuery(ValueObject.class, "val >= 0")).getAll();

    assertNotNull(res);
    assertEquals(PUT_CNT, res.size());
    assertEquals(PUT_CNT, size(ValueObject.class));
}
 
Example 2
Source File: IgniteCacheStoreClusterReadOnlyModeSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
private void checkAfter() {
    for (String name : cacheNames) {
        for (Ignite node : G.allGrids()) {
            IgniteCache<Object, Object> cache = node.cache(name);

            cache.loadCache(null);

            assertEquals(name, VAL, cache.get(KEY));

            for (int i = 0; i < NODES_CNT; i++)
                assertEquals(name + " " + node.name(), i, cache.get(i));

            assertEquals(name, NODES_CNT + 1, cache.size());
        }
    }
}
 
Example 3
Source File: IgniteCacheExpiryStoreLoadSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param async If {@code true} uses asynchronous method.
 * @throws Exception If failed.
 */
private void checkLoad(boolean async) throws Exception {
    IgniteCache<String, Integer> cache = jcache(0)
       .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));

     List<Integer> keys = new ArrayList<>();

    keys.add(primaryKey(jcache(0)));
    keys.add(primaryKey(jcache(1)));
    keys.add(primaryKey(jcache(2)));

    if (async)
        cache.loadCacheAsync(null, keys.toArray(new Integer[3])).get();
    else
        cache.loadCache(null, keys.toArray(new Integer[3]));

    assertEquals(3, cache.size(CachePeekMode.PRIMARY));

    Thread.sleep(TIME_TO_LIVE + WAIT_TIME);

    assertEquals(0, cache.size());
}
 
Example 4
Source File: IgniteCacheExpiryPolicyWithStoreAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testLoadCache() throws Exception {
    IgniteCache<Integer, Integer> cache = jcache(0);

    final Integer key = primaryKey(cache);

    storeMap.put(key, 100);

    try {
        cache.loadCache(null);

        checkTtl(key, 500, false);

        assertEquals((Integer)100, cache.localPeek(key, CachePeekMode.ONHEAP));

        U.sleep(600);

        checkExpired(key);
    }
    finally {
        cache.removeAll();
    }
}
 
Example 5
Source File: CacheStoreSessionListenerAbstractSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testTransactionalCache() throws Exception {
    CacheConfiguration<Integer, Integer> cfg = cacheConfiguration(DEFAULT_CACHE_NAME, CacheAtomicityMode.TRANSACTIONAL);

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

    try {
        cache.loadCache(null);
        cache.get(1);
        cache.put(1, 1);
        cache.remove(1);
    }
    finally {
        cache.destroy();
    }

    assertEquals(3, loadCacheCnt.get());
    assertEquals(1, loadCnt.get());
    assertEquals(1, writeCnt.get());
    assertEquals(1, deleteCnt.get());
    assertEquals(0, reuseCnt.get());
}
 
Example 6
Source File: CacheStoreSessionListenerAbstractSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testAtomicCache() throws Exception {
    CacheConfiguration<Integer, Integer> cfg = cacheConfiguration(DEFAULT_CACHE_NAME, CacheAtomicityMode.ATOMIC);

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

    try {
        cache.loadCache(null);
        cache.get(1);
        cache.put(1, 1);
        cache.remove(1);
    }
    finally {
        cache.destroy();
    }

    assertEquals(3, loadCacheCnt.get());
    assertEquals(1, loadCnt.get());
    assertEquals(1, writeCnt.get());
    assertEquals(1, deleteCnt.get());
    assertEquals(0, reuseCnt.get());
}
 
Example 7
Source File: CacheJdbcPojoStoreAbstractSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testLoadNotRegisteredType() throws Exception {
    startTestGrid(false, false, false, false, 512);

    IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME);

    try {
        checkFetchSize = true;

        c1.loadCache(null, "PersonKeyWrong", "SELECT * FROM Person");
    }
    catch (CacheLoaderException e) {
        String msg = e.getMessage();

        assertTrue("Unexpected exception: " + msg,
            ("Provided key type is not found in store or cache configuration " +
                "[cache=" + CACHE_NAME + ", key=PersonKeyWrong]").equals(msg));
    } finally {
        checkFetchSize = false;
    }
}
 
Example 8
Source File: CacheHibernateStoreExample.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Makes initial cache loading.
 *
 * @param cache Cache to load.
 */
private static void loadCache(IgniteCache<Long, Person> cache) {
    long start = System.currentTimeMillis();

    // Start loading cache from persistent store on all caching nodes.
    cache.loadCache(null, ENTRY_COUNT);

    long end = System.currentTimeMillis();

    System.out.println(">>> Loaded " + cache.size() + " keys with backups in " + (end - start) + "ms.");
}
 
Example 9
Source File: CacheJdbcStoreExample.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Makes initial cache loading.
 *
 * @param cache Cache to load.
 */
private static void loadCache(IgniteCache<Long, Person> cache) {
    long start = System.currentTimeMillis();

    // Start loading cache from persistent store on all caching nodes.
    cache.loadCache(null, ENTRY_COUNT);

    long end = System.currentTimeMillis();

    System.out.println(">>> Loaded " + cache.size() + " keys with backups in " + (end - start) + "ms.");
}
 
Example 10
Source File: CacheSpringStoreExample.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Makes initial cache loading.
 *
 * @param cache Cache to load.
 */
private static void loadCache(IgniteCache<Long, Person> cache) {
    long start = System.currentTimeMillis();

    // Start loading cache from persistent store on all caching nodes.
    cache.loadCache(null, ENTRY_COUNT);

    long end = System.currentTimeMillis();

    System.out.println(">>> Loaded " + cache.size() + " keys with backups in " + (end - start) + "ms.");
}
 
Example 11
Source File: BinaryMetadataRegistrationCacheStoreTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected void put(IgniteCache<Integer, Object> cache, Integer key, Object val) {
    GLOBAL_STORE.clear();
    GLOBAL_STORE.put(key, val);

    cache.loadCache(null);
}
 
Example 12
Source File: IgniteCacheQueryIndexSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testWithStoreLoad() throws Exception {
    for (int i = 0; i < ENTRY_CNT; i++)
        storeStgy.putToStore(i, new CacheValue(i));

    IgniteCache<Integer, CacheValue> cache0 = grid(0).cache(DEFAULT_CACHE_NAME);

    cache0.loadCache(null);

    checkCache(cache0);
    checkQuery(cache0);
}
 
Example 13
Source File: CacheClientStoreSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Load cache created on client as LOCAL and see if it only loaded on client
 *
 * @throws Exception If failed.
 */
@Test
public void testLocalLoadClient() throws Exception {
    cacheMode = CacheMode.LOCAL;
    factory = new Factory3();

    startGrids(2);

    Ignite client = startClientGrid("client-1");

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

    cache.loadCache(null);

    assertEquals(10, cache.localSize(CachePeekMode.ALL));

    assertEquals(0, grid(0).cache(CACHE_NAME).localSize(CachePeekMode.ALL));
    assertEquals(0, grid(1).cache(CACHE_NAME).localSize(CachePeekMode.ALL));

    assert loadedFromClient;
}
 
Example 14
Source File: CacheJdbcPojoStoreAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Check that data was loaded correctly.
 */
protected void checkCacheLoad() {
    IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME);

    checkFetchSize = true;

    c1.loadCache(null);

    checkFetchSize = false;

    assertEquals(ORGANIZATION_CNT + PERSON_CNT, c1.size());
}
 
Example 15
Source File: CacheJdbcPojoStoreAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Checks that data was loaded correctly with prepared statement.
 */
protected void checkCacheLoadWithStatement() throws SQLException {
    Connection conn = null;

    PreparedStatement stmt = null;

    try {
        conn = getConnection();

        conn.setAutoCommit(true);

        String qry = "select id, org_id, name, birthday, gender from Person";

        stmt = conn.prepareStatement(qry);

        IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME);

        c1.loadCache(null, "org.apache.ignite.cache.store.jdbc.model.PersonKey", stmt);

        assertEquals(PERSON_CNT, c1.size());
    }
    finally {
        U.closeQuiet(stmt);

        U.closeQuiet(conn);
    }

}
 
Example 16
Source File: CacheJdbcPojoStoreAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Check that data was loaded correctly.
 */
protected void checkCacheLoadWithSql() {
    IgniteCache<Object, Object> c1 = grid().cache(CACHE_NAME);

    checkFetchSize = true;

    c1.loadCache(null, "org.apache.ignite.cache.store.jdbc.model.PersonKey", "select id, org_id, name, birthday, gender from Person");

    checkFetchSize = false;

    assertEquals(PERSON_CNT, c1.size());
}
 
Example 17
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 18
Source File: CacheTtlAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDefaultTimeToLiveLoadCache() throws Exception {
    IgniteCache<Integer, Integer> cache = jcache(0);

    cache.loadCache(null);

    checkSizeBeforeLive(SIZE);

    Thread.sleep(DEFAULT_TIME_TO_LIVE + 500);

    checkSizeAfterLive();
}
 
Example 19
Source File: GridTestMain.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Load cache from data store. Also take a look at
 * {@link GridTestCacheStore#loadAll} method.
 *
 * @param cache Cache to load.
 */
private static void loadFromStore(IgniteCache<GridTestKey, Long> cache) {
    cache.loadCache(null, 0, GridTestConstants.LOAD_THREADS, GridTestConstants.ENTRY_COUNT);
}
 
Example 20
Source File: IgnitePersistentStoreTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** */
@Test
public void loadCacheTest() {
    Ignition.stopAll(true);

    LOGGER.info("Running loadCache test");

    LOGGER.info("Filling Cassandra table with test data");

    CacheStore store = CacheStoreHelper.createCacheStore("personTypes",
        new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-3.xml"),
        CassandraHelper.getAdminDataSrc());

    Collection<CacheEntryImpl<PersonId, Person>> entries = TestsHelper.generatePersonIdsPersonsEntries();

    //noinspection unchecked
    store.writeAll(entries);

    LOGGER.info("Cassandra table filled with test data");

    LOGGER.info("Running loadCache test");

    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/pojo/ignite-config.xml")) {
        CacheConfiguration<PersonId, Person> ccfg = new CacheConfiguration<>("cache3");

        IgniteCache<PersonId, Person> personCache3 = ignite.getOrCreateCache(ccfg);

        int size = personCache3.size(CachePeekMode.ALL);

        LOGGER.info("Initial cache size " + size);

        LOGGER.info("Loading cache data from Cassandra table");

        String qry = "select * from test1.pojo_test3 limit 3";

        personCache3.loadCache(null, qry);

        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra table by '" + qry + "'", 3, size);

        personCache3.clear();

        personCache3.loadCache(null, new SimpleStatement(qry));

        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra table by statement", 3, size);

        personCache3.clear();

        personCache3.loadCache(null);

        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra. " +
                "Expected number of records is " + TestsHelper.getBulkOperationSize() +
                ", but loaded number of records is " + size,
            TestsHelper.getBulkOperationSize(), size);

        LOGGER.info("Cache data loaded from Cassandra table");
    }

    LOGGER.info("loadCache test passed");
}