Repository: incubator-reef Updated Branches: refs/heads/master aea64d9fc -> 1f1c7383c
[REEF-756] Log assembly load errors instead of dying during class hierarchy generation in Tang This addressed the issue by * Catching exception when assembly loading fails * Generate appropriate log to facilitate debugging JIRA: [REEF-756](https://issues.apache.org/jira/browse/REEF-756) Pull Request: This closes #496 Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/1f1c7383 Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/1f1c7383 Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/1f1c7383 Branch: refs/heads/master Commit: 1f1c7383cf24d6e867c6018f87c0b45ff64648b2 Parents: aea64d9 Author: Anupam <anupam...@gmail.com> Authored: Wed Sep 16 14:01:01 2015 -0700 Committer: Markus Weimer <wei...@apache.org> Committed: Wed Sep 16 16:28:57 2015 -0700 ---------------------------------------------------------------------- .../Org.Apache.REEF.Tang.Tests.csproj | 1 + .../Utilities/AssemblyLoaderTests.cs | 42 ++++++++++++++++++++ .../ClassHierarchy/ClassHierarchyImpl.cs | 26 +++++++++++- .../Org.Apache.REEF.Tang/Util/AssemblyLoader.cs | 9 ++++- 4 files changed, 75 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/1f1c7383/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj b/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj index a92d1c9..601f9a8 100644 --- a/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj @@ -108,6 +108,7 @@ under the License. <Compile Include="Tang\TestExternalConstructors.cs" /> <Compile Include="Tang\TestLegacyConstructors.cs" /> <Compile Include="Tang\TestTang.cs" /> + <Compile Include="Utilities\AssemblyLoaderTests.cs" /> <Compile Include="Utilities\TestUtilities.cs" /> <Compile Include="Utilities\Utilities.cs" /> </ItemGroup> http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/1f1c7383/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/AssemblyLoaderTests.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/AssemblyLoaderTests.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/AssemblyLoaderTests.cs new file mode 100644 index 0000000..50278dd --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Utilities/AssemblyLoaderTests.cs @@ -0,0 +1,42 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.REEF.Tang.Examples; +using Org.Apache.REEF.Tang.Util; + +namespace Org.Apache.REEF.Tang.Tests.Utilities +{ + [TestClass] + public class AssemblyLoaderTests + { + [TestMethod] + public void AssemblyLoadingFailsNoException() + { + var notUsed = new AssemblyLoader(new []{"DoesNotExist.dll"}); + } + + [TestMethod] + public void AssemblyLoadingSomeSucceedFailuresAreIgnored() + { + var loader = new AssemblyLoader(new []{"DoesNotExist.dll", FileNames.Examples}); + Assert.AreEqual(1, loader.Assemblies.Count); + Assert.IsTrue(loader.Assemblies.First().GetName().Name == FileNames.Examples); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/1f1c7383/lang/cs/Org.Apache.REEF.Tang/Implementations/ClassHierarchy/ClassHierarchyImpl.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Implementations/ClassHierarchy/ClassHierarchyImpl.cs b/lang/cs/Org.Apache.REEF.Tang/Implementations/ClassHierarchy/ClassHierarchyImpl.cs index 5164b4a..6d866b0 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Implementations/ClassHierarchy/ClassHierarchyImpl.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Implementations/ClassHierarchy/ClassHierarchyImpl.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Reflection; using System.Text; @@ -79,9 +80,30 @@ namespace Org.Apache.REEF.Tang.Implementations.ClassHierarchy foreach (var a in loader.Assemblies) { - foreach (var t in a.GetTypes()) + Type[] types; + try + { + types = a.GetTypes(); + } + catch (ReflectionTypeLoadException exception) + { + LOGGER.Log(Level.Warning, + "GetTypes failed for assembly: {0} LoaderExceptions: {1}", + a, + string.Join<Exception>("; ", exception.LoaderExceptions)); + continue; + } + + foreach (var t in types) { - RegisterType(t); + try + { + RegisterType(t); + } + catch (FileNotFoundException exception) + { + LOGGER.Log(Level.Warning, "Could not register type: {0} Exception: {1}", t, exception); + } } } } http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/1f1c7383/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs b/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs index 238914f..156f297 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Util/AssemblyLoader.cs @@ -36,7 +36,14 @@ namespace Org.Apache.REEF.Tang.Util Assemblies = new List<Assembly>(); foreach (var a in files) { - Assemblies.Add(Assembly.Load(a)); + try + { + Assemblies.Add(Assembly.Load(a)); + } + catch (FileNotFoundException exception) + { + LOGGER.Log(Level.Warning, "Could not load assembly: {0} Exception: {1}", a, exception); + } } }