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

The following examples show how to use org.apache.ignite.IgniteCache#destroy() . 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: 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 2
Source File: CacheDeferredDeleteSanitySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param mode Mode.
 * @param atomicityMode Atomicity mode.
 * @param near Near cache enabled.
 * @param expVal Expected deferred delete value.
 */
@SuppressWarnings("unchecked")
private void testDeferredDelete(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near, boolean expVal) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME)
        .setCacheMode(mode)
        .setAtomicityMode(atomicityMode);

    if (near)
        ccfg.setNearConfiguration(new NearCacheConfiguration());

    IgniteCache cache = null;

    try {
        cache = grid(0).getOrCreateCache(ccfg);

        assertEquals(expVal, ((IgniteCacheProxy)grid(0).cache(DEFAULT_CACHE_NAME)).context().deferredDelete());
    }
    finally {
        if (cache != null)
            cache.destroy();
    }
}
 
Example 3
Source File: GridTransformSpringInjectionSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testTransformResourceInjection() throws Exception {
    Ignite grid = grid(0);

    IgniteCache<String, Integer> cache = grid.createCache(cacheConfiguration(ATOMIC));

    try {
        doTransformResourceInjection(cache);
    }
    finally {
        cache.destroy();
    }

    cache = grid.createCache(cacheConfiguration(TRANSACTIONAL));

    try {
        doTransformResourceInjection(cache);

        for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
            for (TransactionIsolation isolation : TransactionIsolation.values()) {
                IgniteTransactions txs = grid.transactions();

                try (Transaction tx = txs.txStart(concurrency, isolation)) {
                    doTransformResourceInjection(cache);

                    tx.commit();
                }
            }
        }
    }
    finally {
        cache.destroy();
    }
}
 
Example 4
Source File: GridCacheQueryTransformerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testLocalKeepBinary() throws Exception {
    IgniteCache<Integer, Value> cache = grid().createCache("test-cache");

    try {
        for (int i = 0; i < 50; i++)
            cache.put(i, new Value("str" + i, i * 100));

        Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
            @IgniteInstanceResource
            private Ignite ignite;

            @Override public List<Integer> call() throws Exception {
                IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer> transformer =
                    new IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer>() {
                        @Override public Integer apply(Cache.Entry<Integer, BinaryObject> e) {
                            return e.getValue().field("idx");
                        }
                    };

                return ignite.cache("test-cache").withKeepBinary().query(
                    new ScanQuery<Integer, BinaryObject>().setLocal(true), transformer).getAll();
            }
        });

        List<Integer> res = new ArrayList<>(F.flatCollections(lists));

        assertEquals(50, res.size());

        Collections.sort(res);

        for (int i = 0; i < 50; i++)
            assertEquals(i * 100, res.get(i).intValue());
    }
    finally {
        cache.destroy();
    }
}
 
Example 5
Source File: GridCacheQueryTransformerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testKeepBinaryFiltered() throws Exception {
    IgniteCache<Integer, Value> cache = grid().createCache("test-cache");

    try {
        for (int i = 0; i < 50; i++)
            cache.put(i, new Value("str" + i, i * 100));

        IgniteCache<Integer, BinaryObject> binaryCache = cache.withKeepBinary();

        IgniteBiPredicate<Integer, BinaryObject> filter = new IgniteBiPredicate<Integer, BinaryObject>() {
            @Override public boolean apply(Integer k, BinaryObject v) {
                return v.<Integer>field("idx") % 1000 == 0;
            }
        };

        IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer> transformer =
            new IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer>() {
                @Override public Integer apply(Cache.Entry<Integer, BinaryObject> e) {
                    return e.getValue().field("idx");
                }
            };

        List<Integer> res = binaryCache.query(new ScanQuery<>(filter), transformer).getAll();

        assertEquals(5, res.size());

        Collections.sort(res);

        for (int i = 0; i < 5; i++)
            assertEquals(i * 1000, res.get(i).intValue());
    }
    finally {
        cache.destroy();
    }
}
 
