Beispiel #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestSerializedExceptionDeSer()
        {
            // without cause
            YarnException       yarnEx    = new YarnException("Yarn_Exception");
            SerializedException serEx     = SerializedException.NewInstance(yarnEx);
            Exception           throwable = serEx.DeSerialize();

            NUnit.Framework.Assert.AreEqual(yarnEx.GetType(), throwable.GetType());
            NUnit.Framework.Assert.AreEqual(yarnEx.Message, throwable.Message);
            // with cause
            IOException      ioe = new IOException("Test_IOException");
            RuntimeException runtimeException = new RuntimeException("Test_RuntimeException",
                                                                     ioe);
            YarnException       yarnEx2    = new YarnException("Test_YarnException", runtimeException);
            SerializedException serEx2     = SerializedException.NewInstance(yarnEx2);
            Exception           throwable2 = serEx2.DeSerialize();

            Sharpen.Runtime.PrintStackTrace(throwable2);
            NUnit.Framework.Assert.AreEqual(yarnEx2.GetType(), throwable2.GetType());
            NUnit.Framework.Assert.AreEqual(yarnEx2.Message, throwable2.Message);
            NUnit.Framework.Assert.AreEqual(runtimeException.GetType(), throwable2.InnerException
                                            .GetType());
            NUnit.Framework.Assert.AreEqual(runtimeException.Message, throwable2.InnerException
                                            .Message);
            NUnit.Framework.Assert.AreEqual(ioe.GetType(), throwable2.InnerException.InnerException
                                            .GetType());
            NUnit.Framework.Assert.AreEqual(ioe.Message, throwable2.InnerException.InnerException
                                            .Message);
        }
Beispiel #2
0
        public override Exception DeSerialize()
        {
            SerializedException cause = GetCause();

            YarnProtos.SerializedExceptionProtoOrBuilder p = viaProto ? proto : builder;
            Type realClass = null;

            try
            {
                realClass = Sharpen.Runtime.GetType(p.GetClassName());
            }
            catch (TypeLoadException e)
            {
                throw new YarnRuntimeException(e);
            }
            Type classType = null;

            if (typeof(YarnException).IsAssignableFrom(realClass))
            {
                classType = typeof(YarnException);
            }
            else
            {
                if (typeof(IOException).IsAssignableFrom(realClass))
                {
                    classType = typeof(IOException);
                }
                else
                {
                    if (typeof(RuntimeException).IsAssignableFrom(realClass))
                    {
                        classType = typeof(RuntimeException);
                    }
                    else
                    {
                        classType = typeof(Exception);
                    }
                }
            }
            return(InstantiateException(realClass.AsSubclass(classType), GetMessage(), cause
                                        == null ? null : cause.DeSerialize()));
        }