javax.cache.CacheException Java Examples
The following examples show how to use
javax.cache.CacheException.
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: DataStreamerImplSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Test logging on {@code DataStreamer.addData()} method when cache have no data nodes * * @throws Exception If fail. */ @Test public void testNoDataNodesOnClose() throws Exception { boolean failed = false; cnt = 0; noNodesFilter = true; try { Ignite ignite = startGrid(1); try (IgniteDataStreamer<Integer, String> streamer = ignite.dataStreamer(DEFAULT_CACHE_NAME)) { streamer.addData(1, "1"); } catch (CacheException ignored) { failed = true; } } finally { noNodesFilter = false; assertTrue(failed); } }
Example #2
Source File: GridQueryProcessor.java From ignite with Apache License 2.0 | 6 votes |
/** * Execute query setting busy lock, preserving current cache context and properly handling checked exceptions. * * @param cctx Cache context. * @param supplier Code to be executed. * @return Result. */ private <T> T executeQuerySafe(@Nullable final GridCacheContext<?, ?> cctx, SupplierX<T> supplier) { GridCacheContext oldCctx = curCache.get(); curCache.set(cctx); if (!busyLock.enterBusy()) throw new IllegalStateException("Failed to execute query (grid is stopping)."); try { return supplier.get(); } catch (IgniteCheckedException e) { throw new CacheException(e); } finally { curCache.set(oldCctx); busyLock.leaveBusy(); } }
Example #3
Source File: IgniteAbstractDynamicCacheStartFailTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Tests that a cache with the same name can be started after failure if cache configuration is corrected. * * @throws Exception If test failed. */ @Test public void testCacheStartAfterFailure() throws Exception { CacheConfiguration cfg = createCacheConfigsWithBrokenAffinityFun( false, 1, 0, 1, false).get(0); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { grid(0).getOrCreateCache(cfg); return null; } }, CacheException.class, null); // Correct the cache configuration. Default constructor creates a good affinity function. cfg.setAffinity(new BrokenAffinityFunction()); checkCacheOperations(grid(0).getOrCreateCache(cfg)); }
Example #4
Source File: CacheManagerTest.java From cache2k with Apache License 2.0 | 6 votes |
@Test public void createCacheSameName() { CacheManager cacheManager = getCacheManager(); String name1 = "c1"; cacheManager.createCache(name1, new MutableConfiguration()); Cache cache1 = cacheManager.getCache(name1); assertEquals(cache1, cacheManager.getCache(name1)); ensureOpen(cache1); try { cacheManager.createCache(name1, new MutableConfiguration()); } catch (CacheException e) { //expected } Cache cache2 = cacheManager.getCache(name1); }
Example #5
Source File: CacheMvccConfigurationValidationTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @SuppressWarnings("ThrowableNotThrown") @Test public void testMvccModeMismatchForGroup2() throws Exception { final Ignite node = startGrid(0); node.createCache( new CacheConfiguration("cache1").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() { node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(ATOMIC)); return null; } }, CacheException.class, null); node.createCache( new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL_SNAPSHOT)); }
Example #6
Source File: DataStreamerImplSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testCloseWithCancellation() throws Exception { cnt = 0; startGrids(2); Ignite g1 = grid(1); List<IgniteFuture> futures = new ArrayList<>(); IgniteDataStreamer<Object, Object> dataLdr = g1.dataStreamer(DEFAULT_CACHE_NAME); for (int i = 0; i < 100; i++) futures.add(dataLdr.addData(i, i)); try { dataLdr.close(true); } catch (CacheException e) { // No-op. } for (IgniteFuture fut : futures) assertTrue(fut.isDone()); }
Example #7
Source File: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ private void doTxPutAll(Map<Integer, Person> values) throws Exception { executeWithAllTxCaches(new TestClosure() { @Override public void run() throws Exception { GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) { cache.putAll(values); tx.commit(); } assertEquals(0, cache.size()); return null; } }, CacheException.class, ERR_MSG); } }); }
Example #8
Source File: CacheAbstractJdbcStore.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cacheName Cache name. * @param typeId Type id. * @return Entry mapping. * @throws CacheException If mapping for key was not found. */ private EntryMapping entryMapping(String cacheName, Object typeId) throws CacheException { Map<Object, EntryMapping> mappings = getOrCreateCacheMappings(cacheName); EntryMapping em = mappings.get(typeId); if (em == null) { String maskedCacheName = U.maskName(cacheName); throw new CacheException("Failed to find mapping description [cache=" + maskedCacheName + ", typeId=" + typeId + "]. Please configure JdbcType to associate cache '" + maskedCacheName + "' with JdbcPojoStore."); } return em; }
Example #9
Source File: AccessTimeObjectHolder.java From triava with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public V peek() { int serializationMode = flags & SERIALIZATION_MASK; try { switch (serializationMode) { case SERIALIZATION_NONE: return (V)data; case SERIALIZATION_SERIALIZABLE: Object dataRef = data; // defensive copy return dataRef != null ? (V)Serializing.fromBytearray((byte[])(dataRef)) : null; case SERIALIZATION_EXTERNALIZABLE: default: throw new UnsupportedOperationException("Serialization type is not supported: " + serializationMode); } } catch (Exception exc) { throw new CacheException("Cannot serialize cache value for serialization type " + serializationMode, exc); } }
Example #10
Source File: IgniteCacheInsertSqlQuerySelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * */ @Test public void testDuplicateKeysException() { final IgniteCache<Integer, Integer> p = ignite(0).cache("I2I"); p.clear(); p.put(3, 5); GridTestUtils.assertThrows(log, new Callable<Void>() { /** {@inheritDoc} */ @Override public Void call() throws Exception { p.query(new SqlFieldsQuery("insert into Integer(_key, _val) values (1, ?), " + "(?, 4), (5, 6)").setArgs(2, 3)); return null; } }, CacheException.class, "Failed to INSERT some keys because they are already in cache [keys=[3]]"); assertEquals(2, (int)p.get(1)); assertEquals(5, (int)p.get(3)); assertEquals(6, (int)p.get(5)); }
Example #11
Source File: DataStreamerTimeoutTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Test timeout on {@code DataStreamer.addData()} method * @throws Exception If fail. */ @Test public void testTimeoutOnCloseMethod() throws Exception { failOn = 1; Ignite ignite = startGrid(1); boolean thrown = false; try (IgniteDataStreamer ldr = ignite.dataStreamer(CACHE_NAME)) { ldr.timeout(TIMEOUT); ldr.receiver(new TestDataReceiver()); ldr.perNodeBufferSize(ENTRY_AMOUNT); for (int i = 0; i < ENTRY_AMOUNT; i++) ldr.addData(i, i); } catch (CacheException | IgniteDataStreamerTimeoutException ignored) { thrown = true; } finally { stopAllGrids(); } assertTrue(thrown); }
Example #12
Source File: CacheMvccSqlConfigurationValidationTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testTxDifferentMvccSettingsTransactional() throws Exception { ccfg = defaultCacheConfiguration().setSqlSchema("PUBLIC"); Ignite node = startGrid(); IgniteCache cache = node.cache(DEFAULT_CACHE_NAME); cache.query(new SqlFieldsQuery("CREATE TABLE Person (id int primary key, name varchar) WITH " + "\"atomicity=transactional_snapshot,template=partitioned,backups=1\"")).getAll(); cache.query(new SqlFieldsQuery("CREATE TABLE City (id int primary key, name varchar, population int) WITH " + "\"atomicity=transactional,template=partitioned,backups=3\"")).getAll(); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { try (Transaction tx = node.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) { cache.query(new SqlFieldsQuery("SELECT * FROM Person, City")).getAll(); tx.commit(); } return null; } }, CacheException.class, "Caches with transactional_snapshot atomicity mode cannot participate in the same transaction"); }
Example #13
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public long sizeLong(int part, CachePeekMode... peekModes) throws CacheException { IgniteInternalCache<K, V> delegate = getDelegateSafe(); try { if (isAsync()) { setFuture(delegate.sizeLongAsync(part, peekModes)); return 0; } else return delegate.sizeLong(part, peekModes); } catch (IgniteCheckedException | IgniteException e) { throw cacheException(e); } }
Example #14
Source File: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testTxPutUpdate() throws Exception { executeWithAllTxCaches(new TestClosure() { @Override public void run() throws Exception { GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) { cache.put(key1, okValue); cache.put(key2, okValue); cache.put(key2, badValue); tx.commit(); } assertEquals(0, cache.size()); return null; } }, CacheException.class, ERR_MSG); } }); }
Example #15
Source File: IgniteCacheAbstractQuerySelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testLocalSqlQueryFromClient() throws Exception { try (Ignite g = startClientGrid("client")) { IgniteCache<Integer, Integer> c = jcache(g, Integer.class, Integer.class); for (int i = 0; i < 10; i++) c.put(i, i); SqlQuery<Integer, Integer> qry = new SqlQuery<>(Integer.class, "_key >= 5 order by _key"); qry.setLocal(true); assertThrowsWithCause(() -> c.query(qry), CacheException.class); } }
Example #16
Source File: GridReduceQueryExecutor.java From ignite with Apache License 2.0 | 6 votes |
/** * Check if query is cancelled. * * @param cancel Query cancel object. * @throws CacheException If query was cancelled. */ private void ensureQueryNotCancelled(GridQueryCancel cancel) { if (Thread.currentThread().isInterrupted()) throw new CacheException(new IgniteInterruptedCheckedException("Query was interrupted.")); try { cancel.checkCancelled(); } catch (QueryCancelledException cancelEx) { throw new CacheException("Failed to run reduce query locally. " + cancelEx.getMessage(), cancelEx); } if (ctx.clientDisconnected()) { throw new CacheException("Query was cancelled, client node disconnected.", new IgniteClientDisconnectedException(ctx.cluster().clientReconnectFuture(), "Client node disconnected.")); } }
Example #17
Source File: ConcurrentCreateICacheTest.java From hazelcast-simulator with Apache License 2.0 | 6 votes |
@Setup public void setup() { counterList = targetInstance.getList(name); CacheConfig config = new CacheConfig(); config.setName(name); Counter counter = new Counter(); try { CacheManager cacheManager = createCacheManager(targetInstance); cacheManager.createCache(name, config); counter.create++; } catch (CacheException e) { logger.fatal(name + ": createCache exception " + e, e); counter.createException++; } counterList.add(counter); }
Example #18
Source File: TCacheMBean.java From triava with Apache License 2.0 | 6 votes |
public void register(Cache<?,?> cache) { TCacheJSR107<?, ?> jsr107cache = cache.jsr107cache(); // these can change during runtime, so always look it up ObjectName registeredObjectName = calculateObjectName(jsr107cache, objectNameType()); if (isRegistered(registeredObjectName)) { // Do not register twice. Actually this contains a race condition due to a // check-then-act "isRegistered() => registerMBean()" action, but it should not be // a problem for us, because there are never two caches with the same name alive at the // same time. return; } try { mBeanServer.registerMBean(getMBean(jsr107cache), registeredObjectName); } catch (Exception e) { throw new CacheException("Error registering cache MXBeans for CacheManager " + registeredObjectName + " . Error was " + e.getMessage(), e); } }
Example #19
Source File: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Test public void testTxReplace() throws Exception { executeWithAllTxCaches(new TestClosure() { @Override public void run() throws Exception { GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { cache.put(1, okValue); try (Transaction tx = ignite.transactions().txStart(concurrency, isolation)) { cache.replace(key1, badValue); tx.commit(); } assertEquals(1, cache.size()); assertEquals(okValue, cache.get(key1)); return null; } }, CacheException.class, ERR_MSG); } }); }
Example #20
Source File: MangleICacheTest.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@TimeStep(prob = 0.2) public void destroyCache(ThreadState state) { try { int cacheNumber = state.randomInt(maxCaches); state.cacheManager.destroyCache(name + cacheNumber); state.counter.destroy++; } catch (CacheException | IllegalStateException e) { state.counter.destroyException++; } }
Example #21
Source File: JCSCache.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public void clear() { assertNotClosed(); try { delegate.removeAll(); } catch (final IOException e) { throw new CacheException(e); } }
Example #22
Source File: CacheAsyncOperationsTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param cache Cache. */ private void async1(IgniteCache<Integer, Integer> cache) { cache.put(1, 1); latch = new CountDownLatch(1); IgniteFuture<?> fut1 = cache.putAsync(0, 0); IgniteFuture<?> fut2 = cache.getAndPutAsync(1, 2); IgniteFuture<?> fut3 = cache.getAndPutAsync(1, 3); assertFalse(fut1.isDone()); assertFalse(fut2.isDone()); assertFalse(fut3.isDone()); latch.countDown(); try { fut1.get(); fail(); } catch (CacheException e) { log.info("Expected error: " + e); } assertEquals(1, fut2.get()); assertEquals(2, fut3.get()); assertNull(cache.get(0)); assertEquals((Integer)3, cache.get(1)); }
Example #23
Source File: GridCacheAtomicFullApiSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testLock() throws Exception { GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return jcache().lock("1").tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS); } }, CacheException.class, "Locks are not supported"); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { return jcache().lockAll(Collections.singleton("1")).tryLock(Long.MAX_VALUE, TimeUnit.MILLISECONDS); } }, CacheException.class, "Locks are not supported"); }
Example #24
Source File: GatewayProtectedCacheProxy.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public IgniteFuture<V> getAndPutIfAbsentAsync(K key, V val) throws CacheException, TransactionException { CacheOperationGate opGate = onEnter(); try { return delegate.getAndPutIfAbsentAsync(key, val); } finally { onLeave(opGate); } }
Example #25
Source File: GridReduceQueryExecutor.java From ignite with Apache License 2.0 | 5 votes |
/** * @param reconnectFut Reconnect future. */ public void onDisconnected(IgniteFuture<?> reconnectFut) { CacheException err = new CacheException("Query was cancelled, client node disconnected.", new IgniteClientDisconnectedException(reconnectFut, "Client node disconnected.")); for (Map.Entry<Long, ReduceQueryRun> e : runs.entrySet()) e.getValue().disconnected(err); for (DmlDistributedUpdateRun r: updRuns.values()) r.handleDisconnect(err); }
Example #26
Source File: QueryEntityTypeDescriptor.java From ignite with Apache License 2.0 | 5 votes |
/** * Adds property to the type descriptor. * * @param prop Property. * @param key Property ownership flag (key or not). * @param failOnDuplicate Fail on duplicate flag. */ public void addProperty(QueryEntityClassProperty prop, boolean key, boolean failOnDuplicate) { if (props.put(prop.name(), prop) != null && failOnDuplicate) { throw new CacheException("Property with name '" + prop.name() + "' already exists for " + (key ? "key" : "value") + ": " + "QueryEntity [key=" + keyCls.getName() + ", value=" + valCls.getName() + ']'); } fields.put(prop.fullName(), prop.type()); if (key) keyProps.add(prop.fullName()); }
Example #27
Source File: JCache.java From redisson with Apache License 2.0 | 5 votes |
<T, R> R evalRead(String key, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, Object... params) { RFuture<R> future = commandExecutor.evalReadAsync(key, codec, evalCommandType, script, keys, params); try { return get(future); } catch (Exception e) { throw new CacheException(e); } }
Example #28
Source File: KillQueryTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Check if query hangs (due to reducer spins retrying to reserve partitions but they can't be reserved), we still * able to cancel it. Used mocked indexing simulates 100% unability. */ @Test public void testCancelQueryIfPartitionsCantBeReservedOnMapNodes() throws Exception { // Releases thread that kills query when map nodes receive query request. At least one map node received is ok. GridMessageListener qryStarted = (node, msg, plc) -> { if (msg instanceof GridH2QueryRequest) TestSQLFunctions.cancelLatch.countDown(); }; for (int i = 0; i < NODES_COUNT; i++) grid(i).context().io().addMessageListener(GridTopic.TOPIC_QUERY, qryStarted); // Suspends distributed queries on the map nodes. MockedIndexing.failReservations = true; try { IgniteInternalFuture cancelFut = cancel(1, asyncCancel); GridTestUtils.assertThrows(log, () -> { ignite.cache(DEFAULT_CACHE_NAME).query( new SqlFieldsQuery("select * from Integer where _val <> 42") ).getAll(); return null; }, CacheException.class, "The query was cancelled while executing."); cancelFut.get(CHECK_RESULT_TIMEOUT); } finally { for (int i = 0; i < NODES_COUNT; i++) grid(i).context().io().removeMessageListener(GridTopic.TOPIC_QUERY, qryStarted); } }
Example #29
Source File: DataStreamerImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void flush() throws CacheException { lock(true); try { doFlush(); } catch (IgniteCheckedException e) { throw CU.convertToCacheException(e); } finally { unlock(true); } }
Example #30
Source File: CacheAbstractJdbcStore.java From ignite with Apache License 2.0 | 5 votes |
/** * @param stmt Prepare statement. * @param idx Start index for parameters. * @param em Entry mapping. * @param key Key object. * @return Next index for parameters. * @throws CacheException If failed to set statement parameters. */ protected int fillKeyParameters(PreparedStatement stmt, int idx, EntryMapping em, Object key) throws CacheException { for (JdbcTypeField field : em.keyColumns()) { Object fieldVal = extractParameter(em.cacheName, em.keyType(), em.keyKind(), field.getJavaFieldName(), key); fillParameter(stmt, idx++, field, fieldVal); } return idx; }