From a5ee47af7f445d0fa13ccc0eeafbd2e63bbf30e6 Mon Sep 17 00:00:00 2001 From: Scott Inglis Date: Wed, 12 Sep 2018 16:34:10 -0700 Subject: [PATCH 1/3] [REEF-2044] Serializing a List in Tang for C# has missing functionality The current state did not handle serializing out a list when a list was set in the configuration. This now adds that functionality along with unit tests. JIRA: [REEF-2044](https://issues.apache.org/jira/browse/REEF-2044) Closes # --- .../Configuration/TestConfiguration.cs | 107 +++++++++++++++++- .../Formats/AvroConfigurationSerializer.cs | 36 ++++-- .../Formats/ConfigurationFile.cs | 35 +++++- .../Configuration/ConfigurationBuilderImpl.cs | 15 +++ .../Configuration/ConfigurationImpl.cs | 10 +- .../Interface/IConfiguration.cs | 1 + 6 files changed, 183 insertions(+), 21 deletions(-) diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs index 0c10dfd36a..2f719ac9e9 100644 --- a/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs @@ -15,8 +15,6 @@ // specific language governing permissions and limitations // under the License. -using System; -using System.Collections.Generic; using Org.Apache.REEF.Common.Tasks; using Org.Apache.REEF.Examples.Tasks.HelloTask; using Org.Apache.REEF.Tang.Annotations; @@ -31,6 +29,9 @@ using Org.Apache.REEF.Tang.Protobuf; using Org.Apache.REEF.Tang.Tests.ScenarioTest; using Org.Apache.REEF.Tang.Util; +using System; +using System.Collections.Generic; +using System.Linq; using Xunit; namespace Org.Apache.REEF.Tang.Tests.Configuration @@ -425,6 +426,77 @@ public void TestTimerConfigurationWithClassHierarchy() timer.sleep(); } + [Fact] + public void TestListConfig() + { + IList stringList1 = new List(); + stringList1.Add("foo"); + stringList1.Add("bar"); + + IList stringList2 = new List(); + stringList2.Add("test1"); + stringList2.Add("test2"); + stringList2.Add("test3"); + stringList2.Add("test4"); + + IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() + .BindList(GenericType.Class, stringList1) + .BindList(GenericType.Class, stringList2) + .Build(); + + ConfigurationFile.WriteConfigurationFile(conf, "ListOfStringsConf.txt"); + + string s = ConfigurationFile.ToConfigurationString(conf); + IConfiguration conf2 = ConfigurationFile.GetConfiguration(s); + + ListInjectTest injectTest = (ListInjectTest)TangFactory.GetTang(). + NewInjector(conf2).GetInstance(typeof(ListInjectTest)); + + Assert.Equal(stringList1, injectTest.List1); + Assert.Equal(stringList2, injectTest.List2); + } + + [Fact] + public void TestListConfigWithAvroSerialization() + { + IList stringList = new List(); + stringList.Add("foo"); + stringList.Add("bar"); + IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() + .BindList(GenericType.Class, stringList) + .Build(); + + var serializer = new AvroConfigurationSerializer(); + byte[] bytes = serializer.ToByteArray(conf); + IConfiguration conf2 = serializer.FromByteArray(bytes); + Assert.Equal(1, conf2.GetBoundList().Count); + + var actualList = conf2.GetBoundList().First().Value; + Assert.Equal(stringList, actualList); + } + + [Fact] + public void TestListSerializeNullStringValue() + { + string msg = null; + IList stringList = new List(); + stringList.Add(null); + + try + { + IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() + .BindList(GenericType.Class, stringList) + .Build(); + var serializer = new AvroConfigurationSerializer(); + byte[] bytes = serializer.ToByteArray(conf); + } + catch (IllegalStateException e) + { + msg = e.Message; + } + Assert.NotNull(msg); + } + [Fact] public void TestSetConfig() { @@ -448,6 +520,7 @@ public void TestSetConfig() Assert.True(actual.Contains("six")); } + [Fact] public void TestSetConfigWithAvroSerialization() { @@ -471,6 +544,7 @@ public void TestSetConfigWithAvroSerialization() Assert.True(actual.Contains("six")); } + [Fact] public void TestNullStringValue() { @@ -508,11 +582,38 @@ public void TestSetConfigNullValue() } } + [NamedParameter] + class ListOfStrings : Name> + { + + } + + [NamedParameter] + class ListOfStrings2 : Name> + { + + } + + class ListInjectTest + { + public IList List1; + public IList List2; + + [Inject] + ListInjectTest([Parameter(typeof(ListOfStrings))] IList list1, + [Parameter(typeof(ListOfStrings2))] IList list2) + { + this.List1 = list1; + this.List2 = list2; + } + } + [NamedParameter(DefaultValues = new string[] { "one", "two", "three" })] class SetOfNumbers : Name> { } + class Box { public ISet Numbers; @@ -560,4 +661,4 @@ public string GetString() return str; } } -} \ No newline at end of file +} diff --git a/lang/cs/Org.Apache.REEF.Tang/Formats/AvroConfigurationSerializer.cs b/lang/cs/Org.Apache.REEF.Tang/Formats/AvroConfigurationSerializer.cs index 565d4fdd57..83eb50e5c8 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Formats/AvroConfigurationSerializer.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Formats/AvroConfigurationSerializer.cs @@ -15,13 +15,6 @@ // specific language governing permissions and limitations // under the License. -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; using Microsoft.Hadoop.Avro; using Microsoft.Hadoop.Avro.Container; using Newtonsoft.Json; @@ -34,6 +27,13 @@ using Org.Apache.REEF.Tang.Types; using Org.Apache.REEF.Tang.Util; using Org.Apache.REEF.Utilities.Logging; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; namespace Org.Apache.REEF.Tang.Formats { @@ -260,6 +260,28 @@ public AvroConfiguration ToAvroConfiguration(IConfiguration c) l.Add(new ConfigurationEntry(e.Key.GetFullName(), val)); } + IEnumerator bl = conf.GetBoundList().GetEnumerator(); + while (bl.MoveNext()) + { + KeyValuePair> e = (KeyValuePair>)bl.Current; + foreach (var item in e.Value) + { + string val = null; + if (item is string) + { + val = (string)item; + } + else if (item is INode) + { + val = ((INode)item).GetFullName(); + } + else + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER); + } + l.Add(new ConfigurationEntry(e.Key.GetFullName(), val)); + } + } return new AvroConfiguration(Language.Cs.ToString(), l); } diff --git a/lang/cs/Org.Apache.REEF.Tang/Formats/ConfigurationFile.cs b/lang/cs/Org.Apache.REEF.Tang/Formats/ConfigurationFile.cs index 01a20c8a26..f72c589b37 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Formats/ConfigurationFile.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Formats/ConfigurationFile.cs @@ -15,12 +15,6 @@ // specific language governing permissions and limitations // under the License. -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; using Org.Apache.REEF.Tang.Exceptions; using Org.Apache.REEF.Tang.Implementations.Configuration; using Org.Apache.REEF.Tang.Implementations.Tang; @@ -28,6 +22,12 @@ using Org.Apache.REEF.Tang.Types; using Org.Apache.REEF.Tang.Util; using Org.Apache.REEF.Utilities.Logging; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; namespace Org.Apache.REEF.Tang.Formats { @@ -139,6 +139,29 @@ public static HashSet ToConfigurationStringList(IConfiguration c) l.Add(GetFullName(e.Key) + '=' + Escape(val)); } + IEnumerator bl = conf.GetBoundList().GetEnumerator(); + while (bl.MoveNext()) + { + KeyValuePair> e = (KeyValuePair>)bl.Current; + foreach (var item in e.Value) + { + string val = null; + if (item is string) + { + val = GetFullName((string)item); + } + else if (e.Value is INode) + { + val = GetFullName((INode)e.Value); + } + else + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER); + } + l.Add(GetFullName(e.Key) + '=' + Escape(val)); + } + } + return l; } diff --git a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationBuilderImpl.cs b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationBuilderImpl.cs index 4eab9a1e8a..03b7efb80d 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationBuilderImpl.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationBuilderImpl.cs @@ -275,6 +275,10 @@ public void BindParameter(INamedParameterNode name, string value) { BindSetEntry((INamedParameterNode)name, value); } + else if (name.IsList()) + { + BindList((INamedParameterNode)name, value); + } else { try @@ -289,6 +293,17 @@ public void BindParameter(INamedParameterNode name, string value) } } + public void BindList(INamedParameterNode iface, string impl) + { + IList l; + if (!BoundLists.TryGetValue(iface, out l)) + { + l = new List(); + BoundLists.Add(iface, l); + } + l.Add((object)impl); + } + public void BindImplementation(IClassNode n, IClassNode m) { if (this.ClassHierarchy.IsImplementation(n, m)) diff --git a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationImpl.cs b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationImpl.cs index 2a3ce89023..252c38c5b7 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationImpl.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationImpl.cs @@ -15,9 +15,9 @@ // specific language governing permissions and limitations // under the License. -using System.Collections.Generic; using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Tang.Types; +using System.Collections.Generic; namespace Org.Apache.REEF.Tang.Implementations.Configuration { @@ -39,7 +39,7 @@ public IConfigurationBuilder newBuilder() { return ((ConfigurationImpl)Builder.Build()).Builder; } - + public ICollection GetBoundImplementations() { return Builder.BoundImpls.Keys; @@ -95,12 +95,12 @@ public ICollection GetLegacyConstructors() return Builder.LegacyConstructors.Keys; } - public ISet GetBoundSet(INamedParameterNode np) + public ISet GetBoundSet(INamedParameterNode np) { return Builder.BoundSetEntries.GetValuesForKey(np); } - public IEnumerator> GetBoundSets() + public IEnumerator> GetBoundSets() { return Builder.BoundSetEntries.GetEnumerator(); } @@ -117,4 +117,4 @@ public IList GetBoundList(INamedParameterNode np) return list; } } -} \ No newline at end of file +} diff --git a/lang/cs/Org.Apache.REEF.Tang/Interface/IConfiguration.cs b/lang/cs/Org.Apache.REEF.Tang/Interface/IConfiguration.cs index cb50d2ada8..af4c892b18 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Interface/IConfiguration.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Interface/IConfiguration.cs @@ -39,6 +39,7 @@ public interface IConfiguration ICollection GetLegacyConstructors(); IEnumerator> GetBoundSets(); + IDictionary> GetBoundList(); } } From f847c75222ec346581ae285585af39f4bcac87a6 Mon Sep 17 00:00:00 2001 From: Scott Inglis Date: Thu, 18 Oct 2018 16:56:40 -0700 Subject: [PATCH 2/3] - Added more unit tests, plus checks for null/empty strings in lists --- .../Configuration/TestConfiguration.cs | 98 ++++++++++++++++--- .../Formats/AvroConfigurationSerializer.cs | 12 +-- .../Formats/ConfigurationFile.cs | 16 ++- .../Configuration/ConfigurationBuilderImpl.cs | 5 + .../Configuration/ConfigurationImpl.cs | 10 +- .../CsConfigurationBuilderImpl.cs | 12 ++- .../Interface/IConfiguration.cs | 1 - 7 files changed, 119 insertions(+), 35 deletions(-) diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs index 2f719ac9e9..a33960f792 100644 --- a/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs @@ -444,8 +444,6 @@ public void TestListConfig() .BindList(GenericType.Class, stringList2) .Build(); - ConfigurationFile.WriteConfigurationFile(conf, "ListOfStringsConf.txt"); - string s = ConfigurationFile.ToConfigurationString(conf); IConfiguration conf2 = ConfigurationFile.GetConfiguration(s); @@ -457,22 +455,83 @@ public void TestListConfig() } [Fact] - public void TestListConfigWithAvroSerialization() + public void TestListConfigWithEmptyList() { - IList stringList = new List(); - stringList.Add("foo"); - stringList.Add("bar"); + IList stringList1 = new List(); + IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() - .BindList(GenericType.Class, stringList) + .BindList(GenericType.Class, stringList1) + .Build(); + string s = ConfigurationFile.ToConfigurationString(conf); + // string will be empty since there is nothing to save + Assert.Equal(0, s.Length); + } + + [Fact] + public void TestListConfigWithEmptyString() + { + IList stringList1 = new List(); + stringList1.Add(""); + + try + { + IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() + .BindList(GenericType.Class, stringList1) + .Build(); + } + catch(BindException) + { + return; + } + + Assert.True(false, "Failed to throw expected exception."); + + } + + [Fact] + public void TestListConfigWithNullStringValue() + { + IList stringList1 = new List(); + stringList1.Add(null); + + try + { + IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() + .BindList(GenericType.Class, stringList1) + .Build(); + } + catch(BindException) + { + return; + } + + Assert.True(false, "Failed to throw expected exception."); + } + + private void TestSerializeListHelper(IList items, int expectedLists = 1) + { + IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() + .BindList(GenericType.Class, items) .Build(); var serializer = new AvroConfigurationSerializer(); byte[] bytes = serializer.ToByteArray(conf); IConfiguration conf2 = serializer.FromByteArray(bytes); - Assert.Equal(1, conf2.GetBoundList().Count); + Assert.Equal(expectedLists, conf2.GetBoundList().Count); + if (expectedLists > 1) + { + var actualList = conf2.GetBoundList().First().Value; + Assert.Equal(items, actualList); + } + } - var actualList = conf2.GetBoundList().First().Value; - Assert.Equal(stringList, actualList); + [Fact] + public void TestListSerialize() + { + IList stringList = new List(); + stringList.Add("foo"); + stringList.Add("bar"); + TestSerializeListHelper(stringList); } [Fact] @@ -490,13 +549,30 @@ public void TestListSerializeNullStringValue() var serializer = new AvroConfigurationSerializer(); byte[] bytes = serializer.ToByteArray(conf); } - catch (IllegalStateException e) + catch (TangApplicationException e) { msg = e.Message; } Assert.NotNull(msg); } + [Fact] + public void TestListSerializeEmptyList() + { + IList stringList = new List(); + TestSerializeListHelper(stringList, 0); + } + + [Fact] + public void TestListSerializeEmptyStrings() + { + string msg = null; + IList stringList = new List(); + stringList.Add(""); + stringList.Add(""); + TestSerializeListHelper(stringList); + } + [Fact] public void TestSetConfig() { diff --git a/lang/cs/Org.Apache.REEF.Tang/Formats/AvroConfigurationSerializer.cs b/lang/cs/Org.Apache.REEF.Tang/Formats/AvroConfigurationSerializer.cs index 83eb50e5c8..c09321e073 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Formats/AvroConfigurationSerializer.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Formats/AvroConfigurationSerializer.cs @@ -254,17 +254,15 @@ public AvroConfiguration ToAvroConfiguration(IConfiguration c) } else { - Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER); + throw new TangApplicationException("Unable to serialize set of type {e.Value.GetType()}"); } l.Add(new ConfigurationEntry(e.Key.GetFullName(), val)); } - IEnumerator bl = conf.GetBoundList().GetEnumerator(); - while (bl.MoveNext()) + foreach (var kvp in conf.GetBoundList()) { - KeyValuePair> e = (KeyValuePair>)bl.Current; - foreach (var item in e.Value) + foreach (var item in kvp.Value) { string val = null; if (item is string) @@ -277,9 +275,9 @@ public AvroConfiguration ToAvroConfiguration(IConfiguration c) } else { - Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER); + throw new TangApplicationException("Unable to serialize list of type {item.GetType()}"); } - l.Add(new ConfigurationEntry(e.Key.GetFullName(), val)); + l.Add(new ConfigurationEntry(kvp.Key.GetFullName(), val)); } } return new AvroConfiguration(Language.Cs.ToString(), l); diff --git a/lang/cs/Org.Apache.REEF.Tang/Formats/ConfigurationFile.cs b/lang/cs/Org.Apache.REEF.Tang/Formats/ConfigurationFile.cs index f72c589b37..63cf800603 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Formats/ConfigurationFile.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Formats/ConfigurationFile.cs @@ -133,32 +133,30 @@ public static HashSet ToConfigurationStringList(IConfiguration c) } else { - Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER); + throw new BindException($"Failed to serialize set of unsupported type {e.Value.GetType()}"); } l.Add(GetFullName(e.Key) + '=' + Escape(val)); } - IEnumerator bl = conf.GetBoundList().GetEnumerator(); - while (bl.MoveNext()) + foreach(var kvp in conf.GetBoundList()) { - KeyValuePair> e = (KeyValuePair>)bl.Current; - foreach (var item in e.Value) + foreach (var item in kvp.Value) { string val = null; if (item is string) { val = GetFullName((string)item); } - else if (e.Value is INode) + else if (kvp.Value is INode) { - val = GetFullName((INode)e.Value); + val = GetFullName((INode)kvp.Value); } else { - Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER); + throw new BindException($"Failed to serialize list of unsupported type {item.GetType()}"); } - l.Add(GetFullName(e.Key) + '=' + Escape(val)); + l.Add(GetFullName(kvp.Key) + '=' + Escape(val)); } } diff --git a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationBuilderImpl.cs b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationBuilderImpl.cs index 03b7efb80d..b3dff636fb 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationBuilderImpl.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationBuilderImpl.cs @@ -352,6 +352,11 @@ public void BindList(INamedParameterNode iface, IList impl) IList l = new List(); foreach (var n in impl) { + if (string.IsNullOrEmpty(n)) + { + throw new ArgumentException("List cannot contain string that are null or empty"); + } + l.Add((object)n); } BoundLists.Add(iface, l); diff --git a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationImpl.cs b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationImpl.cs index 252c38c5b7..2a3ce89023 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationImpl.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/ConfigurationImpl.cs @@ -15,9 +15,9 @@ // specific language governing permissions and limitations // under the License. +using System.Collections.Generic; using Org.Apache.REEF.Tang.Interface; using Org.Apache.REEF.Tang.Types; -using System.Collections.Generic; namespace Org.Apache.REEF.Tang.Implementations.Configuration { @@ -39,7 +39,7 @@ public IConfigurationBuilder newBuilder() { return ((ConfigurationImpl)Builder.Build()).Builder; } - + public ICollection GetBoundImplementations() { return Builder.BoundImpls.Keys; @@ -95,12 +95,12 @@ public ICollection GetLegacyConstructors() return Builder.LegacyConstructors.Keys; } - public ISet GetBoundSet(INamedParameterNode np) + public ISet GetBoundSet(INamedParameterNode np) { return Builder.BoundSetEntries.GetValuesForKey(np); } - public IEnumerator> GetBoundSets() + public IEnumerator> GetBoundSets() { return Builder.BoundSetEntries.GetEnumerator(); } @@ -117,4 +117,4 @@ public IList GetBoundList(INamedParameterNode np) return list; } } -} +} \ No newline at end of file diff --git a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/CsConfigurationBuilderImpl.cs b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/CsConfigurationBuilderImpl.cs index 569d4670a1..922aefded6 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/CsConfigurationBuilderImpl.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Implementations/Configuration/CsConfigurationBuilderImpl.cs @@ -399,7 +399,15 @@ ICsInternalConfigurationBuilder ICsInternalConfigurationBuilder.BindList(Type if Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); } - BindList((INamedParameterNode)n, implList); + try + { + BindList((INamedParameterNode)n, implList); + } + catch(ArgumentException ex) + { + throw new BindException($"BindList failed to bind for {iface.Name}, reason: {ex.Message}"); + } + return this; } @@ -490,4 +498,4 @@ private INode GetNode(Type c) return ((ICsClassHierarchy)ClassHierarchy).GetNode(c); } } -} \ No newline at end of file +} diff --git a/lang/cs/Org.Apache.REEF.Tang/Interface/IConfiguration.cs b/lang/cs/Org.Apache.REEF.Tang/Interface/IConfiguration.cs index af4c892b18..cb50d2ada8 100644 --- a/lang/cs/Org.Apache.REEF.Tang/Interface/IConfiguration.cs +++ b/lang/cs/Org.Apache.REEF.Tang/Interface/IConfiguration.cs @@ -39,7 +39,6 @@ public interface IConfiguration ICollection GetLegacyConstructors(); IEnumerator> GetBoundSets(); - IDictionary> GetBoundList(); } } From 11b134de07cabebd00a30042e7063deaab9300f7 Mon Sep 17 00:00:00 2001 From: Scott Inglis Date: Fri, 19 Oct 2018 11:46:27 -0700 Subject: [PATCH 3/3] - Updating to tests to handle the binding exception for null and empty lists --- .../Configuration/TestConfiguration.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs index a33960f792..b2970ae0d1 100644 --- a/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Configuration/TestConfiguration.cs @@ -541,19 +541,8 @@ public void TestListSerializeNullStringValue() IList stringList = new List(); stringList.Add(null); - try - { - IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() - .BindList(GenericType.Class, stringList) - .Build(); - var serializer = new AvroConfigurationSerializer(); - byte[] bytes = serializer.ToByteArray(conf); - } - catch (TangApplicationException e) - { - msg = e.Message; - } - Assert.NotNull(msg); + var builder = TangFactory.GetTang().NewConfigurationBuilder(); + Assert.Throws(() => builder.BindList(GenericType.Class, stringList)); } [Fact] @@ -570,7 +559,9 @@ public void TestListSerializeEmptyStrings() IList stringList = new List(); stringList.Add(""); stringList.Add(""); - TestSerializeListHelper(stringList); + + var builder = TangFactory.GetTang().NewConfigurationBuilder(); + Assert.Throws(() => builder.BindList(GenericType.Class, stringList)); } [Fact]