org.apache.ignite.IgniteCache Java Examples
The following examples show how to use
org.apache.ignite.IgniteCache.
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: GridCacheP2PUndeploySelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache Cache. * @param timeout Timeout. * @return {@code True} if success. * @throws InterruptedException If thread was interrupted. */ @SuppressWarnings({"BusyWait"}) private boolean waitCacheEmpty(IgniteCache<Integer, Object> cache, long timeout) throws InterruptedException { assert cache != null; assert timeout >= 0; long end = System.currentTimeMillis() + timeout; while (end - System.currentTimeMillis() >= 0) { if (cache.localSize() == 0) return true; Thread.sleep(500); } return cache.localSize() == 0; }
Example #2
Source File: GridCacheBinaryObjectsAbstractSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testGet() throws Exception { IgniteCache<Integer, TestObject> c = jcache(0); for (int i = 0; i < ENTRY_CNT; i++) c.put(i, new TestObject(i)); for (int i = 0; i < ENTRY_CNT; i++) { TestObject obj = c.get(i); assertEquals(i, obj.val); } IgniteCache<Integer, BinaryObject> kpc = keepBinaryCache(); for (int i = 0; i < ENTRY_CNT; i++) { BinaryObject po = kpc.get(i); assertEquals(i, (int)po.field("val")); } }
Example #3
Source File: LongRunningQueryTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); startGrid(); IgniteCache c = grid().createCache(new CacheConfiguration<Long, Long>() .setName("test") .setSqlSchema("TEST") .setQueryEntities(Collections.singleton(new QueryEntity(Long.class, Long.class) .setTableName("test") .addQueryField("id", Long.class.getName(), null) .addQueryField("val", Long.class.getName(), null) .setKeyFieldName("id") .setValueFieldName("val") )) .setAffinity(new RendezvousAffinityFunction(false, 10)) .setSqlFunctionClasses(TestSQLFunctions.class)); for (long i = 0; i < KEY_CNT; ++i) c.put(i, i); }
Example #4
Source File: IgniteSqlSegmentedIndexSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Verifies that <code>select count(*)</code> return valid result on a single-node grid. */ @SuppressWarnings("deprecation") @Test public void testSizeOnSegmentedIndexWithEvictionPolicy() { final IgniteCache<Object, Object> cache = ignite(0).createCache( cacheConfig(ORG_CACHE_NAME, true, Integer.class, Organization.class) .setEvictionPolicy(new FifoEvictionPolicy(10)) .setOnheapCacheEnabled(true)); final long SIZE = 20; for (int i = 0; i < SIZE; i++) cache.put(i, new Organization("org-" + i)); String select0 = "select count(*) from \"org\".Organization"; List<List<?>> res = cache.query(new SqlFieldsQuery(select0)).getAll(); assertEquals(SIZE, res.get(0).get(0)); }
Example #5
Source File: CacheOptimisticTransactionsWithFilterTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cache Cache. * @return Test keys. * @throws Exception If failed. */ private List<Integer> testKeys(IgniteCache<Integer, Integer> cache) throws Exception { CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class); List<Integer> keys = new ArrayList<>(); if (!cache.unwrap(Ignite.class).configuration().isClientMode()) { if (ccfg.getCacheMode() == PARTITIONED && serversNumber() > 1) keys.add(nearKey(cache)); keys.add(primaryKey(cache)); if (ccfg.getBackups() != 0 && serversNumber() > 1) keys.add(backupKey(cache)); } else keys.add(nearKey(cache)); return keys; }
Example #6
Source File: IgniteCacheReadThroughEvictionSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception if failed. */ @Ignore("https://issues.apache.org/jira/browse/IGNITE-11849") @Test public void testReadThroughSkipStore() throws Exception { Ignite ig = testedGrid(); CacheConfiguration<Object, Object> cc = variationConfig("skipStore"); final IgniteCache<Object, Object> cache = ig.createCache(cc); try { for (int i = 0; i < KEYS; i++) { cache.put(key(i), value(i)); cache.withSkipStore().remove(key(i)); } waitEmpty(cc.getName()); for (int i = 0; i < KEYS; i++) assertEquals(value(i), cache.get(key(i))); } finally { destroyCacheSafe(ig, cc.getName()); } }
Example #7
Source File: IgniteSqlGroupConcatNotCollocatedTest.java From ignite with Apache License 2.0 | 6 votes |
/** * */ @Test public void testGroupConcatCountDistinct() { IgniteCache c = ignite(CLIENT).cache(CACHE_NAME); List<List<Object>> res = c.query( new SqlFieldsQuery("select count(distinct str0), group_concat(str0) from Value group by grp")).getAll(); for (List<Object> row : res) { long cnt = (long)row.get(0); String str = (String)row.get(1); for (int i = 0; i < cnt; ++i) { String s = "" + (char)('A' + i + (cnt - 1) * cnt / 2); assertTrue("Invalid group_concat result: string doesn't contain value: " + "[str=" + str + ", val=" + s, str.contains(s)); } } }
Example #8
Source File: IgniteKernal.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public <K, V> IgniteCache<K, V> createCache(String cacheName) { CU.validateNewCacheName(cacheName); guard(); try { checkClusterState(); ctx.cache().createFromTemplate(cacheName).get(); return ctx.cache().publicJCache(cacheName); } catch (IgniteCheckedException e) { throw CU.convertToCacheException(e); } finally { unguard(); } }
Example #9
Source File: GridCacheTransactionalAbstractMetricsSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testCommitTime() { IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME); HistogramMetricImpl m = metric("CommitTime"); assertTrue(Arrays.stream(m.value()).allMatch(v -> v == 0)); try (Transaction tx = grid(0).transactions().txStart()) { cache.put(1, 1); tx.commit(); } assertEquals(1, Arrays.stream(m.value()).filter(v -> v == 1).count()); }
Example #10
Source File: BaseSqlTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Check greater operator in where clause with both indexed and non-indexed field. */ @Test public void testWhereGreater() { testAllNodes(node -> { Result idxActual = executeFrom("SELECT firstName FROM Employee WHERE age > 30", node); Result noidxActual = executeFrom("SELECT firstName FROM Employee WHERE salary > 75", node); IgniteCache<Object, Object> cache = node.cache(EMP_CACHE_NAME); List<List<Object>> idxExp = select(cache, row -> (Integer)row.get("AGE") > 30, "firstName"); List<List<Object>> noidxExp = select(cache, row -> (Integer)row.get("SALARY") > 75, "firstName"); assertContainsEq(idxActual.values(), idxExp); assertContainsEq(noidxActual.values(), noidxExp); }); }
Example #11
Source File: RestBinaryProtocolSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testReplace() throws Exception { assertFalse(client.cacheReplace(DEFAULT_CACHE_NAME, "key1", "val1")); IgniteCache<Object, Object> jcacheDflt = grid().cache(DEFAULT_CACHE_NAME); jcacheDflt.put("key1", "val1"); assertTrue(client.cacheReplace(DEFAULT_CACHE_NAME, "key1", "val2")); assertFalse(client.cacheReplace(DEFAULT_CACHE_NAME, "key2", "val1")); jcacheDflt.put("key2", "val1"); assertTrue(client.cacheReplace(DEFAULT_CACHE_NAME, "key2", "val2")); jcacheDflt.clear(); assertFalse(client.cacheReplace(CACHE_NAME, "key1", "val1")); grid().cache(CACHE_NAME).put("key1", "val1"); assertTrue(client.cacheReplace(CACHE_NAME, "key1", "val2")); }
Example #12
Source File: GridIndexingWithNoopSwapSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** @throws Exception If failed. */ @Test public void testQuery() throws Exception { IgniteCache<Integer, ObjectValue> cache = ignite.cache(DEFAULT_CACHE_NAME); int cnt = 10; for (int i = 0; i < cnt; i++) cache.getAndPut(i, new ObjectValue("test" + i, i)); for (int i = 0; i < cnt; i++) { assertNotNull(cache.localPeek(i, ONHEAP_PEEK_MODES)); cache.localEvict(Collections.singleton(i)); // Swap. } SqlQuery<Integer, ObjectValue> qry = new SqlQuery(ObjectValue.class, "intVal >= ? order by intVal"); assertEquals(10, cache.query(qry.setArgs(0)).getAll().size()); }
Example #13
Source File: H2ConnectionLeaksSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception On failed. */ @Test public void testExplainLeak() throws Exception { startGridAndPopulateCache(NODE_CNT); final IgniteCache cache = grid(0).cache(CACHE_NAME); for (int i = 0; i < ITERS; ++i) { GridTestUtils.runMultiThreaded(() -> { cache.query(new SqlFieldsQuery("explain select * from String")).getAll(); }, 10, "explain-threads"); checkThereAreNotUsedConnections(); } }
Example #14
Source File: GridCacheAbstractMetricsSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws IgniteCheckedException If failed. */ @Test public void testInvokeAllAsyncAvgTime() throws IgniteCheckedException { IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME); assertEquals(0.0, cache.localMetrics().getEntryProcessorAverageInvocationTime(), 0.001f); Map<Integer, EntryProcessorResult<Object>> invokeFut = cache.invokeAllAsync( ImmutableMap.of(0, updatingProcessor, 1, readingProcessor, 2, removingProcessor)).get(); U.sleep(100); assertTrue(cache.localMetrics().getEntryProcessorAverageInvocationTime() > 0.0); }
Example #15
Source File: IgniteSqlKeyValueFieldsTest.java From ignite with Apache License 2.0 | 6 votes |
/** Check that joins are working on keyFieldName, valueFieldName columns */ @Test public void testJoinKeyValFields() throws Exception { IgniteEx client = grid(NODE_CLIENT); IgniteCache<Integer, Person> cache = client.cache(CACHE_PERSON); IgniteCache<Integer, Integer> cache2 = client.cache(CACHE_JOB); checkInsert(cache, "insert into Person (id, v) values (?, ?)", 1, new Person("Bob", 30)); checkInsert(cache, "insert into Person (id, v) values (?, ?)", 2, new Person("David", 35)); checkInsert(cache2, "insert into Integer (_key, _val) values (?, ?)", 100, 1); checkInsert(cache2, "insert into Integer (_key, _val) values (?, ?)", 200, 2); QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select p.id, j._key from Person p, \"" + CACHE_JOB + "\".Integer j where p.id = j._val")); List<List<?>> results = cursor.getAll(); assertEquals(2, results.size()); assertEquals(1, results.get(0).get(0)); assertEquals(100, results.get(0).get(1)); assertEquals(2, results.get(1).get(0)); assertEquals(200, results.get(1).get(1)); }
Example #16
Source File: SqlPartOfComplexPkLookupTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testPartOfComplexPkLookupDdl() throws Exception { IgniteEx ign = startGrid(0); IgniteCache<Object, Object> cache = ign.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)); cache.query(new SqlFieldsQuery("" + "CREATE TABLE Person(\n" + " id int,\n" + " city_id int,\n" + " name varchar,\n" + " PRIMARY KEY (id, city_id)\n" + ");")); cache.query(new SqlFieldsQuery("INSERT INTO Person (id, city_id, name) VALUES (1, 3, 'John Doe');")); cache.query(new SqlFieldsQuery("INSERT INTO Person (id, city_id, name) VALUES (1, 4, 'John Dean');")); checkPartialPkLookup(cache); }
Example #17
Source File: CacheManager.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void enableManagement(String cacheName, boolean enabled) { if (IgniteUtils.IGNITE_MBEANS_DISABLED) return; kernalGateway.readLock(); try { IgniteCache<?, ?> cache = getCache0(cacheName); if (cache == null) throw new CacheException("Cache not found: " + cacheName); if (enabled) registerCacheObject(cache.mxBean(), cacheName, CACHE_CONFIGURATION); else unregisterCacheObject(cacheName, CACHE_CONFIGURATION); cache.getConfiguration(CacheConfiguration.class).setManagementEnabled(enabled); } finally { kernalGateway.readUnlock(); } }
Example #18
Source File: IgniteSqlSegmentedIndexSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Run tests on single-node grid. */ @SuppressWarnings("deprecation") @Test public void testSegmentedIndexWithEvictionPolicy() { final IgniteCache<Object, Object> cache = ignite(0).createCache( cacheConfig(ORG_CACHE_NAME, true, Integer.class, Organization.class) .setEvictionPolicy(new FifoEvictionPolicy(10)) .setOnheapCacheEnabled(true)); final long SIZE = 20; for (int i = 0; i < SIZE; i++) cache.put(i, new Organization("org-" + i)); String select0 = "select name from \"org\".Organization"; List<List<?>> res = cache.query(new SqlFieldsQuery(select0)).getAll(); assertEquals(SIZE, res.size()); }
Example #19
Source File: DhtAndNearEvictionTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Checking rebalancing which used to be affected by IGNITE-9315. */ @Test public void testRebalancing() throws Exception { Ignite grid0 = startGrid(0); CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<Integer, Integer>("mycache") .setOnheapCacheEnabled(true) .setEvictionPolicyFactory(new LruEvictionPolicyFactory<>(500)) .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) .setNearConfiguration( new NearCacheConfiguration<Integer, Integer>() .setNearEvictionPolicyFactory(new LruEvictionPolicyFactory<>(100)) ); IgniteCache<Integer, Integer> cache = grid0.createCache(ccfg); for (int i = 0; i < 1000; i++) cache.put(i, i); startGrid(1); awaitPartitionMapExchange(true, true, null); assertFalse(strLog.toString().contains("AssertionError")); }
Example #20
Source File: RunningQueriesTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Check cleanup running queries on node stop. * * @throws Exception Exception in case of failure. */ @Test public void testCloseRunningQueriesOnNodeStop() throws Exception { IgniteEx ign = startGrid(super.getConfiguration("TST")); IgniteCache<Integer, Integer> cache = ign.getOrCreateCache(new CacheConfiguration<Integer, Integer>() .setName("TST") .setQueryEntities(Collections.singletonList(new QueryEntity(Integer.class, Integer.class))) ); for (int i = 0; i < 10000; i++) cache.put(i, i); cache.query(new SqlFieldsQuery("SELECT * FROM Integer order by _key")); Assert.assertEquals("Should be one running query", 1, ign.context().query().runningQueries(-1).size()); ign.close(); Assert.assertEquals(0, ign.context().query().runningQueries(-1).size()); }
Example #21
Source File: IgniteClientReconnectCacheTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testReconnectCacheDestroyed() throws Exception { final IgniteEx client = startClientGrid(SRV_CNT); assertTrue(client.cluster().localNode().isClient()); final Ignite srv = clientRouter(client); final IgniteCache<Object, Object> clientCache = client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)); reconnectClientNode(client, srv, new Runnable() { @Override public void run() { srv.destroyCache(DEFAULT_CACHE_NAME); } }); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return clientCache.get(1); } }, IllegalStateException.class, null); checkCacheDiscoveryData(srv, client, DEFAULT_CACHE_NAME, false, false, false); IgniteCache<Object, Object> clientCache0 = client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)); checkCacheDiscoveryData(srv, client, DEFAULT_CACHE_NAME, true, true, false); clientCache0.put(1, 1); assertEquals(1, clientCache0.get(1)); }
Example #22
Source File: CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} * while {@link IgniteCache#put(Object, Object)} performed. * * @throws Exception If failed. */ @Test public void testUpdate() throws Exception { IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); Random r = new Random(); for (int i = 0; i < CNT; ++i) cache.put(r.nextInt(), "test-value"); }
Example #23
Source File: CacheMvccConfigurationValidationTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @SuppressWarnings("ThrowableNotThrown") @Test public void testMvccLocalCacheDisabled() throws Exception { final Ignite node1 = startGrid(1); final Ignite node2 = startGrid(2); IgniteCache cache1 = node1.createCache(new CacheConfiguration("cache1") .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); cache1.put(1,1); cache1.put(2,2); cache1.put(2,2); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() { node1.createCache(new CacheConfiguration("cache2").setCacheMode(CacheMode.LOCAL) .setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); return null; } }, CacheException.class, null); IgniteCache cache3 = node2.createCache(new CacheConfiguration("cache3") .setAtomicityMode(TRANSACTIONAL)); cache3.put(1, 1); cache3.put(2, 2); cache3.put(3, 3); }
Example #24
Source File: GridCacheAbstractMetricsSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param emptyCache Empty cache. * @throws IgniteCheckedException If failed. */ private void testReadOnlyInvocations(final boolean emptyCache) throws IgniteCheckedException { IgniteCache<Integer, Integer> cache0 = grid(0).cache(DEFAULT_CACHE_NAME); final Integer key = primaryKey(jcache(0)); if (emptyCache) cache0.remove(key); else cache0.put(key, 0); cache0.invoke(key, readingProcessor); assertEquals(1, cache0.localMetrics().getEntryProcessorReadOnlyInvocations()); if (emptyCache) { assertEquals(1, cache0.localMetrics().getEntryProcessorMisses()); assertEquals(100f, cache0.localMetrics().getEntryProcessorMissPercentage()); assertEquals(0f, cache0.localMetrics().getEntryProcessorHitPercentage()); } else { assertEquals(1, cache0.localMetrics().getEntryProcessorHits()); assertEquals(0f, cache0.localMetrics().getEntryProcessorMissPercentage()); assertEquals(100f, cache0.localMetrics().getEntryProcessorHitPercentage()); } for (int i = 1; i < gridCount(); i++) assertEquals(0, jcache(i).localMetrics().getEntryProcessorReadOnlyInvocations()); assertEquals(1, cache0.localMetrics().getEntryProcessorInvocations()); }
Example #25
Source File: IgniteTxConfigCacheSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Success if explicit tx fails. * * @param cache Cache name. * @param ignite Ignite instance. * @throws Exception If failed. */ protected void checkExplicitTxTimeout(final IgniteCache<Object, Object> cache, final Ignite ignite) throws Exception { try (final Transaction tx = ignite.transactions().txStart()) { assert tx != null; cache.put("key0", "val0"); sleepForTxFailure(); cache.put("key", "val"); fail("Timeout exception must be thrown"); } catch (CacheException e) { assert e.getCause() instanceof TransactionTimeoutException; } assertNull(ignite.transactions().tx()); assert !cache.containsKey("key0"); assert !cache.containsKey("key"); // New transaction must succeed. try (final Transaction tx = ignite.transactions().txStart()) { cache.put("key", "val"); tx.commit(); } assert cache.containsKey("key"); }
Example #26
Source File: CacheEntryProcessorExample.java From ignite with Apache License 2.0 | 5 votes |
/** * Increments values of entries stored in the cache using {@link IgniteCache#invokeAll(Set, EntryProcessor, * Object...)} method. * * @param cache Cache instance. */ private static void incrementEntriesWithInvokeAll(IgniteCache<Integer, Integer> cache) { System.out.println(""); System.out.println(">> Incrementing values in the cache using EntryProcessor."); // Using EntryProcessor.invokeAll to increment every value in place. cache.invokeAll(KEYS_SET, (entry, object) -> { entry.setValue(entry.getValue() + 5); return null; }); // Print outs entries that are incremented using the EntryProcessor above. printCacheEntries(cache); }
Example #27
Source File: CacheContinuousQueryOperationFromCallbackTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param rcvsEvts Set for received events. * @param evtsFromCb Set for received events. * @param cache Ignite cache. * @param cntr Received events counter. * @param cbCntr Received events counter from callbacks. */ public TestCacheAsyncEventListener(Set<T2<QueryTestKey, QueryTestValue>> rcvsEvts, Set<T2<QueryTestKey, QueryTestValue>> evtsFromCb, @Nullable IgniteCache cache, AtomicInteger cntr, AtomicInteger cbCntr) { this.rcvsEvts = rcvsEvts; this.evtsFromCb = evtsFromCb; this.cache = cache; this.cntr = cntr; this.cbCntr = cbCntr; }
Example #28
Source File: DecisionTreeClassificationTrainerIntegrationTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ @Test public void testFit() { int size = 100; CacheConfiguration<Integer, double[]> trainingSetCacheCfg = new CacheConfiguration<>(); trainingSetCacheCfg.setAffinity(new RendezvousAffinityFunction(false, 10)); trainingSetCacheCfg.setName("TRAINING_SET"); IgniteCache<Integer, double[]> data = ignite.createCache(trainingSetCacheCfg); Random rnd = new Random(0); for (int i = 0; i < size; i++) { double x = rnd.nextDouble() - 0.5; data.put(i, new double[]{x, x > 0 ? 1 : 0}); } DecisionTreeClassificationTrainer trainer = new DecisionTreeClassificationTrainer(1, 0); DecisionTreeNode tree = trainer.fit(ignite, data, new DoubleArrayVectorizer<Integer>().labeled(1)); assertTrue(tree instanceof DecisionTreeConditionalNode); DecisionTreeConditionalNode node = (DecisionTreeConditionalNode) tree; assertEquals(0, node.getThreshold(), 1e-3); assertTrue(node.getThenNode() instanceof DecisionTreeLeafNode); assertTrue(node.getElseNode() instanceof DecisionTreeLeafNode); DecisionTreeLeafNode thenNode = (DecisionTreeLeafNode) node.getThenNode(); DecisionTreeLeafNode elseNode = (DecisionTreeLeafNode) node.getElseNode(); assertEquals(1, thenNode.getVal(), 1e-10); assertEquals(0, elseNode.getVal(), 1e-10); }
Example #29
Source File: CacheMvccOperationChecksTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param mtdName Method name. * @param errMsg Expected error message. * @param paramTypes Operation param types. * @param args Operation arguments. * @throws Exception if failed. */ @SuppressWarnings("ThrowableNotThrown") private void checkOperationUnsupported(String mtdName, String errMsg, Class[] paramTypes, Object... args) throws Exception { final boolean async = mtdName.endsWith("Async"); try (final Ignite node = startGrid(0)) { final CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>("cache"); cfg.setCacheMode(cacheMode()); cfg.setAtomicityMode(TRANSACTIONAL_SNAPSHOT); try (IgniteCache<Integer, String> cache = node.createCache(cfg)) { GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { try { Object o = U.invoke(null, cache, mtdName, paramTypes, args); if (async) { assertTrue(o instanceof IgniteFuture<?>); ((IgniteFuture)o).get(); } } catch (Exception e) { if (e.getCause() == null) throw e; if (e.getCause().getCause() == null) throw e; throw (Exception)e.getCause().getCause(); } return null; } }, UnsupportedOperationException.class, errMsg); } } }
Example #30
Source File: IgniteCacheAbstractQuerySelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception In case of error. */ @Test public void testComplexTypeKeepBinary() throws Exception { if (ignite().configuration().getMarshaller() == null || ignite().configuration().getMarshaller() instanceof BinaryMarshaller) { IgniteCache<Key, GridCacheQueryTestValue> cache = jcache(Key.class, GridCacheQueryTestValue.class); GridCacheQueryTestValue val1 = new GridCacheQueryTestValue(); val1.setField1("field1"); val1.setField2(1); val1.setField3(1L); GridCacheQueryTestValue val2 = new GridCacheQueryTestValue(); val2.setField1("field2"); val2.setField2(2); val2.setField3(2L); val2.setField6(null); cache.put(new Key(100500), val1); cache.put(new Key(100501), val2); QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> qry = cache.withKeepBinary() .query(new SqlQuery<BinaryObject, BinaryObject>(GridCacheQueryTestValue.class, "fieldName='field1' and field2=1 and field3=1 and id=100500 and embeddedField2=11 and x=3")); Cache.Entry<BinaryObject, BinaryObject> entry = F.first(qry.getAll()); assertNotNull(entry); assertEquals(Long.valueOf(100500L), entry.getKey().field("id")); assertEquals(val1, entry.getValue().deserialize()); } }