/** * @param e Exception to check. * @return {@code true} if specified exception is {@link GridClientAuthenticationException}. */ private boolean isAuthError(Throwable e) { return X.hasCause(e, GridClientAuthenticationException.class); }
/** * @param errs Error. * @return {@code True} if error was caused by some connection IO error. */ private static boolean connectionError(IgniteCheckedException errs) { return X.hasCause(errs, ConnectException.class, HandshakeException.class, SocketTimeoutException.class, HandshakeTimeoutException.class, IgniteSpiOperationTimeoutException.class); }
/** * Checks if this exception has given class in {@code 'cause'} hierarchy. * * @param cls Cause class to check (if {@code null}, {@code false} is returned).. * @return {@code True} if one of the causing exception is an instance of passed in class, * {@code false} otherwise. */ public boolean hasCause(@Nullable Class<? extends Throwable>... cls) { return X.hasCause(this, cls); }
/** * Checks if this exception has given class in {@code 'cause'} hierarchy. * * @param cls Cause classes to check (if {@code null} or empty, {@code false} is returned). * @return {@code True} if one of the causing exception is an instance of passed in classes, * {@code false} otherwise. */ @SafeVarargs public final boolean hasCause(@Nullable Class<? extends Throwable>... cls) { return X.hasCause(this, cls); }
/** * Checks if this exception has given class in {@code 'cause'} hierarchy. * * @param cls Cause classes to check (if {@code null} or empty, {@code false} is returned). * @return {@code True} if one of the causing exception is an instance of passed in classes, * {@code false} otherwise. */ @SafeVarargs public final boolean hasCause(@Nullable Class<? extends Throwable>... cls) { return X.hasCause(this, cls); }
/** * Checks if passed in {@code 'Throwable'} has given class in {@code 'cause'} hierarchy <b>including</b> that * throwable itself. <p> Note that this method follows includes {@link Throwable#getSuppressed()} into check. * * @param t Throwable to check (if {@code null}, {@code false} is returned). * @param cls Cause classes to check (if {@code null} or empty, {@code false} is returned). * @return {@code True} if one of the causing exception is an instance of passed in classes, {@code false} * otherwise. */ public static boolean hasCause(@Nullable Throwable t, @Nullable Class<?>... cls) { return hasCause(t, null, cls); }
@Override public Throwable apply(Throwable e) { if (e instanceof IgniteException || e instanceof IgniteCheckedException || X.hasCause(e, ClusterTopologyCheckedException.class)) { info("Discarding exception: " + e); return null; } else return e; } };
/** * Checks whether the given {@link Exception} is generated because failure detection timeout has been reached. * * @param e Exception. * @return {@code true} if failure detection timeout is reached, {@code false} otherwise. */ public boolean checkFailureTimeoutReached(Exception e) { if (!failureDetectionTimeoutEnabled) return false; if (X.hasCause(e, IgniteSpiOperationTimeoutException.class, SocketTimeoutException.class, SocketException.class)) return true; return (timeout - (U.currentTimeMillis() - lastOperStartTs) <= 0); } }
/** * */ private boolean expectedThrowableClass(Throwable throwable) { return X.hasCause( throwable, IgniteClientDisconnectedException.class, CacheInvalidStateException.class, ClusterTopologyCheckedException.class, IllegalStateException.class, NodeStoppingException.class ); } }
/** * @param e Exception. * @return {@code True} if local node should try reconnect in case of error. */ public boolean reconnectOnError(Throwable e) { return (e instanceof IgniteNeedReconnectException || X.hasCause(e, IOException.class, IgniteClientDisconnectedCheckedException.class)) && cctx.discovery().reconnectSupported(); }
@Override public void apply(IgniteInternalFuture<?> txFut) { try { txFut.get(); } catch (IgniteCheckedException e) { tx0.setRollbackOnly(); // Just in case. if (!X.hasCause(e, IgniteTxOptimisticCheckedException.class) && !X.hasCause(e, IgniteFutureCancelledException.class) && !ctx.kernalContext().isStopping()) U.error(log, "Failed to prepare DHT transaction: " + tx0, e); } } });
/** {@inheritDoc} */ @Override public void uncaughtException(Thread t, Throwable e) { if (X.hasCause(e, OutOfMemoryError.class)) ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e)); } }
/** * @param cache Cache. * @param cnt Entry count. * @throws IgniteCheckedException If failed. */ private void remove(IgniteCache<String, Integer> cache, int cnt) throws Exception { try { for (int i = 0; i < cnt; i++) cache.remove("key" + i); } catch (CacheException e) { if (!X.hasCause(e, ClusterTopologyCheckedException.class) && !(e instanceof CachePartialUpdateException)) throw e; } }
@Override public void uncaughtException(Thread t, Throwable e) { if (grid != null && X.hasCause(e, OutOfMemoryError.class)) grid.context().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e)); } };
/** * Sends get atomically and handles fail. * * @param k Key. */ protected void failGet(int k) { try { jcache(0).get(new TestKey(String.valueOf(k))); assert false : "p2p marshalling failed, but error response was not sent"; } catch (CacheException e) { assert X.hasCause(e, IOException.class); } }
/** * @throws Exception If failed. */ @Test public void testServerNotAuthenticatedByClient() throws Exception { try { checkServerAuthenticatedByClient(true); } catch (GridClientDisconnectedException e) { assertTrue(X.hasCause(e, GridServerUnreachableException.class)); } }
/** * @throws Exception If failed. */ @Test public void testClientNotAuthenticated() throws Exception { try { checkServerAuthenticatedByClient(true); } catch (GridClientDisconnectedException e) { assertTrue(X.hasCause(e, GridServerUnreachableException.class)); } }
/** * Sends get atomically and handles fail. * * @param k Key. */ protected void failGetAll(int k) { try { Set<Object> keys = F.<Object>asSet(new TestKey(String.valueOf(k))); jcache(0).getAll(keys); assert false : "p2p marshalling failed, but error response was not sent"; } catch (CacheException e) { assert X.hasCause(e, IOException.class); } }
/** * Sends put with pessimistic lock and handles fail. */ private void failPessimictic() { IgniteCache<Object, Object> cache = jcache(0); try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.put(new TestKey(String.valueOf(++key)), ""); assert false : "p2p marshalling failed, but error response was not sent"; } catch (CacheException e) { assert X.hasCause(e, IOException.class); } assert readCnt.get() == 0; // Ensure we have read count as expected. }
/** Tests that node join fails due failure in node validation. */ @Test public void testValidationException() throws Exception { token = "123456"; startGrid(0); token = "abcdef"; try { startGrid(1); } catch (Exception ex) { assertTrue("Wrong exception type for validation error", X.hasCause(ex, IgniteSpiException.class)); return; } fail("Exception is expected due validation error in plugin"); }