Search in sources :

Example 26 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteCacheClientNearCacheExpiryTest method testExpirationOnClient.

/**
     * @throws Exception If failed.
     */
public void testExpirationOnClient() throws Exception {
    Ignite ignite = grid(NODES - 1);
    assertTrue(ignite.configuration().isClientMode());
    IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
    assertTrue(((IgniteCacheProxy) cache).context().isNear());
    for (int i = 0; i < KEYS_COUNT; i++) cache.put(i, i);
    CreatedExpiryPolicy plc = new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 500));
    IgniteCache<Object, Object> cacheWithExpiry = cache.withExpiryPolicy(plc);
    for (int i = KEYS_COUNT; i < KEYS_COUNT * 2; i++) {
        cacheWithExpiry.put(i, i);
        assertEquals(i, cacheWithExpiry.localPeek(i));
    }
    U.sleep(1000);
    // Check size of near entries via reflection because entries is filtered for size() API call.
    IgniteEx igniteEx = (IgniteEx) ignite;
    GridCacheConcurrentMap map = GridTestUtils.getFieldValue(((GridCacheProxyImpl) igniteEx.cachex(DEFAULT_CACHE_NAME)).delegate(), GridCacheAdapter.class, "map");
    assertEquals(KEYS_COUNT, map.publicSize());
    assertEquals(KEYS_COUNT, cache.size());
    for (int i = 0; i < KEYS_COUNT; i++) assertEquals(i, cacheWithExpiry.localPeek(i));
    for (int i = KEYS_COUNT; i < KEYS_COUNT * 2; i++) assertNull(cache.localPeek(i));
}
Also used : GridCacheConcurrentMap(org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) Duration(javax.cache.expiry.Duration) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy)

Example 27 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgfsAbstractBaseSelfTest method getMetaCache.

/**
     * Gets meta cache.
     *
     * @param igfs The IGFS instance.
     * @return The data cache.
     */
protected static GridCacheAdapter<IgniteUuid, IgfsEntryInfo> getMetaCache(IgniteFileSystem igfs) {
    String dataCacheName = igfs.configuration().getMetaCacheConfiguration().getName();
    IgniteEx igniteEx = ((IgfsEx) igfs).context().kernalContext().grid();
    return ((IgniteKernal) igniteEx).internalCache(dataCacheName);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 28 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgfsAbstractBaseSelfTest method getDataCache.

/**
     * Gets the data cache instance for this IGFS instance.
     *
     * @param igfs The IGFS unstance.
     * @return The data cache.
     */
protected static GridCacheAdapter<IgfsBlockKey, byte[]> getDataCache(IgniteFileSystem igfs) {
    String dataCacheName = igfs.configuration().getDataCacheConfiguration().getName();
    IgniteEx igniteEx = ((IgfsEx) igfs).context().kernalContext().grid();
    return ((IgniteKernal) igniteEx).internalCache(dataCacheName);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 29 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class GridQueryParsingTest method connection.

/**
     *
     */
private JdbcConnection connection() throws Exception {
    GridKernalContext ctx = ((IgniteEx) ignite).context();
    GridQueryProcessor qryProcessor = ctx.query();
    IgniteH2Indexing idx = U.field(qryProcessor, "idx");
    String schemaName = idx.schema(DEFAULT_CACHE_NAME);
    return (JdbcConnection) idx.connectionForSchema(schemaName);
}
Also used : GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteEx(org.apache.ignite.internal.IgniteEx) GridQueryProcessor(org.apache.ignite.internal.processors.query.GridQueryProcessor) JdbcConnection(org.h2.jdbc.JdbcConnection) IgniteH2Indexing(org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing)

Example 30 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class CacheLoadingConcurrentGridStartSelfTest method loadCacheWithDataStreamerSequential.

/**
     * @throws Exception if failed
     */
private void loadCacheWithDataStreamerSequential() throws Exception {
    startGrid(1);
    Ignite g0 = startGrid(0);
    IgniteInternalFuture<Object> restartFut = runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (restarts) {
                stopGrid(1);
                startGrid(1);
                U.sleep(100);
            }
            return null;
        }
    });
    IgniteInternalFuture<Object> fut = runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            for (int i = 2; i < GRIDS_CNT; i++) startGrid(i);
            return null;
        }
    });
    final HashSet<IgniteFuture> set = new HashSet<>();
    IgniteInClosure<Ignite> f = new IgniteInClosure<Ignite>() {

        @Override
        public void apply(Ignite grid) {
            try (IgniteDataStreamer<Integer, String> dataStreamer = grid.dataStreamer(DEFAULT_CACHE_NAME)) {
                dataStreamer.allowOverwrite(allowOverwrite);
                for (int i = 0; i < KEYS_CNT; i++) {
                    set.add(dataStreamer.addData(i, "Data"));
                    if (i % 100000 == 0)
                        log.info("Streaming " + i + "'th entry.");
                }
            }
        }
    };
    f.apply(g0);
    log.info("Data loaded.");
    restarts = false;
    fut.get();
    restartFut.get();
    for (IgniteFuture res : set) assertNull(res.get());
    IgniteCache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    long size = cache.size(CachePeekMode.PRIMARY);
    if (size != KEYS_CNT) {
        Set<Integer> failedKeys = new LinkedHashSet<>();
        for (int i = 0; i < KEYS_CNT; i++) if (!cache.containsKey(i)) {
            log.info("Actual cache size: " + size);
            for (Ignite ignite : G.allGrids()) {
                IgniteEx igniteEx = (IgniteEx) ignite;
                log.info("Missed key info:" + igniteEx.localNode().id() + " primary=" + ignite.affinity(DEFAULT_CACHE_NAME).isPrimary(igniteEx.localNode(), i) + " backup=" + ignite.affinity(DEFAULT_CACHE_NAME).isBackup(igniteEx.localNode(), i) + " local peek=" + ignite.cache(DEFAULT_CACHE_NAME).localPeek(i, CachePeekMode.ONHEAP));
            }
            for (int j = i; j < i + 10000; j++) {
                if (!cache.containsKey(j))
                    failedKeys.add(j);
            }
            break;
        }
        assert failedKeys.isEmpty() : "Some failed keys: " + failedKeys.toString();
    }
    assertCacheSize();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheWriterException(javax.cache.integration.CacheWriterException) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)198 Ignite (org.apache.ignite.Ignite)42 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)40 IgniteException (org.apache.ignite.IgniteException)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)32 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)26 Transaction (org.apache.ignite.transactions.Transaction)25 HashMap (java.util.HashMap)18 CacheException (javax.cache.CacheException)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 ArrayList (java.util.ArrayList)16 LinkedHashMap (java.util.LinkedHashMap)16 IgniteCache (org.apache.ignite.IgniteCache)16 CountDownLatch (java.util.concurrent.CountDownLatch)14 IgniteKernal (org.apache.ignite.internal.IgniteKernal)14 UUID (java.util.UUID)13 ClusterNode (org.apache.ignite.cluster.ClusterNode)13 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)12 IOException (java.io.IOException)11 Map (java.util.Map)11