} else { data = Arrays.copyOfRange(data, ProtobufUtil.lengthOfPBMagic(), data.length); ee = ForeignException.deserialize(data);
ee = ForeignException.deserialize(data);
/** * Verify that we get back similar stack trace information before an after serialization. */ @Test public void testSimpleException() throws IOException { String data = "some bytes"; ForeignException in = new ForeignException("SRC", new IllegalArgumentException(data)); // check that we get the data back out ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, in)); assertNotNull(e); // now check that we get the right stack trace StackTraceElement elem = new StackTraceElement(this.getClass().toString(), "method", "file", 1); in.setStackTrace(new StackTraceElement[] { elem }); e = ForeignException.deserialize(ForeignException.serialize(srcName, in)); assertNotNull(e); assertEquals("Stack trace got corrupted", elem, e.getCause().getStackTrace()[0]); assertEquals("Got an unexpectedly long stack trace", 1, e.getCause().getStackTrace().length); }
/** * Compare that a generic exception's stack trace has the same stack trace elements after * serialization and deserialization */ @Test public void testRemoteFromLocal() throws IOException { String errorMsg = "some message"; Exception generic = new Exception(errorMsg); generic.printStackTrace(); assertTrue(generic.getMessage().contains(errorMsg)); ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, generic)); assertArrayEquals("Local stack trace got corrupted", generic.getStackTrace(), e.getCause().getStackTrace()); e.printStackTrace(); // should have ForeignException and source node in it. assertTrue(e.getCause().getCause() == null); // verify that original error message is present in Foreign exception message assertTrue(e.getCause().getMessage().contains(errorMsg)); }
} else { data = Arrays.copyOfRange(data, ProtobufUtil.lengthOfPBMagic(), data.length); ee = ForeignException.deserialize(data);
/** * Receive a notification and propagate it to the local coordinator * @param abortNode full znode path to the failed procedure information */ protected void abort(String abortNode) { String procName = ZKUtil.getNodeName(abortNode); ForeignException ee = null; try { byte[] data = ZKUtil.getData(zkProc.getWatcher(), abortNode); if (!ProtobufUtil.isPBMagicPrefix(data)) { LOG.warn("Got an error notification for op:" + abortNode + " but we can't read the information. Killing the procedure."); // we got a remote exception, but we can't describe it ee = new ForeignException(coordName, "Data in abort node is illegally formatted. ignoring content."); } else { data = Arrays.copyOfRange(data, ProtobufUtil.lengthOfPBMagic(), data.length); ee = ForeignException.deserialize(data); } } catch (InvalidProtocolBufferException e) { LOG.warn("Got an error notification for op:" + abortNode + " but we can't read the information. Killing the procedure."); // we got a remote exception, but we can't describe it ee = new ForeignException(coordName, e); } catch (KeeperException e) { coordinator.rpcConnectionFailure("Failed to get data for abort node:" + abortNode + zkProc.getAbortZnode(), new IOException(e)); } coordinator.abortProcedure(procName, ee); }
/** * Verify that we get back similar stack trace information before an after serialization. */ @Test public void testSimpleException() throws IOException { String data = "some bytes"; ForeignException in = new ForeignException("SRC", new IllegalArgumentException(data)); // check that we get the data back out ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, in)); assertNotNull(e); // now check that we get the right stack trace StackTraceElement elem = new StackTraceElement(this.getClass().toString(), "method", "file", 1); in.setStackTrace(new StackTraceElement[] { elem }); e = ForeignException.deserialize(ForeignException.serialize(srcName, in)); assertNotNull(e); assertEquals("Stack trace got corrupted", elem, e.getCause().getStackTrace()[0]); assertEquals("Got an unexpectedly long stack trace", 1, e.getCause().getStackTrace().length); }
/** * Compare that a generic exception's stack trace has the same stack trace elements after * serialization and deserialization */ @Test public void testRemoteFromLocal() throws IOException { String errorMsg = "some message"; Exception generic = new Exception(errorMsg); generic.printStackTrace(); assertTrue(generic.getMessage().contains(errorMsg)); ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, generic)); assertArrayEquals("Local stack trace got corrupted", generic.getStackTrace(), e.getCause().getStackTrace()); e.printStackTrace(); // should have ForeignException and source node in it. assertTrue(e.getCause().getCause() == null); // verify that original error message is present in Foreign exception message assertTrue(e.getCause().getMessage().contains(errorMsg)); }
ee = ForeignException.deserialize(data);
} else { data = Arrays.copyOfRange(data, ProtobufUtil.lengthOfPBMagic(), data.length); ee = ForeignException.deserialize(data);