Java Code Examples for org.apache.ignite.internal.IgniteEx#getOrCreateCache()
The following examples show how to use
org.apache.ignite.internal.IgniteEx#getOrCreateCache() .
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: OomFailureHandlerTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Test OOME in service method invocation. */ @Test public void testServiceInvokeOomError() throws Exception { IgniteEx ignite0 = startGrid(0); IgniteEx ignite1 = startGrid(1); IgniteCache<Integer, Integer> cache1 = ignite1.getOrCreateCache(DEFAULT_CACHE_NAME); awaitPartitionMapExchange(); Integer key = primaryKey(cache1); ignite0.services().deployKeyAffinitySingleton("fail-invoke-service", new FailServiceImpl(false), DEFAULT_CACHE_NAME, key); FailService svc = ignite0.services().serviceProxy("fail-invoke-service", FailService.class, false); try { svc.fail(); } catch (Throwable ignore) { // Expected. } assertFailureState(ignite0, ignite1); }
Example 2
Source File: SchemaExchangeSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Check empty metadata propagation. * * @param dynamic Dynamic start flag. * @throws Exception If failed. */ private void checkEmpty(boolean dynamic) throws Exception { IgniteEx node1; if (dynamic) { node1 = startNoCache(1); node1.getOrCreateCache(cacheConfiguration()); } else node1 = start(1); assertTypes(node1); IgniteEx node2 = start(2, KeyClass.class, ValueClass.class); assertTypes(node1); assertTypes(node2); IgniteEx node3 = start(3, KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class); assertTypes(node1); assertTypes(node2); assertTypes(node3); }
Example 3
Source File: CacheBlockOnReadAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Reinit internal cache using passed ignite instance and fill it with data if required. * * @param ignite Node to get or create cache from. * @param fillData Whether the cache should be filled with new data or not. */ public void initCache(IgniteEx ignite, boolean fillData) { cache = ignite.getOrCreateCache( createCacheConfiguration() .setAtomicityMode(atomicityMode()) .setCacheMode(cacheMode()) ); if (fillData) { try (IgniteDataStreamer<KeyType, ValueType> dataStreamer = ignite.dataStreamer(cache.getName())) { dataStreamer.allowOverwrite(true); for (int i = 0; i < entriesCount(); i++) dataStreamer.addData(createKey(i), createValue(i)); } } }
Example 4
Source File: IgniteCacheGroupsWithRestartsTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param ignite Ignite instance. */ private void prepareCachesAndData(IgniteEx ignite) { ignite.cluster().active(true); for (int j = 0; j < 3; j++) { for (int i = 0; i < 64 * 10; i++) { IgniteCache<Object, Object> cache = ignite.getOrCreateCache(getCacheConfiguration(j)); byte[] val = new byte[ThreadLocalRandom.current().nextInt(8148)]; Arrays.fill(val, (byte)i); cache.put((long)i, new Account(i)); } } }
Example 5
Source File: IgnitePdsWithTtlTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception if failed. */ @Test public void testTtlIsAppliedForMultipleCaches() throws Exception { IgniteEx srv = startGrid(0); srv.cluster().active(true); int cacheCnt = 2; // Create a new caches in the same group. // It is important that initially created cache CACHE_NAME remains empty. for (int i = 0; i < cacheCnt; ++i) { String cacheName = CACHE_NAME + "-" + i; srv.getOrCreateCache(getCacheConfiguration(cacheName)); fillCache(srv.cache(cacheName)); } waitAndCheckExpired(srv, srv.cache(CACHE_NAME + "-" + (cacheCnt - 1))); srv.cluster().active(false); stopAllGrids(); }
Example 6
Source File: OomFailureHandlerTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Test OOME in EntryProcessor. */ @Test public void testEntryProcessorOomError() throws Exception { IgniteEx ignite0 = startGrid(0); IgniteEx ignite1 = startGrid(1); IgniteCache<Integer, Integer> cache0 = ignite0.getOrCreateCache(DEFAULT_CACHE_NAME); IgniteCache<Integer, Integer> cache1 = ignite1.getOrCreateCache(DEFAULT_CACHE_NAME); awaitPartitionMapExchange(); Integer key = primaryKey(cache1); cache1.put(key, key); try { IgniteFuture fut = cache0.invokeAsync(key, new EntryProcessor<Integer, Integer, Object>() { @Override public Object process(MutableEntry<Integer, Integer> entry, Object... arguments) throws EntryProcessorException { throw new OutOfMemoryError(); } }); fut.get(); } catch (Throwable ignore) { // Expected. } assertFailureState(ignite0, ignite1); }
Example 7
Source File: CacheWithDifferentDataRegionConfigurationTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param node Node. * @param cacheName Cache name. * @param size Size. */ public void populateCache(IgniteEx node, String cacheName, int size) { IgniteCache<Integer, Integer> cache = node.getOrCreateCache(cacheName); for (int i = 0; i < size; i++) cache.put(i, i); }
Example 8
Source File: ClassLoadingProblemExceptionTest.java From ignite with Apache License 2.0 | 5 votes |
/** * * @param spoilDeploymentBeforePrepare Test the check on preparing message. * @param spoilMsgOnSnd Test the check on receiving message. * @param eExp Exception expected. * @throws Exception If failed. */ private void doTest( boolean spoilDeploymentBeforePrepare, boolean spoilMsgOnSnd, Class<? extends Throwable> eExp ) throws Exception { this.spoilDeploymentBeforePrepare = spoilDeploymentBeforePrepare; this.spoilMsgOnSnd = spoilMsgOnSnd; this.exceptionThrown.set(null); IgniteEx crd = (IgniteEx)startGridsMultiThreaded(1); crd.getOrCreateCache(CACHE_NAME); IgniteEx client1 = startGrid(CLIENT_1); IgniteEx client2 = startGrid(CLIENT_2); awaitPartitionMapExchange(); GridDeploymentManager deploymentMgr = client2.context().deploy(); GridDeploymentStore store = GridTestUtils.getFieldValue(deploymentMgr, "locStore"); GridTestUtils.setFieldValue(deploymentMgr, "locStore", new GridDeploymentTestStore(store)); client1.compute(client1.cluster().forRemotes()).execute(new P2PDeploymentLongRunningTask(), null); if (exceptionThrown.get() != null) exceptionThrown.get().printStackTrace(); assertTrue( "Wrong exception: " + exceptionThrown.get(), exceptionThrown.get() == null && eExp == null || X.hasCause(exceptionThrown.get(), eExp) ); }
Example 9
Source File: IgniteNativeIoWithNoPersistenceTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Checks simple launch with native IO. * @throws Exception if failed */ @Test public void testDirectIoHandlesNoPersistentGrid() throws Exception { IgniteEx ignite = startGrid(0); ignite.active(true); IgniteCache<Object, Object> cache = ignite.getOrCreateCache("cache"); for (int i = 0; i < 100; i++) cache.put(i, valueForKey(i)); stopAllGrids(); }
Example 10
Source File: OomFailureHandlerTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Test OOME in event listener. */ @Test public void testEventListenerOomError() throws Exception { IgniteEx ignite0 = startGrid(0); IgniteEx ignite1 = startGrid(1); IgniteCache<Integer, Integer> cache0 = ignite0.getOrCreateCache(DEFAULT_CACHE_NAME); IgniteCache<Integer, Integer> cache1 = ignite1.getOrCreateCache(DEFAULT_CACHE_NAME); awaitPartitionMapExchange(); ignite1.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { throw new OutOfMemoryError(); } }, EventType.EVT_CACHE_OBJECT_PUT); Integer key = primaryKey(cache1); try { cache0.put(key, key); } catch (Throwable ignore) { // Expected. } assertFailureState(ignite0, ignite1); }
Example 11
Source File: ArrayIndexTest.java From ignite with Apache License 2.0 | 5 votes |
/** * */ @Test public void shouldSelectAllRows() throws Exception { IgniteEx ex = startGrid(0); ex.cluster().active(true); IgniteCache<Object, Object> cache = ex.getOrCreateCache(DEFAULT_CACHE_NAME); cache.put(new byte[] {8, 9, 10}, 3); cache.put(new byte[] {1, 2, 3}, 1); cache.put(new byte[] {5, 6, 7}, 2); List<List<?>> sorted = cache.query(new SqlFieldsQuery("select _key, _val from Integer")).getAll(); assertEquals(3, sorted.size()); List<?> first = sorted.get(0); assertTrue(Objects.deepEquals(first.get(0), new byte[] {1, 2, 3})); assertTrue(Objects.deepEquals(first.get(1), 1)); List<?> second = sorted.get(1); assertTrue(Objects.deepEquals(second.get(0), new byte[] {5, 6, 7})); assertTrue(Objects.deepEquals(second.get(1), 2)); List<?> third = sorted.get(2); assertTrue(Objects.deepEquals(third.get(0), new byte[] {8, 9, 10})); assertTrue(Objects.deepEquals(third.get(1), 3)); }
Example 12
Source File: MvccUnsupportedTxModesTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); IgniteEx ign = startGrid(0); cache = ign.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME) .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); }
Example 13
Source File: IgniteStandByClusterTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception if fail. */ @Test public void testSimple() throws Exception { IgniteEx ig = startGrid(0); ig.active(true); IgniteCache<Integer, String> cache0 = ig.getOrCreateCache("cache"); cache0.put(1, "1"); assertEquals("1", cache0.get(1)); ig.active(false); assertTrue(!ig.active()); ig.active(true); IgniteCache<Integer, String> cache = ig.cache("cache"); assertEquals("1", cache.get(1)); }
Example 14
Source File: IgniteDynamicCacheStartSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** */ @Test public void testGetOrCreate() throws Exception { try { final CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME); cfg.setName(DYNAMIC_CACHE_NAME); cfg.setNodeFilter(NODE_FILTER); grid(0).getOrCreateCache(cfg); grid(0).getOrCreateCache(cfg); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return grid(0).getOrCreateCache(cfg, new NearCacheConfiguration()); } }, CacheException.class, null); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return grid(0).getOrCreateNearCache(DYNAMIC_CACHE_NAME, new NearCacheConfiguration()); } }, CacheException.class, null); testAttribute = false; startGrid(nodeCount()); startGrid(nodeCount() + 1); try { IgniteEx nearGrid = grid(nodeCount()); nearGrid.getOrCreateCache(cfg, new NearCacheConfiguration()); nearGrid.getOrCreateNearCache(DYNAMIC_CACHE_NAME, new NearCacheConfiguration()); GridCacheContext<Object, Object> nCtx = ((IgniteKernal)nearGrid) .internalCache(DYNAMIC_CACHE_NAME).context(); assertTrue(nCtx.isNear()); assertFalse(nCtx.affinityNode()); IgniteEx clientGrid = grid(nodeCount() + 1); clientGrid.getOrCreateCache(cfg); clientGrid.getOrCreateCache(cfg); GridCacheContext<Object, Object> cCtx = ((IgniteKernal)clientGrid) .internalCache(DYNAMIC_CACHE_NAME).context(); assertFalse(cCtx.isNear()); assertFalse(cCtx.affinityNode()); } finally { stopGrid(nodeCount() + 1); stopGrid(nodeCount()); } } finally { grid(0).destroyCache(DYNAMIC_CACHE_NAME); } }
Example 15
Source File: ServicePredicateAccessCacheTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testPredicateAccessCache() throws Exception { final IgniteEx ignite0 = startGrid(0); CacheConfiguration<String, String> cacheCfg = new CacheConfiguration<>(); cacheCfg.setName("testCache"); cacheCfg.setAtomicityMode(ATOMIC); cacheCfg.setCacheMode(REPLICATED); cacheCfg.setWriteSynchronizationMode(FULL_SYNC); IgniteCache<String, String> cache = ignite0.getOrCreateCache(cacheCfg); if (ignite0.context().service() instanceof IgniteServiceProcessor) cache.put(ignite0.cluster().localNode().id().toString(), "val"); latch = new CountDownLatch(1); final ClusterGroup grp = ignite0.cluster().forPredicate((IgnitePredicate<ClusterNode>)node -> { System.out.println("Predicated started [thread=" + Thread.currentThread().getName() + ']'); latch.countDown(); try { Thread.sleep(3000); } catch (InterruptedException ignore) { // No-op. } System.out.println("Call contains key [thread=" + Thread.currentThread().getName() + ']'); boolean ret = Ignition.localIgnite().cache("testCache").containsKey(node.id().toString()); System.out.println("After contains key [ret=" + ret + ", thread=" + Thread.currentThread().getName() + ']'); return ret; }); IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() { @Override public Void call() throws Exception { info("Start deploy service."); ignite0.services(grp).deployNodeSingleton("testService", new TestService()); info("Service deployed."); return null; } }, "deploy-thread"); latch.await(); startGrid(1); fut.get(); }
Example 16
Source File: RebuildIndexTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @throws Exception if failed. */ private void check(boolean msgFound) throws Exception { srvLog = new ListeningTestLogger(false, log); LogListener idxRebuildLsnr = LogListener.matches(idxRebuildPattert).build(); srvLog.registerListener(idxRebuildLsnr); IgniteEx node = startGrids(2); node.cluster().active(true); IgniteCache<UserKey, UserValue> cache = node.getOrCreateCache(CACHE_NAME); cache.put(new UserKey(1), new UserValue(333)); cache.put(new UserKey(2), new UserValue(555)); stopGrid(0); removeIndexBin(0); node = startGrid(0); awaitPartitionMapExchange(); forceCheckpoint(); enableCheckpoints(G.allGrids(), false); // Validate indexes on start. ValidateIndexesClosure clo = new ValidateIndexesClosure(Collections.singleton(CACHE_NAME), 0, 0, false, true); node.context().resource().injectGeneric(clo); assertFalse(clo.call().hasIssues()); assertEquals(msgFound, idxRebuildLsnr.check()); }
Example 17
Source File: CacheMvccTxRecoveryTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @throws Exception if failed. */ @Test public void testRecoveryCommit() throws Exception { startGridsMultiThreaded(2); client = true; IgniteEx ign = startGrid(2); IgniteCache<Object, Object> cache = ign.getOrCreateCache(basicCcfg()); AtomicInteger keyCntr = new AtomicInteger(); ArrayList<Integer> keys = new ArrayList<>(); ign.cluster().forServers().nodes() .forEach(node -> keys.add(keyForNode(ign.affinity(DEFAULT_CACHE_NAME), keyCntr, node))); GridTestUtils.runAsync(() -> { // run in separate thread to exclude tx from thread-local map Transaction tx = ign.transactions().txStart(PESSIMISTIC, REPEATABLE_READ); for (Integer k : keys) cache.query(new SqlFieldsQuery("insert into Integer(_key, _val) values(?, 42)").setArgs(k)); ((TransactionProxyImpl)tx).tx().prepareNearTxLocal().get(); return null; }).get(); // drop near stopGrid(2, true); IgniteEx srvNode = grid(0); assertConditionEventually( () -> srvNode.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer")).getAll().size() == 2 ); assertPartitionCountersAreConsistent(keys, G.allGrids()); }
Example 18
Source File: CacheMvccTxFailoverTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @param rollBack If {@code True} then Tx will be rolled backup, committed otherwise. * @param recoverFromWAL If {@code True} then Tx recovery from WAL will be checked, * binary recovery from latest checkpoint otherwise. * @param omitTxFinish If {@code True} then unfinished Tx state will be restored as if node fails during commit. * @throws Exception If fails. */ public void checkSingleNodeRestart(boolean rollBack, boolean recoverFromWAL, boolean omitTxFinish) throws Exception { IgniteEx node = startGrid(0); node.cluster().active(true); IgniteCache<Integer, Integer> cache = node.getOrCreateCache(DEFAULT_CACHE_NAME); cache.put(1, 1); cache.put(2, 1); IgniteTransactions txs = node.transactions(); IgniteWriteAheadLogManager wal = node.context().cache().context().wal(); if (recoverFromWAL) { //Force checkpoint. See for details: https://issues.apache.org/jira/browse/IGNITE-10187 node.context().cache().context().database().waitForCheckpoint(null); ((GridCacheDatabaseSharedManager)node.context().cache().context().database()).enableCheckpoints(false).get(); } GridTimeoutProcessor.CancelableTask flushTask = GridTestUtils.getFieldValue(wal, FileWriteAheadLogManager.class, "backgroundFlushSchedule"); WalStateManager.WALDisableContext wctx = GridTestUtils.getFieldValue(wal, FileWriteAheadLogManager.class, "walDisableContext"); // Disable checkpoint and WAL flusher. node.context().timeout().removeTimeoutObject(flushTask); try (Transaction tx = txs.txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { assertEquals((Integer)1, cache.get(1)); cache.put(2, 2); flushTask.onTimeout(); // Flush WAL. if (!recoverFromWAL) { //Force checkpoint, then disable. node.context().cache().context().database().waitForCheckpoint(null); ((GridCacheDatabaseSharedManager)node.context().cache().context().database()).enableCheckpoints(false).get(); } if (omitTxFinish) GridTestUtils.setFieldValue(wctx, "disableWal", true); // Disable wal. if (rollBack) tx.rollback(); else tx.commit(); } stopGrid(0); node = startGrid(0); node.cluster().active(true); cache = node.cache(DEFAULT_CACHE_NAME); assertEquals((Integer)1, cache.get(1)); if (omitTxFinish || rollBack) assertEquals((Integer) 1, cache.get(2)); // Commit\rollback marker were saved neither in WAL nor in checkpoint. else assertEquals((Integer) 2, cache.get(2)); cache.put(2, 3); assertEquals((Integer)3, cache.get(2)); }
Example 19
Source File: TxPartitionCounterStateConsistencyTest.java From ignite with Apache License 2.0 | 2 votes |
/** * Tests for same order of updates on all owners after txs are finished. */ @Test public void testSingleThreadedUpdateOrder() throws Exception { backups = 2; startGridsMultiThreaded(SERVER_NODES); IgniteEx client = startClientGrid(CLIENT_GRID_NAME); IgniteCache<Object, Object> cache = client.getOrCreateCache(DEFAULT_CACHE_NAME); List<Integer> keys = partitionKeys(cache, PARTITION_ID, 100, 0); LinkedList<T2<Integer, GridCacheOperation>> ops = new LinkedList<>(); final CacheAtomicityMode mode = atomicityMode(cache); final GridCacheOperation op = mode == ATOMIC ? UPDATE : CREATE; cache.put(keys.get(0), new TestVal(keys.get(0))); ops.add(new T2<>(keys.get(0), op)); cache.put(keys.get(1), new TestVal(keys.get(1))); ops.add(new T2<>(keys.get(1), op)); cache.put(keys.get(2), new TestVal(keys.get(2))); ops.add(new T2<>(keys.get(2), op)); assertCountersSame(PARTITION_ID, false); cache.remove(keys.get(2)); ops.add(new T2<>(keys.get(2), GridCacheOperation.DELETE)); cache.remove(keys.get(1)); ops.add(new T2<>(keys.get(1), GridCacheOperation.DELETE)); cache.remove(keys.get(0)); ops.add(new T2<>(keys.get(0), GridCacheOperation.DELETE)); assertCountersSame(PARTITION_ID, false); for (Ignite ignite : G.allGrids()) { if (ignite.configuration().isClientMode()) continue; checkWAL((IgniteEx)ignite, new LinkedList<>(ops), 6); } }
Example 20
Source File: BasicIndexTest.java From ignite with Apache License 2.0 | 2 votes |
/** */ private void runDynamicIdxOnStaticCacheWithIdx(boolean persistEnabled) throws Exception { isPersistenceEnabled = persistEnabled; inlineSize = 10; createIdx = false; indexes = Collections.singletonList(new QueryIndex("valStr")); IgniteEx ig0 = startGrid(0); createIdx = true; startGrid(1); if (persistEnabled) ig0.cluster().active(true); IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME); populateCache(); String plan = cache.query(new SqlFieldsQuery("explain select * from Val where valStr between 0 and ?") .setArgs(100)).getAll().get(0).get(0).toString(); assertTrue(plan, plan.contains(SCAN_INDEX_NAME_SUFFIX)); stopAllGrids(); if (persistEnabled) cleanPersistenceDir(); createStaticCache = false; ig0 = startGrid(0); if (persistEnabled) ig0.cluster().active(true); ig0.getOrCreateCache(DEFAULT_CACHE_NAME); populateCache(); createStaticCache = true; try { startGrid(1); fail("Exception wasn't thrown"); } catch (IgniteCheckedException e) { // no op. } }