Example 6
Source File: IgniteSqlSplitterSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testIndexWithDifferentSegmentationLevelsFailure() throws Exception {
    CacheConfiguration ccfg1 = cacheConfig("pers", true,
        Integer.class, Person2.class).setQueryParallelism(4);
    CacheConfiguration ccfg2 = cacheConfig("org", true,
        Integer.class, Organization.class).setQueryParallelism(3);

    final IgniteCache<Object, Object> c1 = ignite(0).getOrCreateCache(ccfg1);
    final IgniteCache<Object, Object> c2 = ignite(0).getOrCreateCache(ccfg2);

    try {
        c2.put(1, new Organization("o1"));
        c2.put(2, new Organization("o2"));
        c1.put(3, new Person2(1, "p1"));
        c1.put(4, new Person2(2, "p2"));
        c1.put(5, new Person2(3, "p3"));

        String select0 = "select o.name n1, p.name n2 from \"pers\".Person2 p, \"org\".Organization o where p.orgId = o._key and o._key=1";

        final SqlFieldsQuery qry = new SqlFieldsQuery(select0);

        qry.setDistributedJoins(true);

        GridTestUtils.assertThrows(log, new Callable<Void>() {
            @Override public Void call() throws Exception {
                c1.query(qry);

                return null;
            }
        }, CacheException.class, "Using indexes with different parallelism levels in same query is forbidden.");
    }
    finally {
        c1.destroy();
        c2.destroy();
    }
}
 
Example 7
Source File: IgniteSqlSplitterSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testIndexSegmentation() throws Exception {
    CacheConfiguration ccfg1 = cacheConfig("pers", true,
        Integer.class, Person2.class).setQueryParallelism(4);
    CacheConfiguration ccfg2 = cacheConfig("org", true,
        Integer.class, Organization.class).setQueryParallelism(4);

    IgniteCache<Object, Object> c1 = ignite(0).getOrCreateCache(ccfg1);
    IgniteCache<Object, Object> c2 = ignite(0).getOrCreateCache(ccfg2);

    try {
        c2.put(1, new Organization("o1"));
        c2.put(2, new Organization("o2"));
        c1.put(3, new Person2(1, "p1"));
        c1.put(4, new Person2(2, "p2"));
        c1.put(5, new Person2(3, "p3"));

        String select0 = "select o.name n1, p.name n2 from \"pers\".Person2 p, \"org\".Organization o where p.orgId = o._key and o._key=1";

        checkQueryPlan(c1, true, 1, new SqlFieldsQuery(select0));

        checkQueryPlan(c1, true, 1, new SqlFieldsQuery(select0).setLocal(true));
    }
    finally {
        c1.destroy();
        c2.destroy();
    }
}
 
Example 8
Source File: GridCacheQueryTransformerSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testGetKeys() throws Exception {
    IgniteCache<Integer, String> cache = grid().createCache("test-cache");

    try {
        for (int i = 0; i < 50; i++)
            cache.put(i, "val" + i);

        IgniteClosure<Cache.Entry<Integer, String>, Integer> transformer =
            new IgniteClosure<Cache.Entry<Integer, String>, Integer>() {
                @Override public Integer apply(Cache.Entry<Integer, String> e) {
                    return e.getKey();
                }
            };

        List<Integer> keys = cache.query(new ScanQuery<Integer, String>(), transformer).getAll();

        assertEquals(50, keys.size());

        Collections.sort(keys);

        for (int i = 0; i < 50; i++)
            assertEquals(i, keys.get(i).intValue());
    }
    finally {
        cache.destroy();
    }
}
 
Example 9
Source File: TxPessimisticDeadlockDetectionTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
private void doTestDeadlocks(IgniteCache cache, Object startKey) throws Exception {
    try {
        awaitPartitionMapExchange();

        doTestDeadlock(2, false, true, true, startKey);
        doTestDeadlock(2, false, false, false, startKey);
        doTestDeadlock(2, false, false, true, startKey);

        doTestDeadlock(3, false, true, true, startKey);
        doTestDeadlock(3, false, false, false, startKey);
        doTestDeadlock(3, false, false, true, startKey);

        doTestDeadlock(4, false, true, true, startKey);
        doTestDeadlock(4, false, false, false, startKey);
        doTestDeadlock(4, false, false, true, startKey);
    }
    catch (Exception e) {
        U.error(log, "Unexpected exception: ", e);

        fail();
    }
    finally {
        if (cache != null)
            cache.destroy();
    }
}
 
