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

The following examples show how to use org.apache.ignite.IgniteCache#getName() . 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: CacheStopAndDestroySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache.
 * @throws Exception If failed.
 */
private void checkDestroyed(IgniteCache<Object, Object> cache) throws Exception {
    checkUsageFails(cache);

    awaitPartitionMapExchange();

    String cacheName = cache.getName();

    for (int i = 0; i < 3; i++)
        assertNull("Unexpected cache for node: " + i, grid(i).cache(cacheName));
}
 
Example 2
Source File: IgnitePdsCacheWalDisabledOnRebalancingTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private void verifyCache(IgniteCache cache, BiFunction<String, Integer, String> generatingFunc) {
    int size = cache.size(CachePeekMode.PRIMARY);

    String cacheName = cache.getName();

    for (int i = 0; i < size; i++) {
        String value = (String) cache.get(i);

        assertEquals(generatingFunc.apply(cacheName, i), value);
    }
}
 
Example 3
Source File: CacheSerializableTransactionsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNearCacheReaderUpdate() throws Exception {
    Ignite ignite0 = ignite(0);

    IgniteCache<Integer, Integer> cache0 =
        ignite0.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false));

    final String cacheName = cache0.getName();

    try {
        Ignite client1 = ignite(SRVS);
        Ignite client2 = ignite(SRVS + 1);

        IgniteCache<Integer, Integer> cache1 = client1.createNearCache(cacheName,
            new NearCacheConfiguration<Integer, Integer>());
        IgniteCache<Integer, Integer> cache2 = client2.createNearCache(cacheName,
            new NearCacheConfiguration<Integer, Integer>());

        Integer key = primaryKey(ignite(0).cache(cacheName));

        try (Transaction tx = client1.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
            assertNull(cache1.get(key));
            cache1.put(key, 1);

            tx.commit();
        }

        try (Transaction tx = client2.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
            assertEquals(1, (Object)cache2.get(key));
            cache2.put(key, 2);

            tx.commit();
        }

        try (Transaction tx = client1.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
            assertEquals(2, (Object)cache1.get(key));
            cache1.put(key, 3);

            tx.commit();
        }
    }
    finally {
        destroyCache(cacheName);
    }
}
 
Example 4
Source File: IgniteAbstractTxSuspendResumeTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param ignite Ignite.
 * @param cache Cache.
 * @param isolation Isolation.
 * @param suspended Left transaction in suspended state.
 */
private Transaction initTxWithTimeout(Ignite ignite, IgniteCache cache, TransactionIsolation isolation,
    boolean suspended) throws Exception {
    final int RETRIES = 5;

    // Make several attempts to init transaction, sometimes it takes more time then given timeout.
    for (int i = 0; i < RETRIES; i++) {
        try {
            final Transaction tx = ignite.transactions().txStart(transactionConcurrency(), isolation,
                TX_TIMEOUT, 0);

            cache.put(1, 1);

            tx.suspend();

            GridTestUtils.runAsync(() -> {
                tx.resume();

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

                tx.suspend();
            }).get(FUT_TIMEOUT);

            tx.resume();

            cache.put(1, 1);
            cache.put(2, 2);
            cache.put(3, 3);

            if (suspended)
                tx.suspend();

            return tx;
        }
        catch (Exception e) {
            if (X.hasCause(e, TransactionTimeoutException.class)) {
                if (i == RETRIES - 1) {
                    throw new Exception("Can't init transaction within given timeout [isolation=" +
                        isolation + ", cache=" + cache.getName() + ", ignite=" +
                        ignite.configuration().getIgniteInstanceName() + ']', e);
                }
                else {
                    log.info("Got timeout on transaction init [attempt=" + i + ", isolation=" + isolation +
                        ", cache=" + cache.getName() + ", ignite=" + ignite.configuration().getIgniteInstanceName() + ']');
                }
            }
            else
                throw e;
        }
    }

    return null;
}
 
Example 5
Source File: PreloadLogger.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Print cache size along with amount of recently loaded entries.
 *
 * @param cache Ignite cache.
 */
private void printCacheStatistics(IgniteCache<Object, Object> cache) {
    String cacheName = cache.getName();

    long cacheSize = cache.sizeLong();

    long recentlyLoaded = cacheSize - cntrs.get(cacheName);
    String recLoaded = recentlyLoaded == 0 ? String.valueOf(recentlyLoaded) : "+" + recentlyLoaded;

    BenchmarkUtils.println(cfg, String.format(strFmt, cacheName, cacheSize, recLoaded));

    cntrs.put(cacheName, cacheSize);
}
 
Example 6
Source File: IgniteCacheRandomOperationBenchmark.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @param cache Ignite cache.
 * @throws Exception If failed.
 */
private void doScanQuery(IgniteCache<Object, Object> cache) throws Exception {
    if (!affCaches.contains(cache))
        return;

    Map<UUID, List<Integer>> partitionsMap = personCachePartitions(cache.getName());

    ScanQueryBroadcastClosure c = new ScanQueryBroadcastClosure(cache.getName(), partitionsMap);

    ClusterGroup clusterGrp = ignite().cluster().forNodeIds(partitionsMap.keySet());

    IgniteCompute compute = ignite().compute(clusterGrp);

    compute.broadcast(c);
}
 
Example 7
Source File: DiagnosticLogForPartitionStatesTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @param cfgs Cache configurations.
 * @param msgExp {@code true} if warning message is expected.
 * @throws Exception If failed.
 */
private void doTest(List<CacheConfiguration<Integer, Integer>> cfgs, boolean msgExp) throws Exception {
    String name = (cfgs.size() == 1) ? cfgs.get(0).getName() : cfgs.get(0).getGroupName();

    LogListener lsnr = LogListener
        .matches(s -> s.startsWith(String.format(PARTITION_STATE_FAILED_MSG, name, ANY_MSG)))
        .times(msgExp ? 1 : 0)
        .build();

    log.registerListener(lsnr);

    IgniteEx node1 = startGrid(0);

    IgniteEx node2 = startGrid(1);

    node1.cluster().active(true);

    List<IgniteCache<Integer, Integer>> caches = cfgs.stream()
        .map(cfg -> node1.getOrCreateCache(cfg)).collect(Collectors.toList());

    Map<String, Set<Integer>> clearKeys = new HashMap<>();

    for (IgniteCache<Integer, Integer> cache : caches) {
        String cacheName = cache.getName();

        Set<Integer> clr = new HashSet<>();

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

            if (node2.affinity(cacheName).isPrimary(node2.localNode(), i))
                clr.add(i);
        }

        clearKeys.put(cacheName, clr);
    }

    for (IgniteCache<Integer, Integer> c : caches) {
        node2.context().cache().cache(c.getName())
            .clearLocallyAll(clearKeys.get(c.getName()), true, true, true);
    }

    // Trigger partition map exchange and therefore trigger partitions validation.
    startGrid(2);

    awaitPartitionMapExchange();

    assertTrue(lsnr.check());
}