/** * @param e Exception to handle. * @return GridSpiException Converted exception. */ private IgniteSpiException unwrapException(IgniteCheckedException e) { // Avoid double-wrapping. if (e.getCause() instanceof IgniteSpiException) return (IgniteSpiException)e.getCause(); return new IgniteSpiException("Failed to execute SPI context method.", e); } });
/** * Converts exception, but unlike {@link #convertException(IgniteCheckedException)} * does not wrap passed in exception if none suitable converter found. * * @param e Ignite checked exception. * @return Ignite runtime exception. */ public static Exception convertExceptionNoWrap(IgniteCheckedException e) { C1<IgniteCheckedException, IgniteException> converter = exceptionConverters.get(e.getClass()); if (converter != null) return converter.apply(e); if (e.getCause() instanceof IgniteException) return (Exception)e.getCause(); return e; }
/** * @param e Ignite checked exception. * @return Ignite runtime exception. */ public static IgniteException convertException(IgniteCheckedException e) { IgniteClientDisconnectedException e0 = e.getCause(IgniteClientDisconnectedException.class); if (e0 != null) { assert e0.reconnectFuture() != null : e0; throw e0; } IgniteClientDisconnectedCheckedException disconnectedErr = e.getCause(IgniteClientDisconnectedCheckedException.class); if (disconnectedErr != null) { assert disconnectedErr.reconnectFuture() != null : disconnectedErr; e = disconnectedErr; } C1<IgniteCheckedException, IgniteException> converter = exceptionConverters.get(e.getClass()); if (converter != null) return converter.apply(e); if (e.getCause() instanceof IgniteException) return (IgniteException)e.getCause(); return new IgniteException(e.getMessage(), e); }
@Override public IgniteException apply(IgniteCheckedException e) { return new IgniteInterruptedException(e.getMessage(), (InterruptedException)e.getCause()); } });
/** * @throws Exception If failed. */ @Test public void testGetCause() throws Exception { IgniteCheckedException me = prepareMultiException(); assertNull(me.getCause(IOException.class)); assertNotNull(me.getCause(IgniteCheckedException.class)); assertTrue(me.getCause(IgniteCheckedException.class) instanceof IgniteCheckedException); assertNotNull(me.getCause(IllegalArgumentException.class)); assertTrue(me.getCause(IllegalArgumentException.class) instanceof IllegalArgumentException); }
/** {@inheritDoc} */ @Override public boolean sendMessage(@Nullable UUID nodeId, Message msg, IgniteInClosure<IgniteException> c) throws IgniteCheckedException { try { // Node ID is never provided in asynchronous send mode. assert nodeId == null; ses.sendNoFuture(msg, c); } catch (IgniteCheckedException e) { if (log.isDebugEnabled()) log.debug("Failed to send message [client=" + this + ", err=" + e + ']'); if (e.getCause() instanceof IOException) { ses.close(); return true; } else throw new IgniteCheckedException("Failed to send message [client=" + this + ']', e); } return false; }
/** * Cast Ignite exception to appropriate IO exception. * * @param e Exception to cast. * @param path Path for exceptions. * @return Casted exception. */ public static IOException cast(IgniteCheckedException e, @Nullable String path) { assert e != null; // First check for any nested IOException; if exists - re-throw it. if (e.hasCause(IOException.class)) return e.getCause(IOException.class); else if (e.hasCause(IgfsPathNotFoundException.class)) return new FileNotFoundException(path); // TODO: Or PathNotFoundException? else if (e.hasCause(IgfsParentNotDirectoryException.class)) return new ParentNotDirectoryException(path); else if (path != null && e.hasCause(IgfsDirectoryNotEmptyException.class)) return new PathIsNotEmptyDirectoryException(path); else if (path != null && e.hasCause(IgfsPathAlreadyExistsException.class)) return new PathExistsException(path); else { String msg = e.getMessage(); return msg == null ? new IOException(e) : new IOException(msg, e); } }
/** * */ @Test public void testHasCause() { ConnectException conEx = new ConnectException(); IOException ioEx = new IOException(conEx); IgniteCheckedException gridEx = new IgniteCheckedException(ioEx); assert X.hasCause(gridEx, IOException.class, NumberFormatException.class); assert !X.hasCause(gridEx, NumberFormatException.class); assert X.cause(gridEx, IOException.class) == ioEx; assert X.cause(gridEx, ConnectException.class) == conEx; assert X.cause(gridEx, NumberFormatException.class) == null; assert gridEx.getCause(IOException.class) == ioEx; assert gridEx.getCause(ConnectException.class) == conEx; assert gridEx.getCause(NumberFormatException.class) == null; }
/** * Test informative exception message while failed object marshalling * * @throws Exception If failed. */ @Test public void testFailedMarshallingLogging() throws Exception { OptimizedMarshaller marsh = new OptimizedMarshaller(true); marsh.setContext(CTX); try { marsh.marshal(new BadSerializableObject()); } catch (IgniteCheckedException ex) { assertTrue(ex.getCause().getMessage().contains( "object [typeName=org.apache.ignite.internal.marshaller.optimized.OptimizedObjectStreamSelfTest$BadSerializableObject]")); assertTrue(ex.getCause().getCause().getMessage().contains("field [name=val")); } }
/** * Tries to start ignite node with invalid configuration and checks that corresponding exception is thrown. * * @param violationType Configuration violation type. */ private void doTest(ValidationViolationType violationType) throws Exception { try { startGrid(0); } catch (IgniteCheckedException e) { Throwable c = e.getCause(); assertTrue(c != null); assertTrue(c.getMessage().contains(violationType.violationMsg)); return; } fail("Expected exception hasn't been thrown"); }
/** * Test informative exception message while failed object unmarshalling * * @throws Exception If failed. */ @Test public void testFailedUnmarshallingLogging() throws Exception { OptimizedMarshaller marsh = new OptimizedMarshaller(true); marsh.setContext(CTX); try { marsh.unmarshal(marsh.marshal(new BadDeserializableObject()), null); } catch (IgniteCheckedException ex) { assertTrue(ex.getCause().getMessage().contains( "object [typeName=org.apache.ignite.internal.marshaller.optimized.OptimizedObjectStreamSelfTest$BadDeserializableObject]")); assertTrue(ex.getCause().getCause().getMessage().contains("field [name=val")); } }
/** * @throws Exception If failed. */ @Test public void testMarshallerInConsistency() throws Exception { startGrid(0); try { startGrid(1); fail("Expected SPI exception was not thrown."); } catch (IgniteCheckedException e) { Throwable ex = e.getCause().getCause(); assertTrue(ex instanceof IgniteSpiException); assertTrue(ex.getMessage().contains("Local node's marshaller differs from remote node's marshaller")); } }
/** * @throws Exception If failed. */ @Test public void testDifferentDeploymentModes() throws Exception { IgniteEx g = startGrid(0); checkIsClientFlag(g); mode = CONTINUOUS; try { startGrid(1); fail(); } catch (IgniteCheckedException e) { if (!e.getCause().getMessage().startsWith("Remote node has deployment mode different from")) throw e; } }
/** * @throws Exception If failed. */ @Test public void testDifferentPeerClassLoadingEnabledFlag() throws Exception { IgniteEx g = startGrid(0); checkIsClientFlag(g); p2pEnabled = true; try { startGrid(1); fail(); } catch (IgniteCheckedException e) { if (!e.getCause().getMessage().startsWith("Remote node has peer class loading enabled flag different from")) throw e; } }
/** * @throws Exception If failed. */ @Test public void testRequireSerializable() throws Exception { try { OptimizedMarshaller marsh = new OptimizedMarshaller(true); marsh.setContext(CTX); marsh.marshal(new Object()); assert false : "Exception not thrown."; } catch (IgniteCheckedException e) { NotSerializableException serEx = e.getCause(NotSerializableException.class); if (serEx == null) throw e; } }
/** * @throws Exception If failed. */ @Test public void testMarshallerInConsistency() throws Exception { sameMarsh = false; startGrid(1); try { startGrid(2); fail("Expected SPI exception was not thrown."); } catch (IgniteCheckedException e) { Throwable ex = e.getCause().getCause(); assertTrue(ex instanceof IgniteSpiException); assertTrue(ex.getMessage().contains("Local node's marshaller differs from remote node's marshaller")); } }
/** * @throws Exception If failed. */ @Test public void testJoinTimeout() throws Exception { clientIpFinder = new TcpDiscoveryVmIpFinder(); joinTimeout = 1000; try { startClientNodes(1); fail("Client cannot be start because no server nodes run"); } catch (IgniteCheckedException e) { IgniteSpiException spiEx = e.getCause(IgniteSpiException.class); assert spiEx != null : e; assert spiEx.getMessage().contains("Join process timed out") : spiEx.getMessage(); } }
/** * @throws Exception If any error occurs. */ @Test public void testDuplicateId() throws Exception { startServerNodes(2); nodeId = G.ignite("server-1").cluster().localNode().id(); try { startGrid("client-0"); assert false; } catch (IgniteCheckedException e) { IgniteSpiException spiEx = e.getCause(IgniteSpiException.class); assert spiEx != null : e; assert spiEx.getMessage().contains("same ID") : spiEx.getMessage(); } }
/** * Verifies scenario that node with corrupted marshaller mapping store must fail on startup * with appropriate error message. * * @see <a href="https://issues.apache.org/jira/browse/IGNITE-6536">IGNITE-6536</a> JIRA provides more information * about this case. */ @Test public void testNodeStartFailsOnCorruptedStorage() throws Exception { isPersistenceEnabled = true; Ignite ig = startGrids(3); ig.active(true); ig.cache(DEFAULT_CACHE_NAME).put(0, new SimpleValue(0, "value0")); stopAllGrids(); corruptMarshallerStorage(); try { startGrid(0); } catch (IgniteCheckedException e) { verifyException((IgniteCheckedException) e.getCause()); } }