Example 10
Source File: AffinityClientNodeSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testClientNodeNotInAffinity() throws Exception {
    checkCache(CACHE1, 2);

    checkCache(CACHE2, 2);

    checkCache(CACHE4, 3);

    checkCache(CACHE5, 2);

    Ignite client = ignite(NODE_CNT - 1);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setBackups(0);

    ccfg.setNodeFilter(new TestNodesFilter());

    IgniteCache<Integer, Integer> cache = client.createCache(ccfg);

    try {
        checkCache(DEFAULT_CACHE_NAME, 1);
    }
    finally {
        cache.destroy();
    }

    cache = client.createCache(ccfg, new NearCacheConfiguration());

    try {
        checkCache(DEFAULT_CACHE_NAME, 1);
    }
    finally {
        cache.destroy();
    }
}
 
Example 11
Source File: IgniteSqlSplitterSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 */
@Test
public void testPushDown() {
    IgniteCache<Integer, Person> c = ignite(CLIENT).getOrCreateCache(cacheConfig("ps", true,
        Integer.class, Person.class));

    try {
        String subqry = "(select max(p.id) as id, p.depId from Person p group by p.depId)";

        for (int i = 0; i < 5; i++) {
            SB qry = new SB("select * from ");

            for (int j = 0; j < 5; j++) {
                if (j != 0)
                    qry.a(", ");

                if (j == i)
                    qry.a(subqry);
                else
                    qry.a("Person");

                qry.a(" p").a(j);
            }

            qry.a(" where");

            for (int j = 1; j < 5; j++) {
                if (j != 1)
                    qry.a(" and");

                qry.a(" p").a(j - 1).a(".id").a(" = ").a("p").a(j).a(".depId");
            }

            c.query(new SqlFieldsQuery(qry.toString())
                .setEnforceJoinOrder(true)).getAll();

            X.println("\nPlan:\n" +
                c.query(new SqlFieldsQuery("explain " + qry.toString())
                    .setEnforceJoinOrder(true)).getAll());
        }
    }
    finally {
        c.destroy();
    }
}
 
Example 12
Source File: IgniteSqlSplitterSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 */
@Test
public void testPushDownLeftJoin() {
    IgniteCache<Integer, Person> c = ignite(0).getOrCreateCache(cacheConfig("ps", true,
        Integer.class, Person.class));

    try {
        String subqryAgg = "(select max(p.id) as id, p.depId from Person p group by p.depId)";
        String subqrySimple = "(select p.id, p.depId from Person p)";

        for (int i = 0; i < 5; i++) {
            for (int k = 0; k < 5; k++) {
                SB qry = new SB("select * from ");

                for (int j = 0; j < 5; j++) {
                    if (j != 0)
                        qry.a(j == i ? " left join " : " join ");

                    if (j == 2)
                        qry.a(subqryAgg);
                    else
                        qry.a(j == k ? subqrySimple : "Person");

                    qry.a(" p").a(j);

                    if (j != 0) {
                        qry.a(" on ");

                        qry.a(" p0.id").a(" = ").a("p").a(j).a(".depId");
                    }
                }

                X.println(" ---> ik: : " + i + " " + k);
                X.println("\nqry: \n" + qry.toString());

                c.query(new SqlFieldsQuery(qry.toString())
                    .setEnforceJoinOrder(true)).getAll();

                X.println("\nPlan:\n" +
                    c.query(new SqlFieldsQuery("explain " + qry.toString())
                        .setEnforceJoinOrder(true)).getAll());
            }
        }
    }
    finally {
        c.destroy();
    }
}
 
Example 13
Source File: DecisionTreeRegressionFromSparkExample.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Run example.
 */
