Java Code Examples for org.apache.ignite.IgniteCache#get()
The following examples show how to use
org.apache.ignite.IgniteCache#get() .
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: IgniteSqlRoutingTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testUnicastQuerySelectKeyEqualsParameterReused() throws Exception { IgniteCache<Integer, Person> cache = grid(NODE_CLIENT).cache(CACHE_PERSON); for (int key : new int[] {0, 250, 500, 750, 1000} ) { List<List<?>> result = runQueryEnsureUnicast(cache, new SqlFieldsQuery("select name, age from Person where _key=?").setArgs(key), 1); assertEquals(1, result.size()); Person person = cache.get(key); checkResultsRow(result, 0, person.name, person.age); } }
Example 2
Source File: JavaStandaloneIgniteRDDSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testStoreDataToIgnite() throws Exception { JavaSparkContext sc = new JavaSparkContext("local[*]", "test"); try { JavaIgniteContext<String, String> ic = new JavaIgniteContext<>(sc, new IgniteConfigProvider()); ic.fromCache(ENTITY_CACHE_NAME) .savePairs(sc.parallelize(F.range(0, KEYS_CNT), 2).mapToPair(TO_PAIR_F)); Ignite ignite = Ignition.ignite("grid-0"); IgniteCache<String, String> cache = ignite.cache(ENTITY_CACHE_NAME); for (int i = 0; i < KEYS_CNT; i++) { String val = cache.get(String.valueOf(i)); assertNotNull("Value was not put to cache for key: " + i, val); assertEquals("Invalid value stored for key: " + i, "val" + i, val); } } finally { sc.stop(); } }
Example 3
Source File: IgniteDialect.java From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Tuple getTuple(EntityKey key, OperationContext operationContext) { IgniteCache<Object, BinaryObject> entityCache = provider.getEntityCache( key.getMetadata() ); Object id = provider.createKeyObject( key ); BinaryObject bo = entityCache.get( id ); if ( bo != null ) { return new Tuple( new IgniteTupleSnapshot( id, bo, key.getMetadata() ), SnapshotType.UPDATE ); } else { return null; } }
Example 4
Source File: IgniteBaselineAffinityTopologyActivationTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void checkDataInCache(IgniteEx srv) { IgniteCache<Object, Object> cache = srv.cache(DEFAULT_CACHE_NAME); for (int i = 0; i < ENTRIES_COUNT; i++) { TestValue testVal = (TestValue) cache.get(i); assertNotNull(testVal); assertEquals(i, testVal.id); } }
Example 5
Source File: PageEvictionMultinodeAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param cfg Config. * @throws Exception If failed. */ protected void createCacheAndTestEviction(CacheConfiguration<Object, Object> cfg) throws Exception { IgniteCache<Object, Object> cache = clientGrid().getOrCreateCache(cfg); for (int i = 1; i <= ENTRIES; i++) { ThreadLocalRandom r = ThreadLocalRandom.current(); if (r.nextInt() % 5 == 0) cache.put(i, new TestObject(PAGE_SIZE / 4 - 50 + r.nextInt(5000))); // Fragmented object. else cache.put(i, new TestObject(r.nextInt(PAGE_SIZE / 4 - 50))); // Fits in one page. if (r.nextInt() % 7 == 0) cache.get(r.nextInt(i)); // Touch. else if (r.nextInt() % 11 == 0) cache.remove(r.nextInt(i)); // Remove. else if (r.nextInt() % 13 == 0) cache.put(r.nextInt(i), new TestObject(r.nextInt(PAGE_SIZE / 2))); // Update. if (i % (ENTRIES / 10) == 0) System.out.println(">>> Entries put: " + i); } int resultingSize = cache.size(CachePeekMode.PRIMARY); System.out.println(">>> Resulting size: " + resultingSize); // Eviction started, no OutOfMemory occurred, success. assertTrue(resultingSize < ENTRIES * 10 / 11); clientGrid().destroyCache(cfg.getName()); }
Example 6
Source File: DataStreamProcessorSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testCustomUserUpdater() throws Exception { useCache = true; try { Ignite ignite = startGridsMultiThreaded(3); afterGridStarted(); try (IgniteDataStreamer<String, TestObject> ldr = ignite.dataStreamer(DEFAULT_CACHE_NAME)) { ldr.allowOverwrite(true); ldr.keepBinary(customKeepBinary()); ldr.receiver(getStreamReceiver()); for (int i = 0; i < 100; i++) ldr.addData(String.valueOf(i), new TestObject(i)); } IgniteCache<String, TestObject> cache = ignite.cache(DEFAULT_CACHE_NAME); for (int i = 0; i < 100; i++) { TestObject val = cache.get(String.valueOf(i)); assertNotNull(val); assertEquals(i + 1, val.val); } } finally { stopAllGrids(); } }
Example 7
Source File: IgniteCacheStoreCollectionTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param cache Cache. */ private void checkStoreMap(IgniteCache<Object, Object> cache) { cache.put(1, new MyMap()); cache.put(2, new MyMap()); MyMap map = (MyMap)cache.get(1); assertNotNull(map); Map<Integer, MyMap> vals = (Map)cache.getAll(F.asSet(1, 2)); assertEquals(2, vals.size()); assertTrue("Unexpected value: " + vals.get(1), vals.get(1) instanceof MyMap); assertTrue("Unexpected value: " + vals.get(2), vals.get(2) instanceof MyMap); }
Example 8
Source File: IgniteCacheEntryListenerExpiredEventsTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param ccfg Cache configuration. * @throws Exception If failed. */ private void checkExpiredEvents(CacheConfiguration<Object, Object> ccfg) throws Exception { IgniteCache<Object, Object> cache = ignite(0).createCache(ccfg); try { evtCntr = new AtomicInteger(); CacheEntryListenerConfiguration<Object, Object> lsnrCfg = new MutableCacheEntryListenerConfiguration<>( new ExpiredListenerFactory(), null, true, false ); cache.registerCacheEntryListener(lsnrCfg); IgniteCache<Object, Object> expiryCache = cache.withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(MILLISECONDS, 500))); expiryCache.put(1, 1); for (int i = 0; i < 10; i++) cache.get(i); boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return evtCntr.get() > 0; } }, 5000); assertTrue(wait); U.sleep(100); assertEquals(1, evtCntr.get()); } finally { ignite(0).destroyCache(cache.getName()); } }
Example 9
Source File: CacheMetricsManageTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Increment cache statistics. * * @param cache cache. */ private void incrementCacheStatistics(IgniteCache<Integer, String> cache) { cache.get(1); cache.put(1, "one"); cache.get(1); cache.remove(1); }
Example 10
Source File: IgniteCacheConfigVariationsFullApiTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testGetAndPutIfAbsentAsync() throws Exception { Transaction tx = txShouldBeUsed() ? transactions().txStart() : null; IgniteCache<String, Integer> cache = jcache(); try { IgniteFuture<Integer> fut1 = cache.getAndPutIfAbsentAsync("key", 1); assertNull(fut1.get()); assertEquals((Integer)1, cache.get("key")); IgniteFuture<Integer> fut2 = cache.getAndPutIfAbsentAsync("key", 2); assertEquals((Integer)1, fut2.get()); assertEquals((Integer)1, cache.get("key")); if (tx != null) tx.commit(); } finally { if (tx != null) tx.close(); } if (!storeEnabled()) return; // Check swap. cache.put("key2", 1); cache.localEvict(Collections.singleton("key2")); if (!isLoadPreviousValue()) cache.get("key2"); assertEquals((Integer)1, cache.getAndPutIfAbsentAsync("key2", 3).get()); // Check db. if (storeEnabled() && isLoadPreviousValue() && !isMultiJvm()) { putToStore("key3", 3); assertEquals((Integer)3, cache.getAndPutIfAbsentAsync("key3", 4).get()); } cache.localEvict(Collections.singleton("key2")); if (!isLoadPreviousValue()) cache.get("key2"); // Same checks inside tx. tx = txShouldBeUsed() ? transactions().txStart() : null; try { assertEquals(1, (int) cache.getAndPutIfAbsentAsync("key2", 3).get()); if (tx != null) tx.commit(); assertEquals((Integer)1, cache.get("key2")); } finally { if (tx != null) tx.close(); } }
Example 11
Source File: IgniteCacheUpdateSqlQuerySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** */ @Test public void testTypeConversions() throws ParseException { boolean oldAllowColumnsVal = GridTestUtils.getFieldValue(UpdatePlanBuilder.class, UpdatePlanBuilder.class, "ALLOW_KEY_VAL_UPDATES"); GridTestUtils.setFieldValue(UpdatePlanBuilder.class, "ALLOW_KEY_VAL_UPDATES", true); try { IgniteCache cache = ignite(0).cache("L2AT"); cache.query(new SqlFieldsQuery("INSERT INTO \"AllTypes\" (_key, _val) VALUES(2, ?)") .setArgs(new AllTypes(2L))).getAll(); cache.query(new SqlFieldsQuery( "UPDATE \"AllTypes\" " + "SET " + "\"dateCol\" = '2016-11-30 12:00:00', " + "\"booleanCol\" = false, " + "\"tsCol\" = DATE '2016-12-01' " + "WHERE _key = 2") ); // Look ma, no hands: first we set value of inner object column (innerTypeCol), then update only one of its // fields (innerLongCol), while leaving another inner property (innerStrCol) as specified by innerTypeCol. cache.query(new SqlFieldsQuery( "UPDATE \"AllTypes\" " + "SET " + "\"innerLongCol\" = ?, " + // (1) "\"doubleCol\" = CAST('50' as INT), " + "\"booleanCol\" = 80, " + "\"innerTypeCol\" = ?, " + // (2) "\"strCol\" = PI(), " + "\"shortCol\" = CAST(WEEK(PARSEDATETIME('2016-11-30', 'yyyy-MM-dd')) as VARCHAR), " + "\"sqlDateCol\"=TIMESTAMP '2016-12-02 13:47:00', " + "\"tsCol\"=TIMESTAMPADD('MI', 2, DATEADD('DAY', 2, \"tsCol\")), " + "\"primitiveIntsCol\" = ?, " + //(3) "\"bytesCol\" = ?" // (4) ).setArgs(5, new AllTypes.InnerType(80L), new int[] {2, 3}, new Byte[] {4, 5, 6}) ).getAll(); AllTypes res = (AllTypes) cache.get(2L); assertNotNull(res); assertEquals(new BigDecimal(301.0).doubleValue(), res.bigDecimalCol.doubleValue()); assertEquals(50.0, res.doubleCol); assertEquals(2L, (long) res.longCol); assertTrue(res.booleanCol); assertEquals("3.141592653589793", res.strCol); assertTrue(Arrays.equals(new byte[] {0, 1}, res.primitiveBytesCol)); assertTrue(Arrays.equals(new Byte[] {4, 5, 6}, res.bytesCol)); assertTrue(Arrays.deepEquals(new Integer[] {0, 1}, res.intsCol)); assertTrue(Arrays.equals(new int[] {2, 3}, res.primitiveIntsCol)); AllTypes.InnerType expInnerType = new AllTypes.InnerType(80L); expInnerType.innerLongCol = 5L; assertEquals(expInnerType, res.innerTypeCol); assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm:SS").parse("2016-11-30 12:00:00"), res.dateCol); assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm:SS").parse("2016-12-03 00:02:00"), res.tsCol); assertEquals(2, res.intCol); assertEquals(AllTypes.EnumType.ENUMTRUE, res.enumCol); assertEquals(new java.sql.Date(new SimpleDateFormat("yyyy-MM-dd").parse("2016-12-02").getTime()), res.sqlDateCol); // 49th week, right? assertEquals(49, res.shortCol); } finally { GridTestUtils.setFieldValue(UpdatePlanBuilder.class, "ALLOW_KEY_VAL_UPDATES", oldAllowColumnsVal); } }
Example 12
Source File: IgniteTxMultiNodeAbstractTest.java From ignite with Apache License 2.0 | 4 votes |
/** * * @param kind Partition ownership to display in log. * @param putCntr Put counter to cache. * @param ignite Grid. * @param itemKey Item key. * @param retry Retry count. */ private void onItem(String kind, boolean putCntr, Ignite ignite, String itemKey, int retry) { IgniteCache<String, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME); UUID locId = ignite.cluster().localNode().id(); UUID itemPrimaryId = primaryId(ignite, itemKey); UUID cntrPrimaryId = primaryId(ignite, CNTR_KEY); boolean isCntrPrimary = cntrPrimaryId.equals(locId); try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { if (DEBUG) info("Before " + kind + " get [retry=" + retry + ", xid=" + tx.xid() + ", node=" + ignite.name() + ", isCntrPrimary=" + isCntrPrimary + ", nearId=" + locId + ", nearEntry=" + nearEntry(locId, CNTR_KEY) + (isCntrPrimary ? ", dhtEntry=" + dhtEntry(locId, CNTR_KEY) : "") + ']'); Integer cntr = cache.get(CNTR_KEY); int newVal = cntr + 1; if (putCntr) { if (DEBUG) info("Before " + kind + " put counter [retry=" + retry + ", isCntrPrimary=" + isCntrPrimary + ", cur=" + cntr + ", new=" + newVal + ", nearEntry=" + nearEntry(locId, CNTR_KEY) + (isCntrPrimary ? ", dhtEntry=" + dhtEntry(locId, CNTR_KEY) : "") + ']'); cache.put(CNTR_KEY, newVal); } if (DEBUG) info("Before " + kind + " put item [retry=" + retry + ", key=" + itemKey + ", cur=" + cntr + ", new=" + newVal + ", nearEntry=" + nearEntry(locId, itemKey) + ", dhtEntry=" + dhtEntry(itemPrimaryId, itemKey) + ']'); cache.put(itemKey, newVal); if (DEBUG) info("After " + kind + " put item [retry=" + retry + ", key=" + itemKey + ", old=" + cntr + ", new=" + newVal + ", nearEntry=" + nearEntry(locId, itemKey) + ", dhtEntry" + dhtEntry(itemPrimaryId, itemKey) + ']'); tx.commit(); } }
Example 13
Source File: GridCacheNearMetricsSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testPrimaryPut() throws Exception { Ignite g0 = grid(0); IgniteCache<Integer, Integer> cache0 = g0.cache(DEFAULT_CACHE_NAME); int key; // Put and get a few keys. for (int i = 0; ; i++) { if (affinity(cache0).isPrimary(g0.cluster().localNode(), i)) { cache0.getAndPut(i, i); // +1 read cache0.get(i); // +1 read. key = i; info("Puts: " + cache0.localMetrics().getCachePuts()); info("Reads: " + cache0.localMetrics().getCacheGets()); info("Affinity nodes: " + U.nodes2names(affinity(cache0).mapKeyToPrimaryAndBackups(i))); break; } } for (int j = 0; j < gridCount(); j++) { Ignite g = grid(j); info("Checking grid: " + g.name()); IgniteCache<Object, Object> jcache = g.cache(DEFAULT_CACHE_NAME); info("Puts: " + jcache.localMetrics().getCachePuts()); info("Reads: " + jcache.localMetrics().getCacheGets()); if (affinity(jcache).isPrimaryOrBackup(g.cluster().localNode(), key)) assertEquals(1, jcache.localMetrics().getCachePuts()); else assertEquals(0, jcache.localMetrics().getCachePuts()); if (affinity(jcache).isPrimary(g.cluster().localNode(), key)) { assertEquals(2, jcache.localMetrics().getCacheGets()); assertEquals(1, jcache.localMetrics().getCacheHits()); assertEquals(1, jcache.localMetrics().getCacheMisses()); } else { assertEquals(0, jcache.localMetrics().getCacheGets()); assertEquals(0, jcache.localMetrics().getCacheHits()); assertEquals(0, jcache.localMetrics().getCacheMisses()); } } }
Example 14
Source File: GridCacheAbstractDistributedByteArrayValuesSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Test transaction behavior. * * @param caches Caches. * @param concurrency Concurrency. * @param key1 Key 1. * @param val1 Value 1. * @param key2 Key 2. * @param val2 Value 2. * @throws Exception If failed. */ private void testTransactionMixed0(IgniteCache<Integer, Object>[] caches, TransactionConcurrency concurrency, Integer key1, byte[] val1, @Nullable Integer key2, @Nullable Object val2) throws Exception { if (MvccFeatureChecker.forcedMvcc() && !MvccFeatureChecker.isSupported(concurrency, REPEATABLE_READ)) return; for (IgniteCache<Integer, Object> cache : caches) { info("Checking cache: " + cache.getName()); Transaction tx = cache.unwrap(Ignite.class).transactions().txStart(concurrency, REPEATABLE_READ); try { cache.put(key1, val1); if (key2 != null) cache.put(key2, val2); tx.commit(); } finally { tx.close(); } for (IgniteCache<Integer, Object> cacheInner : caches) { info("Getting value from cache: " + cacheInner.getName()); tx = cacheInner.unwrap(Ignite.class).transactions().txStart(concurrency, REPEATABLE_READ); try { assertArrayEquals(val1, (byte[])cacheInner.get(key1)); if (key2 != null) { Object actual = cacheInner.get(key2); assertEquals(val2, actual); } tx.commit(); } finally { tx.close(); } } tx = cache.unwrap(Ignite.class).transactions().txStart(concurrency, REPEATABLE_READ); try { cache.remove(key1); if (key2 != null) cache.remove(key2); tx.commit(); } finally { tx.close(); } assertNull(cache.get(key1)); } }
Example 15
Source File: WalRecoveryTxLogicalRecordsTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testFreeListRecovery() throws Exception { try { pageSize = 1024; extraCcfg = new CacheConfiguration(CACHE2_NAME); Ignite ignite = startGrid(0); ignite.cluster().active(true); IgniteCache<Integer, IndexedValue> cache1 = ignite.cache(CACHE_NAME); IgniteCache<Object, Object> cache2 = ignite.cache(CACHE2_NAME); final int KEYS1 = 2048; for (int i = 0; i < KEYS1; i++) cache1.put(i, new IndexedValue(i)); for (int i = 0; i < KEYS1; i++) { if (i % 2 == 0) cache1.remove(i); } ThreadLocalRandom rnd = ThreadLocalRandom.current(); for (int i = 0; i < KEYS1; i++) { cache2.put(i, new byte[rnd.nextInt(512)]); if (rnd.nextBoolean()) cache2.put(i, new byte[rnd.nextInt(512)]); if (rnd.nextBoolean()) cache2.remove(i); } Map<Integer, T2<Map<Integer, long[]>, int[]>> cache1_1 = getFreeListData(ignite, CACHE_NAME); Map<Integer, T2<Map<Integer, long[]>, int[]>> cache2_1 = getFreeListData(ignite, CACHE2_NAME); T2<long[], Integer> rl1_1 = getReuseListData(ignite, CACHE_NAME); T2<long[], Integer> rl2_1 = getReuseListData(ignite, CACHE2_NAME); ignite.close(); ignite = startGrid(0); ignite.cluster().active(true); cache1 = ignite.cache(CACHE_NAME); cache2 = ignite.cache(CACHE2_NAME); for (int i = 0; i < KEYS1; i++) { cache1.get(i); cache2.get(i); } Map<Integer, T2<Map<Integer, long[]>, int[]>> cache1_2 = getFreeListData(ignite, CACHE_NAME); Map<Integer, T2<Map<Integer, long[]>, int[]>> cache2_2 = getFreeListData(ignite, CACHE2_NAME); T2<long[], Integer> rl1_2 = getReuseListData(ignite, CACHE_NAME); T2<long[], Integer> rl2_2 = getReuseListData(ignite, CACHE2_NAME); checkEquals(cache1_1, cache1_2); checkEquals(cache2_1, cache2_2); checkEquals(rl1_1, rl1_2); checkEquals(rl2_1, rl2_2); } finally { stopAllGrids(); } }
Example 16
Source File: IgniteCacheConfigVariationsFullApiTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testGetAndPutIfAbsentAsyncOld() throws Exception { Transaction tx = txShouldBeUsed() ? transactions().txStart() : null; IgniteCache<String, Integer> cache = jcache(); IgniteCache<String, Integer> cacheAsync = cache.withAsync(); try { cacheAsync.getAndPutIfAbsent("key", 1); IgniteFuture<Integer> fut1 = cacheAsync.future(); assertNull(fut1.get()); assertEquals((Integer)1, cache.get("key")); cacheAsync.getAndPutIfAbsent("key", 2); IgniteFuture<Integer> fut2 = cacheAsync.future(); assertEquals((Integer)1, fut2.get()); assertEquals((Integer)1, cache.get("key")); if (tx != null) tx.commit(); } finally { if (tx != null) tx.close(); } if (!storeEnabled()) return; // Check swap. cache.put("key2", 1); cache.localEvict(Collections.singleton("key2")); if (!isLoadPreviousValue()) cache.get("key2"); cacheAsync.getAndPutIfAbsent("key2", 3); assertEquals((Integer)1, cacheAsync.<Integer>future().get()); // Check db. if (storeEnabled() && isLoadPreviousValue() && !isMultiJvm()) { putToStore("key3", 3); cacheAsync.getAndPutIfAbsent("key3", 4); assertEquals((Integer)3, cacheAsync.<Integer>future().get()); } cache.localEvict(Collections.singleton("key2")); if (!isLoadPreviousValue()) cache.get("key2"); // Same checks inside tx. tx = txShouldBeUsed() ? transactions().txStart() : null; try { cacheAsync.getAndPutIfAbsent("key2", 3); assertEquals(1, cacheAsync.future().get()); if (tx != null) tx.commit(); assertEquals((Integer)1, cache.get("key2")); } finally { if (tx != null) tx.close(); } }
Example 17
Source File: IncludeSensitiveAbstractTest.java From ignite with Apache License 2.0 | 3 votes |
/** * Tests basic cache operations. * * @throws Exception If failed. */ @Test public void test() throws Exception { IgniteCache<Long, String> cache = grid(0).cache(DEFAULT_CACHE_NAME); startTx(); for (int i = 1; i < ENTRY_CNT; ++i) cache.put(key(i), value(i)); commitTx(); cache.get(key(ENTRY_CNT / 2)); for (int i = 1; i < ENTRY_CNT; ++i) cache.invoke(key(i), new TestEntryProcessor()); stopGrid(1); cache.rebalance().get(); for (int i = 0; i < ENTRY_CNT; ++i) cache.get(key(i)); startGrid(1); cache.rebalance().get(); startTx(); for (int i = 1; i < ENTRY_CNT; ++i) cache.remove(key(i)); commitTx(); }
Example 18
Source File: IgniteUidAsConsistentIdMigrationTest.java From ignite with Apache License 2.0 | 3 votes |
/** * Checks start on configured ConsistentId with same value as default, this emulate old style folder is already * available. We should restart using this folder. * * @throws Exception if failed */ @Test public void testRestartOnExistingOldStyleId() throws Exception { final String expDfltConsistentId = "127.0.0.1:47500"; this.configuredConsistentId = expDfltConsistentId; //this is for create old node folder final Ignite igniteEx = startActivateGrid(0); final String expVal = "there is compatible mode with old style folders!"; igniteEx.getOrCreateCache(CACHE_NAME).put("hi", expVal); assertPdsDirsDefaultExist(U.maskForFileName(configuredConsistentId)); stopGrid(0); this.configuredConsistentId = null; //now set up grid on existing folder final Ignite igniteRestart = startActivateGrid(0); assertEquals(expDfltConsistentId, igniteRestart.cluster().localNode().consistentId()); final IgniteCache<Object, Object> cache = igniteRestart.cache(CACHE_NAME); assertNotNull("Expected to have cache [" + CACHE_NAME + "] using [" + expDfltConsistentId + "] as PDS folder", cache); final Object valFromCache = cache.get("hi"); assertNotNull("Expected to load data from cache using [" + expDfltConsistentId + "] as PDS folder", valFromCache); assertTrue(expVal.equals(valFromCache)); stopGrid(0); }
Example 19
Source File: IgniteCacheGroupsTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @param cache Cache. */ private void cachePutGetAndReplace(IgniteCache cache) { Random rnd = ThreadLocalRandom.current(); Integer key = rnd.nextInt(); Integer val1 = rnd.nextInt(); Integer val2 = rnd.nextInt(); Object val0 = cache.getAndReplace(key, val1); assertEquals(null, val0); val0 = cache.get(key); assertEquals(null, val0); cache.put(key, val1); val0 = cache.getAndReplace(key, val2); assertEquals(val1, val0); val0 = cache.get(key); assertEquals(val2, val0); tearDown(cache); }
Example 20
Source File: IgniteCacheTxStoreSessionTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @param cache Cache. * @param concurrency Concurrency mode. * @param isolation Isolation mode. * @throws Exception If failed. */ private void testTxPut(IgniteCache<Object, Object> cache, TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception { log.info("Test tx put [concurrency=" + concurrency + ", isolation=" + isolation + ']'); List<Integer> keys = testKeys(cache, 3); Integer key1 = keys.get(0); try (Transaction tx = startTx(concurrency, isolation)) { log.info("Do tx get."); expData.add(new ExpectedData(false, "load", new HashMap(), cache.getName())); expData.add(new ExpectedData(true, "sessionEnd", F.<Object, Object>asMap(0, "load"), cache.getName())); cache.get(key1); expData.clear(); log.info("Do tx put."); cache.put(key1, key1); expData.add(new ExpectedData(true, "write", new HashMap<>(), cache.getName())); expData.add(new ExpectedData(true, "sessionEnd", F.<Object, Object>asMap(0, "write"), cache.getName())); log.info("Do tx commit."); tx.commit(); } assertEquals(0, expData.size()); Integer key2 = keys.get(1); Integer key3 = keys.get(2); try (Transaction tx = startTx(concurrency, isolation)) { log.info("Do tx put1."); cache.put(key2, key2); log.info("Do tx put2."); cache.put(key3, key3); expData.add(new ExpectedData(true, "writeAll", new HashMap<>(), cache.getName())); expData.add(new ExpectedData(true, "sessionEnd", F.<Object, Object>asMap(0, "writeAll"), cache.getName())); log.info("Do tx commit."); tx.commit(); } assertEquals(0, expData.size()); }