public static void main(String[] args) throws FileNotFoundException {
    System.out.println();
    System.out.println(">>> Decision tree regression model loaded from Spark through serialization over partitioned dataset usage example started.");
    // Start ignite grid.
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println(">>> Ignite grid started.");

        IgniteCache<Integer, Vector> dataCache = null;
        try {
            dataCache = TitanicUtils.readPassengersWithoutNulls(ignite);

            final Vectorizer<Integer, Vector, Integer, Double> vectorizer = new DummyVectorizer<Integer>(0, 1, 5, 6).labeled(4);

            DecisionTreeNode mdl = (DecisionTreeNode)SparkModelParser.parse(
                SPARK_MDL_PATH,
                SupportedSparkModels.DECISION_TREE_REGRESSION,
                env
            );

            System.out.println(">>> Decision tree regression model: " + mdl);

            System.out.println(">>> ---------------------------------");
            System.out.println(">>> | Prediction\t| Ground Truth\t|");
            System.out.println(">>> ---------------------------------");

            try (QueryCursor<Cache.Entry<Integer, Vector>> observations = dataCache.query(new ScanQuery<>())) {
                for (Cache.Entry<Integer, Vector> observation : observations) {
                    LabeledVector<Double> lv = vectorizer.apply(observation.getKey(), observation.getValue());
                    Vector inputs = lv.features();
                    double groundTruth = lv.label();
                    double prediction = mdl.predict(inputs);

                    System.out.printf(">>> | %.4f\t\t| %.4f\t\t|\n", prediction, groundTruth);
                }
            }

            System.out.println(">>> ---------------------------------");
        }
        finally {
            dataCache.destroy();
        }
    }
}
 
Example 14
Source File: IgniteModelDistributedInferenceExample.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Run example.
 */
public static void main(String... args) throws IOException, ExecutionException, InterruptedException {
    System.out.println();
    System.out.println(">>> Linear regression model over cache based dataset usage example started.");
    // Start ignite grid.
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println(">>> Ignite grid started.");

        IgniteCache<Integer, Vector> dataCache = null;
        try {
            dataCache = new SandboxMLCache(ignite).fillCacheWith(MLSandboxDatasets.MORTALITY_DATA);

            System.out.println(">>> Create new linear regression trainer object.");
            LinearRegressionLSQRTrainer trainer = new LinearRegressionLSQRTrainer();

            System.out.println(">>> Perform the training to get the model.");
            LinearRegressionModel mdl = trainer.fit(
                ignite,
                dataCache,
                new DummyVectorizer<Integer>().labeled(Vectorizer.LabelCoordinate.FIRST)
            );

            System.out.println(">>> Linear regression model: " + mdl);

            System.out.println(">>> Preparing model reader and model parser.");
            ModelReader reader = new InMemoryModelReader(mdl);
            ModelParser<Vector, Double, ?> parser = new IgniteModelParser<>();
            try (Model<Vector, Future<Double>> infMdl = new IgniteDistributedModelBuilder(ignite, 4, 4)
                .build(reader, parser)) {
                System.out.println(">>> Inference model is ready.");

                System.out.println(">>> ---------------------------------");
                System.out.println(">>> | Prediction\t| Ground Truth\t|");
                System.out.println(">>> ---------------------------------");

                try (QueryCursor<Cache.Entry<Integer, Vector>> observations = dataCache.query(new ScanQuery<>())) {
                    for (Cache.Entry<Integer, Vector> observation : observations) {
                        Vector val = observation.getValue();
                        Vector inputs = val.copyOfRange(1, val.size());
                        double groundTruth = val.get(0);

                        double prediction = infMdl.predict(inputs).get();

                        System.out.printf(">>> | %.4f\t\t| %.4f\t\t|\n", prediction, groundTruth);
                    }
                }
            }

            System.out.println(">>> ---------------------------------");

            System.out.println(">>> Linear regression model over cache based dataset usage example completed.");
        }
        finally {
            if (dataCache != null)
                dataCache.destroy();
        }
    }
    finally {
        System.out.flush();
    }
}
 
Example 15
Source File: GridCacheContinuousQueryAbstractSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testBackupCleanerTaskFinalize() throws Exception {
    final String CACHE_NAME = "LOCAL_CACHE";

    CacheConfiguration<Integer, Integer> cCfg = new CacheConfiguration<>();

    cCfg.setName(CACHE_NAME);

    cCfg.setCacheMode(cacheMode());

    IgniteCache<Integer, Integer> cache = grid(0).getOrCreateCache(cCfg);

    CacheContinuousQueryManager qm = grid(0).context().cache().
        internalCache(CACHE_NAME).context().continuousQueries();

    assertNotNull(qm.getCancelableTask());

    cache.destroy();

    assertNull(qm.getCancelableTask());
}
 
Example 16
Source File: IgniteSqlSplitterSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSortedMergeIndex() throws Exception {
    IgniteCache<Integer,Value> c = ignite(0).getOrCreateCache(cacheConfig("v", true,
        Integer.class, Value.class));

    try {
        GridTestUtils.setFieldValue(AbstractReducer.class, "prefetchSize", 8);

        Random rnd = new GridRandom();

        int cnt = 1000;

        for (int i = 0; i < cnt; i++) {
            c.put(i, new Value(
                rnd.nextInt(5) == 0 ? null : rnd.nextInt(100),
                rnd.nextInt(8) == 0 ? null : rnd.nextInt(2000)));
        }

        List<List<?>> plan = c.query(new SqlFieldsQuery(
            "explain select snd from Value order by fst desc")).getAll();
        String rdcPlan = (String)plan.get(1).get(0);

        assertTrue(rdcPlan.contains("merge_sorted"));
        assertTrue(rdcPlan.contains("/* index sorted */"));

        plan = c.query(new SqlFieldsQuery(
            "explain select snd from Value")).getAll();
        rdcPlan = (String)plan.get(1).get(0);

        assertTrue(rdcPlan.contains("merge_scan"));
        assertFalse(rdcPlan.contains("/* index sorted */"));

        for (int i = 0; i < 10; i++) {
            X.println(" --> " + i);

            List<List<?>> res = c.query(new SqlFieldsQuery(
                "select fst from Value order by fst").setPageSize(5)
            ).getAll();

            assertEquals(cnt, res.size());

            Integer p = null;

            for (List<?> row : res) {
                Integer x = (Integer)row.get(0);

                if (x != null) {
                    if (p != null)
                        assertTrue(x + " >= " + p, x >= p);

                    p = x;
                }
            }
        }
    }
    finally {
        GridTestUtils.setFieldValue(AbstractReducer.class, "prefetchSize", 1024);

        c.destroy();
    }
}
 
Example 17
Source File: GridCacheQueryTransformerSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testUnsupported() throws Exception {
    final IgniteCache<Integer, Integer> cache = grid().createCache("test-cache");

    final IgniteClosure<Cache.Entry<Integer, Integer>, Integer> transformer =
        new IgniteClosure<Cache.Entry<Integer, Integer>, Integer>() {
            @Override public Integer apply(Cache.Entry<Integer, Integer> e) {
                return null;
            }
        };

    try {
        GridTestUtils.assertThrows(
            log,
            new Callable<Object>() {
                @Override public Object call() throws Exception {
                    cache.query(new SqlQuery<Integer, Integer>(Integer.class, "clause"), transformer);

                    return null;
                }
            },
            UnsupportedOperationException.class,
            "Transformers are supported only for SCAN queries."
        );

        GridTestUtils.assertThrows(
            log,
            new Callable<Object>() {
                @Override public Object call() throws Exception {
                    cache.query(new SqlFieldsQuery("clause"), new IgniteClosure<List<?>, Object>() {
                        @Override public Object apply(List<?> objects) {
                            return null;
                        }
                    });

                    return null;
                }
            },
            UnsupportedOperationException.class,
            "Transformers are supported only for SCAN queries."
        );

        GridTestUtils.assertThrows(
            log,
            new Callable<Object>() {
                @Override public Object call() throws Exception {
                    cache.query(new TextQuery<Integer, Integer>(Integer.class, "clause"), transformer);

                    return null;
                }
            },
            UnsupportedOperationException.class,
            "Transformers are supported only for SCAN queries."
        );

        GridTestUtils.assertThrows(
            log,
            new Callable<Object>() {
                @Override public Object call() throws Exception {
                    cache.query(new SpiQuery<Integer, Integer>(), transformer);

                    return null;
                }
            },
            UnsupportedOperationException.class,
            "Transformers are supported only for SCAN queries."
        );

        GridTestUtils.assertThrows(
            log,
            new Callable<Object>() {
                @Override public Object call() throws Exception {
                    cache.query(new ContinuousQuery<Integer, Integer>(), transformer);

                    return null;
                }
            },
            UnsupportedOperationException.class,
            "Transformers are supported only for SCAN queries."
        );
    }
    finally {
        cache.destroy();
    }
}
 
Example 18
Source File: CacheStoreUsageMultinodeDynamicStartAbstractTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @param clientStart {@code True} if start cache from client node.
 * @throws Exception If failed.
 */
private void checkStoreWithDynamicStart(boolean clientStart) throws Exception {
    cacheStore = true;

    CacheConfiguration ccfg = cacheConfiguration();

    assertNotNull(ccfg.getCacheStoreFactory());

    Ignite srv = ignite(0);

    Ignite client = ignite(3);

    Ignite node = clientStart ? client : srv;

    IgniteCache cache = nearCache ? node.createCache(ccfg, new NearCacheConfiguration()) : node.createCache(ccfg);

    assertNotNull(cache);

    try {
        if (nearCache)
            client.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>());

        checkStoreUpdate(true);
    }
    finally {
        cache = srv.cache(DEFAULT_CACHE_NAME);

        if (cache != null)
            cache.destroy();
    }
}
 
Example 19
Source File: IntMaxValueEntriesTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** {@inheritDoc} */
@Override public boolean test(Map<Object, Object> ctx) throws Exception {
    final IgniteCache<Integer, Object> cache = cache();

    final IgniteDataStreamer<Integer, Object> stmr = ignite().dataStreamer(cache.getName());

    final List<Thread> threads = new ArrayList<>(THREADS);

    final LongAdder addedCnt = new LongAdder();

    int delta = (int)((KEYS_HI + Math.abs(KEYS_LO)) / THREADS);

    System.out.println("Delta: " + delta);

    for (int i = 0; i < THREADS; i++) {
        final int lo = i == 0 ? KEYS_LO : delta * i + 1;

        final int hi = i == THREADS - 1 ? (int)KEYS_HI : (int)((long)delta * (i + 1));

        Thread t = new Thread(new Runnable() {
            @Override public void run() {
                ThreadLocalRandom rnd = ThreadLocalRandom.current();

                byte val = (byte)rnd.nextInt();

                println("Start from " + lo + " to " + hi);

                for (int j = lo, k = 0; j < hi; j++, k++) {
                    stmr.addData(j, val++);

                    addedCnt.increment();

                    if (k % REPORT_DELTA == 0)
                        println(addedCnt.sum() + " entries");
                }

                println("Thread finished. " + addedCnt.sum() + " entries.");
            }
        });

        threads.add(t);
        t.start();
    }

    for (Thread thread : threads)
        thread.join();

    println("All threads finished. " + addedCnt.sum() + " entries.");

    println("Streamer flush");

    stmr.flush();

    println("Streamer flushed");

    println("Calculating cache size");
    println("Cache size: " + cache.size());

    println("Calculating long cache size");
    println("Cache size long: " + cache.sizeLong());

    Thread.sleep(10000);

    println("Iterating started");

    long cnt = 0;

    for (Cache.Entry<Integer, Object> ignored : cache) {
        cnt++;

        if (cnt > 0 && cnt % REPORT_DELTA == 0)
            println("Iterated via " + cnt + " entries");
    }

    println("Iterated via " + cnt + " entries");

    cache.destroy();

    return true;
}
 
Example 20
Source File: GridCacheOnCopyFlagAbstractSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
private void putGetKnownImmutable() throws Exception {
    noInterceptor = true;

    IgniteCache<String, Long> cache = grid(0).createCache(cacheConfiguration());

    try {
        Map<String, Long> map = new HashMap<>();

        for (int i = 0; i < ITER_CNT; i++) {
            String key = String.valueOf(i);
            Long val = Long.MAX_VALUE - i;

            cache.put(key, val);

            map.put(key, val);
        }

        GridCacheAdapter cache0 = internalCache(cache);

        GridCacheContext cctx = cache0.context();

        for (Map.Entry<String, Long> e : map.entrySet()) {
            GridCacheEntryEx entry = cache0.peekEx(e.getKey());

            assertNotNull("No entry for key: " + e.getKey(), entry);

            String key0 = entry.key().value(cctx.cacheObjectContext(), false);

            assertSame(key0, e.getKey());

            String key1 = entry.key().value(cctx.cacheObjectContext(), true);

            assertSame(key0, key1);

            if (!storeValue(cache)) {
                Long val0 = entry.rawGet().value(cctx.cacheObjectContext(), false);

                assertNotSame(val0, e.getValue());

                Long val1 = entry.rawGet().value(cctx.cacheObjectContext(), true);

                assertNotSame(val0, val1);

                assertNotSame(e.getValue(), cache.get(e.getKey()));
            }
        }
    }
    finally {
        if (cache != null)
            cache.destroy();
    }
}