http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Configuration/TestAvroConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Configuration/TestAvroConfiguration.cs b/lang/cs/Tests/TangTests/Configuration/TestAvroConfiguration.cs deleted file mode 100644 index 7f7a80d..0000000 --- a/lang/cs/Tests/TangTests/Configuration/TestAvroConfiguration.cs +++ /dev/null @@ -1,68 +0,0 @@ -/** - * 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.Collections.Generic; -using Org.Apache.Reef.Tasks; -using Org.Apache.Reef.Tang.Formats; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Configuration -{ - [TestClass] - public class TestAvroConfiguration - { - [TestMethod] - public void TestFromJsonString() - { - IConfigurationSerializer serializerImpl = (IConfigurationSerializer)TangFactory.GetTang().NewInjector().GetInstance(typeof(IConfigurationSerializer)); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - IConfiguration conf = cb.Build(); - string jsonStr = serializerImpl.ToString(conf); - - IConfiguration c = serializerImpl.FromString(jsonStr); - Assert.IsNotNull(c); - - string jsonStr2 = serializerImpl.ToString(c); - - IConfiguration c1 = serializerImpl.FromString(jsonStr2); - Assert.IsNotNull(c1); - } - - private AvroConfiguration ToAvroConfiguration() - { - var a = new AvroConfiguration(); - HashSet<ConfigurationEntry> b = new HashSet<ConfigurationEntry>(); - ConfigurationEntry e1 = new ConfigurationEntry(); - e1.key = "a"; - e1.value = "a1"; - ConfigurationEntry e2 = new ConfigurationEntry(); - e2.key = "b"; - e2.value = "b1=b2"; - b.Add(e1); - b.Add(e2); - a.Bindings = b; - return a; - } - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Configuration/TestAvroSerializerRoundTrip.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Configuration/TestAvroSerializerRoundTrip.cs b/lang/cs/Tests/TangTests/Configuration/TestAvroSerializerRoundTrip.cs deleted file mode 100644 index 37c583d..0000000 --- a/lang/cs/Tests/TangTests/Configuration/TestAvroSerializerRoundTrip.cs +++ /dev/null @@ -1,71 +0,0 @@ -/** - * 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 Org.Apache.Reef.Tang.Formats; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Test.SmokeTest; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Configuration -{ - internal class TestAvroSerializerRoundTrip - { - [TestClass] - public class AvroConfigurationTest : RoundTripTest - { - public override IConfiguration RoundTrip(IConfiguration configuration) - { - AvroConfiguration aConf = new AvroConfigurationSerializer().ToAvroConfiguration(configuration); - return new AvroConfigurationSerializer().FromAvro(aConf); - } - } - - [TestClass] - public class ByteArrayTest : RoundTripTest - { - public override IConfiguration RoundTrip(IConfiguration configuration) - { - AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); - byte[] theBytes = serializer.ToByteArray(configuration); - return serializer.FromByteArray(theBytes); - } - } - - [TestClass] - public class FileTest : RoundTripTest - { - public override IConfiguration RoundTrip(IConfiguration configuration) - { - AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); - serializer.ToFile(configuration, "TangTest.avroconf"); - return serializer.FromFile("TangTest.avroconf"); - } - } - - [TestClass] - public class StringTest : RoundTripTest - { - public override IConfiguration RoundTrip(IConfiguration configuration) - { - AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); - return serializer.FromString(serializer.ToString(configuration)); - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Configuration/TestConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Configuration/TestConfiguration.cs b/lang/cs/Tests/TangTests/Configuration/TestConfiguration.cs deleted file mode 100644 index 1e96cc3..0000000 --- a/lang/cs/Tests/TangTests/Configuration/TestConfiguration.cs +++ /dev/null @@ -1,566 +0,0 @@ -/** - * 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; -using System.Collections.Generic; -using System.Reflection; -using Org.Apache.Reef.Tasks; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Examples; -using Org.Apache.Reef.Tang.Exceptions; -using Org.Apache.Reef.Tang.Formats; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Implementations.Configuration; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Protobuf; -using Org.Apache.Reef.Tang.Util; -using Org.Apache.Reef.Tang.Test.ScenarioTest; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Configuration -{ - [TestClass] - public class TestConfiguration - { - [ClassInitialize] - public static void ClassSetup(TestContext context) - { - } - - [TestMethod] - public void TestDeserializedConfigMerge() - { - Type activityInterfaceType = typeof(ITask); - ITang tang = TangFactory.GetTang(); - - ICsConfigurationBuilder cb1 = tang.NewConfigurationBuilder(); - cb1.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - cb1.BindNamedParameter<TaskConfigurationOptions.Identifier, string>( - GenericType<TaskConfigurationOptions.Identifier>.Class, "Hello Task"); - IConfiguration conf1 = cb1.Build(); - var serializer = new AvroConfigurationSerializer(); - serializer.ToFile(conf1, "task.config"); - - ICsConfigurationBuilder cb2 = tang.NewConfigurationBuilder(); - cb2.BindNamedParameter<Timer.Seconds, Int32>(GenericType<Timer.Seconds>.Class, "2"); - IConfiguration conf2 = cb2.Build(); - serializer.ToFile(conf2, "timer.config"); - - ProtocolBufferClassHierarchy.Serialize("TaskTimer.bin", conf1.GetClassHierarchy()); - IClassHierarchy ns = ProtocolBufferClassHierarchy.DeSerialize("TaskTimer.bin"); - - AvroConfiguration taskAvroconfiguration = serializer.AvroDeseriaizeFromFile("task.config"); - IConfiguration taskConfiguration = serializer.FromAvro(taskAvroconfiguration, ns); - - AvroConfiguration timerAvroconfiguration = serializer.AvroDeseriaizeFromFile("timer.config"); - IConfiguration timerConfiguration = serializer.FromAvro(timerAvroconfiguration, ns); - - IConfiguration merged = Configurations.MergeDeserializedConfs(taskConfiguration, timerConfiguration); - - var b = merged.newBuilder().Build(); - } - - [TestMethod] - public void TestActivityConfiguration() - { - Type activityInterfaceType = typeof (ITask); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Common, FileNames.Tasks }); - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - cb.BindNamedParameter<TaskConfigurationOptions.Identifier, string>( - GenericType<TaskConfigurationOptions.Identifier>.Class, "Hello Task"); - IConfiguration conf = cb.Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "TaskConf.txt"); - IDictionary<string, string> p = ConfigurationFile.FromFile("TaskConf.txt"); - - ITang tang1 = TangFactory.GetTang(); - ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Common, FileNames.Tasks }); - ConfigurationFile.AddConfigurationFromFile(cb1, "TaskConf.txt"); - IConfiguration conf1 = cb1.Build(); - - IInjector injector = tang1.NewInjector(conf1); - var activityRef = (ITask) injector.GetInstance(activityInterfaceType); - Assert.IsNotNull(activityRef); - } - - [TestMethod] - public void TestMultipleConfiguration() - { - Type activityInterfaceType = typeof (ITask); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Common, FileNames.Tasks }); - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - cb.BindNamedParameter<TaskConfigurationOptions.Identifier, string>( - GenericType<TaskConfigurationOptions.Identifier>.Class, "Hello Task"); - IConfiguration conf = cb.Build(); - - IConfiguration httpConfiguraiton = HttpHandlerConfiguration.CONF - .Set(HttpHandlerConfiguration.P, GenericType<HttpServerReefEventHandler>.Class) - .Set(HttpHandlerConfiguration.P, GenericType<HttpServerNrtEventHandler>.Class) - .Build(); - - IInjector injector = TangFactory.GetTang().NewInjector(new IConfiguration[] {conf, httpConfiguraiton}); - var activityRef = (ITask) injector.GetInstance(activityInterfaceType); - Assert.IsNotNull(activityRef); - - RuntimeClock clock = injector.GetInstance<RuntimeClock>(); - var rh = clock.ClockRuntimeStartHandler.Get(); - Assert.AreEqual(rh.Count, 1); - } - - [TestMethod] - public void TestActivityConfigWithSeperateAssembly() - { - Type activityInterfaceType = typeof (ITask); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Common, FileNames.Tasks }); - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - IConfiguration conf = cb.Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "TaskConf1.txt"); - IDictionary<string, string> p = ConfigurationFile.FromFile("TaskConf1.txt"); - - IInjector injector = tang.NewInjector(new string[] { FileNames.Common, FileNames.Tasks }, "TaskConf1.txt"); - var activityRef = (ITask) injector.GetInstance(activityInterfaceType); - - //combined line sample - var o = (ITask) TangFactory.GetTang() - .NewInjector(new string[] { FileNames.Common, FileNames.Tasks }, "TaskConf1.txt") - .GetInstance(typeof (ITask)); - - Assert.IsNotNull(activityRef); - } - - [TestMethod] - public void TestGetConfgiFromProtoBufClassHierarchy() - { - Type iTaskType = typeof(Org.Apache.Reef.Tasks.ITask); - Type helloTaskType = typeof(Org.Apache.Reef.Tasks.HelloTask); - Type identifierType = typeof (TaskConfigurationOptions.Identifier); - - IClassHierarchy ns = TangFactory.GetTang().GetClassHierarchy(new string[] { FileNames.Common, FileNames.Tasks }); - ProtocolBufferClassHierarchy.Serialize("Task.bin", ns); - IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize("Task.bin"); - ITang tang = TangFactory.GetTang(); - IConfigurationBuilder cb = tang.NewConfigurationBuilder(ch); - cb.Bind(iTaskType.AssemblyQualifiedName, helloTaskType.AssemblyQualifiedName); - cb.Bind(identifierType.AssemblyQualifiedName, "Hello Task"); - IConfiguration conf = cb.Build(); - ConfigurationFile.WriteConfigurationFile(conf, "taskConf2.txt"); - } - - [TestMethod] - public void TestActivityConfig() - { - Type activityInterfaceType = typeof (ITask); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples, FileNames.Common, FileNames.Tasks }); - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - IConfiguration conf = cb.Build(); - ConfigurationFile.WriteConfigurationFile(conf, "TaskConf.txt"); - IDictionary<string, string> p = ConfigurationFile.FromFile("TaskConf.txt"); - - IInjector injector = tang.NewInjector(new string[] { FileNames.Common, FileNames.Tasks }, "TaskConf.txt"); - var activityRef = (ITask) injector.GetInstance(activityInterfaceType); - - Assert.IsNotNull(activityRef); - } - - [TestMethod] - public void TestActivityConfigWithString() - { - Type activityInterfaceType = typeof (ITask); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples, FileNames.Common, FileNames.Tasks }); - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - IConfiguration conf = cb.Build(); - - string s = ConfigurationFile.ToConfigurationString(conf); - ICsConfigurationBuilder cb2 = tang.NewConfigurationBuilder(new string[] { FileNames.Examples, FileNames.Common, FileNames.Tasks }); - ConfigurationFile.AddConfigurationFromString(cb2, s); - IConfiguration conf2 = cb2.Build(); - - IInjector injector = tang.NewInjector(conf2); - var activityRef = (ITask) injector.GetInstance(activityInterfaceType); - - Assert.IsNotNull(activityRef); - } - - [TestMethod] - public void TestTweetConfiguration() - { - Type tweeterType = typeof (Tweeter); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); - cb.BindImplementation(GenericType<ITweetFactory>.Class, GenericType<MockTweetFactory>.Class); - cb.BindImplementation(GenericType<ISMS>.Class, GenericType<MockSMS>.Class); - cb.BindNamedParameter<Tweeter.PhoneNumber, long>(GenericType<Tweeter.PhoneNumber>.Class, "8675309"); - IConfiguration conf = cb.Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "tweeterConf.txt"); - IDictionary<string, string> p = ConfigurationFile.FromFile("tweeterConf.txt"); - ITang tang1 = TangFactory.GetTang(); - ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Examples }); - ConfigurationFile.AddConfigurationFromFile(cb1, "tweeterConf.txt"); - IConfiguration conf1 = cb1.Build(); - - IInjector injector = tang1.NewInjector(conf1); - var tweeter = (Tweeter) injector.GetInstance(tweeterType); - tweeter.sendMessage(); - } - - [TestMethod] - public void TestTweetConfig() - { - Type tweeterType = typeof (Tweeter); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); - cb.BindImplementation(GenericType<ITweetFactory>.Class, GenericType<MockTweetFactory>.Class); - cb.BindImplementation(GenericType<ISMS>.Class, GenericType<MockSMS>.Class); - cb.BindNamedParameter<Tweeter.PhoneNumber, long>(GenericType<Tweeter.PhoneNumber>.Class, "8675309"); - IConfiguration conf = cb.Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "tweeterConf.txt"); - IDictionary<string, string> p = ConfigurationFile.FromFile("tweeterConf.txt"); - - IInjector injector = tang.NewInjector(new string[] { FileNames.Examples }, "tweeterConf.txt"); - var tweeter = (Tweeter) injector.GetInstance(tweeterType); - tweeter.sendMessage(); - } - - - [TestMethod] - public void TestTweetConfigWithAvroThroughFile() - { - Type tweeterType = typeof (Tweeter); - ITang tang = TangFactory.GetTang(); - IConfiguration conf = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }) - .BindImplementation(GenericType<ITweetFactory>.Class, - GenericType<MockTweetFactory>.Class) - .BindImplementation(GenericType<ISMS>.Class, GenericType<MockSMS>.Class) - .BindNamedParameter<Tweeter.PhoneNumber, long>( - GenericType<Tweeter.PhoneNumber>.Class, "8675309") - .Build(); - - var serializer = new AvroConfigurationSerializer(); - serializer.ToFileStream(conf, "tweeterConfAvro.bin"); - IConfiguration conf2 = serializer.FromFileStream("tweeterConfAvro.bin"); - - IInjector injector = tang.NewInjector(conf2); - var tweeter = (Tweeter) injector.GetInstance(tweeterType); - tweeter.sendMessage(); - } - - [TestMethod] - public void TestTweetConfigAddConfigurationFromString() - { - Type tweeterType = typeof (Tweeter); - ITang tang = TangFactory.GetTang(); - IConfiguration conf = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }) - .BindImplementation(GenericType<ITweetFactory>.Class, - GenericType<MockTweetFactory>.Class) - .BindImplementation(GenericType<ISMS>.Class, GenericType<MockSMS>.Class) - .BindNamedParameter<Tweeter.PhoneNumber, long>( - GenericType<Tweeter.PhoneNumber>.Class, "8675309") - .Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "tweeterConf.txt"); - string s = ConfigurationFile.ToConfigurationString(conf); - ICsConfigurationBuilder cb2 = tang.NewConfigurationBuilder(); - ConfigurationFile.AddConfigurationFromString(cb2, s); - IConfiguration conf2 = cb2.Build(); - - IInjector injector = tang.NewInjector(conf2); - var tweeter = (Tweeter) injector.GetInstance(tweeterType); - tweeter.sendMessage(); - } - - [TestMethod] - public void TestTweetConfigWithAvroSerialization() - { - Type tweeterType = typeof (Tweeter); - ITang tang = TangFactory.GetTang(); - IConfiguration conf = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }) - .BindImplementation(GenericType<ITweetFactory>.Class, - GenericType<MockTweetFactory>.Class) - .BindImplementation(GenericType<ISMS>.Class, GenericType<MockSMS>.Class) - .BindNamedParameter<Tweeter.PhoneNumber, long>( - GenericType<Tweeter.PhoneNumber>.Class, "8675309") - .Build(); - - var serializer = new AvroConfigurationSerializer(); - byte[] bytes = serializer.ToByteArray(conf); - IConfiguration conf2 = serializer.FromByteArray(bytes); - - IInjector injector = tang.NewInjector(conf2); - var tweeter = (Tweeter) injector.GetInstance(tweeterType); - tweeter.sendMessage(); - } - - [TestMethod] - public void TestTweetConfigGetConfigurationFromString() - { - Type tweeterType = typeof (Tweeter); - ITang tang = TangFactory.GetTang(); - IConfiguration conf = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }) - .BindImplementation(GenericType<ITweetFactory>.Class, - GenericType<MockTweetFactory>.Class) - .BindImplementation(GenericType<ISMS>.Class, GenericType<MockSMS>.Class) - .BindNamedParameter<Tweeter.PhoneNumber, long>( - GenericType<Tweeter.PhoneNumber>.Class, "8675309") - .Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "tweeterConf.txt"); - string s = ConfigurationFile.ToConfigurationString(conf); - IConfiguration conf2 = ConfigurationFile.GetConfiguration(s); - - IInjector injector = tang.NewInjector(conf2); - var tweeter = (Tweeter) injector.GetInstance(tweeterType); - tweeter.sendMessage(); - } - - [TestMethod] - public void TestTweetInvalidBinding() - { - string msg = null; - try - { - TangFactory.GetTang().NewConfigurationBuilder(new string[] { FileNames.Examples }) - .BindImplementation(typeof (ITweetFactory), typeof (MockSMS)) - .Build(); - } - catch (ArgumentException e) - { - msg = e.Message; - } - Assert.IsNotNull(msg); - } - - [TestMethod] - public void TestTimerConfiguration() - { - Type timerType = typeof (Timer); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); - cb.BindNamedParameter<Timer.Seconds, Int32>(GenericType<Timer.Seconds>.Class, "2"); - IConfiguration conf = cb.Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "timerConf.txt"); - IDictionary<string, string> p = ConfigurationFile.FromFile("timerConf.txt"); - - ITang tang1 = TangFactory.GetTang(); - ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Examples }); - ConfigurationFile.AddConfigurationFromFile(cb1, "timerConf.txt"); - IConfiguration conf1 = cb1.Build(); - - IInjector injector = tang.NewInjector(conf1); - var timer = (Timer) injector.GetInstance(timerType); - - Assert.IsNotNull(timer); - - timer.sleep(); - } - - [TestMethod] - public void TestDocumentLoadNamedParameterConfiguration() - { - Type documentedLocalNamedParameterType = typeof (DocumentedLocalNamedParameter); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); - cb.BindNamedParameter<DocumentedLocalNamedParameter.Foo, string>( - GenericType<DocumentedLocalNamedParameter.Foo>.Class, "Hello"); - IConfiguration conf = cb.Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "docLoadConf.txt"); - IDictionary<string, string> p = ConfigurationFile.FromFile("docLoadConf.txt"); - - ITang tang1 = TangFactory.GetTang(); - ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Examples }); - ConfigurationFile.AddConfigurationFromFile(cb1, "docLoadConf.txt"); - IConfiguration conf1 = cb1.Build(); - - IInjector injector = tang1.NewInjector(conf1); - var doc = (DocumentedLocalNamedParameter) injector.GetInstance(documentedLocalNamedParameterType); - - Assert.IsNotNull(doc); - var s = doc.ToString(); - } - - [TestMethod] - public void TestTimerConfigurationWithClassHierarchy() - { - Type timerType = typeof (Timer); - ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(FileNames.Examples); - - ITang tang = TangFactory.GetTang(); - IConfiguration conf = tang.NewConfigurationBuilder(classHierarchyImpl) - .BindNamedParameter<Timer.Seconds, Int32>(GenericType<Timer.Seconds>.Class, "1") - .Build(); - - ConfigurationFile.WriteConfigurationFile(conf, "timerConfH.txt"); - IDictionary<string, string> p = ConfigurationFile.FromFile("timerConfH.txt"); - - ITang tang1 = TangFactory.GetTang(); - ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Examples }); - ConfigurationFile.AddConfigurationFromFile(cb1, "timerConfH.txt"); - IConfiguration conf1 = cb1.Build(); - - IInjector injector = tang1.NewInjector(conf1); - var timer = (Timer) injector.GetInstance(timerType); - - Assert.IsNotNull(timer); - timer.sleep(); - } - - [TestMethod] - public void TestSetConfig() - { - IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() - .BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "four") - .BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "five") - .BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "six") - .Build(); - - Box b = (Box) TangFactory.GetTang().NewInjector(conf).GetInstance(typeof (Box)); - ConfigurationFile.WriteConfigurationFile(conf, "SetOfNumbersConf.txt"); - - string s = ConfigurationFile.ToConfigurationString(conf); - IConfiguration conf2 = ConfigurationFile.GetConfiguration(s); - - Box b2 = (Box) TangFactory.GetTang().NewInjector(conf2).GetInstance(typeof (Box)); - ISet<string> actual = b2.Numbers; - - Assert.IsTrue(actual.Contains("four")); - Assert.IsTrue(actual.Contains("five")); - Assert.IsTrue(actual.Contains("six")); - } - - [TestMethod] - public void TestSetConfigWithAvroSerialization() - { - IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() - .BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "four") - .BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "five") - .BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "six") - .Build(); - - Box b = (Box) TangFactory.GetTang().NewInjector(conf).GetInstance(typeof (Box)); - - var serializer = new AvroConfigurationSerializer(); - byte[] bytes = serializer.ToByteArray(conf); - IConfiguration conf2 = serializer.FromByteArray(bytes); - - Box b2 = (Box) TangFactory.GetTang().NewInjector(conf2).GetInstance(typeof (Box)); - ISet<string> actual = b2.Numbers; - - Assert.IsTrue(actual.Contains("four")); - Assert.IsTrue(actual.Contains("five")); - Assert.IsTrue(actual.Contains("six")); - } - - [TestMethod] - public void TestNullStringVaue() - { - string msg = null; - try - { - TangFactory.GetTang().NewConfigurationBuilder() - .BindNamedParameter<NamedParamterNoDefault.NamedString, string>(GenericType<NamedParamterNoDefault.NamedString>.Class, null) - .Build(); - } - catch (IllegalStateException e) - { - msg = e.Message; - } - Assert.IsNotNull(msg); - } - - [TestMethod] - public void TestSetConfigNullValue() - { - string msg = null; - try - { - TangFactory.GetTang().NewConfigurationBuilder() - .BindSetEntry<SetOfNumbersNoDefault, string>(GenericType<SetOfNumbersNoDefault>.Class, null) - .BindSetEntry<SetOfNumbersNoDefault, string>(GenericType<SetOfNumbersNoDefault>.Class, "five") - .BindSetEntry<SetOfNumbersNoDefault, string>(GenericType<SetOfNumbersNoDefault>.Class, "six") - .Build(); - } - catch (IllegalStateException e) - { - msg = e.Message; - } - Assert.IsNotNull(msg); - } - } - - [NamedParameter(DefaultValues = new string[] {"one", "two", "three"})] - class SetOfNumbers : Name<ISet<string>> - { - } - - class Box - { - public ISet<string> Numbers; - - [Inject] - Box([Parameter(typeof (SetOfNumbers))] ISet<string> numbers) - { - this.Numbers = numbers; - } - } - - [NamedParameter] - class SetOfNumbersNoDefault : Name<ISet<string>> - { - } - - class BoxNoDefault - { - public ISet<string> Numbers; - - [Inject] - BoxNoDefault([Parameter(typeof(SetOfNumbersNoDefault))] ISet<string> numbers) - { - this.Numbers = numbers; - } - } - - class NamedParamterNoDefault - { - private string str; - - [NamedParameter] - public class NamedString : Name<string> - { - } - - [Inject] - NamedParamterNoDefault([Parameter(typeof (NamedString))] string str) - { - this.str = str; - } - - public string GetString() - { - return str; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Configuration/TestCsConfigurationBuilderExtension.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Configuration/TestCsConfigurationBuilderExtension.cs b/lang/cs/Tests/TangTests/Configuration/TestCsConfigurationBuilderExtension.cs deleted file mode 100644 index f8defdf..0000000 --- a/lang/cs/Tests/TangTests/Configuration/TestCsConfigurationBuilderExtension.cs +++ /dev/null @@ -1,178 +0,0 @@ -/** - * 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.Collections.Generic; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Org.Apache.Reef.Tang.Test.Injection; -using Org.Apache.Reef.Tang.Test.Tang; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Configuration -{ - /// <summary> - /// This class is to test extension API defined in ICsConfigurationBuilder - /// </summary> - [TestClass] - public class TestCsConfigurationBuilderExtension - { - [TestMethod] - public void TestBindNamedParameter1() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<AImplName, Aimpl, INamedImplA>(); - cb.BindNamedParameter<BImplName, Bimpl, INamedImplA>(); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - Aimpl a1 = (Aimpl)i.GetNamedInstance<AImplName, INamedImplA>(GenericType<AImplName>.Class); - Aimpl a2 = (Aimpl)i.GetNamedInstance<AImplName, INamedImplA>(GenericType<AImplName>.Class); - Bimpl b1 = (Bimpl)i.GetNamedInstance<BImplName, INamedImplA>(GenericType<BImplName>.Class); - Bimpl b2 = (Bimpl)i.GetNamedInstance<BImplName, INamedImplA>(GenericType<BImplName>.Class); - Assert.AreSame(a1, a2); - Assert.AreSame(b1, b2); - } - - [TestMethod] - public void TestBindStringNamedParam() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindStringNamedParam<StringTest.NamedString>("foo"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<StringTest>(); - o.Verify("foo"); - } - - [TestMethod] - public void TestBindIntNamedParam() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindIntNamedParam<Int32Test.NamedInt>("8"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<Int32Test>(); - o.Verify(8); - } - - [TestMethod] - public void TestBindNamedParam() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParam<BooleanTest.NamedBool, bool>("true"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<BooleanTest>(); - o.Verify(true); - } - - [TestMethod] - public void TestBindSetEntryImplValue() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindSetEntry<TestSetInjection.SetOfClasses, TestSetInjection.Integer1, INumber>() //bind an impl to the interface of the set - .BindIntNamedParam<TestSetInjection.Integer1.NamedInt>("4"); //bind parameter for the impl - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - - ISet<INumber> actual = i.GetInstance<TestSetInjection.Pool>().Numbers; - ISet<INumber> expected = new HashSet<INumber>(); - expected.Add(new TestSetInjection.Integer1(4)); - - Assert.IsTrue(Utilities.Utilities.Equals<INumber>(actual, expected)); - } - - [TestMethod] - public void TestBindSetEntryStringValue() - { - IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder() - .BindSetEntry<SetOfNumbers, string>("four") - .BindSetEntry<SetOfNumbers, string>("five") - .BindSetEntry<SetOfNumbers, string>("six") - .Build(); - - Box b = (Box)TangFactory.GetTang().NewInjector(conf).GetInstance(typeof(Box)); - ISet<string> actual = b.Numbers; - - Assert.IsTrue(actual.Contains("four")); - Assert.IsTrue(actual.Contains("five")); - Assert.IsTrue(actual.Contains("six")); - } - - [TestMethod] - public void TestBindImplementation() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindImplementation<Interf, Impl>(); - Interf o = TangFactory.GetTang().NewInjector(cb.Build()).GetInstance<Interf>(); - Assert.IsTrue(o is Impl); - } - - [TestMethod] - public void TestBindList() - { - IList<string> injected = new List<string>(); - injected.Add("hi"); - injected.Add("hello"); - injected.Add("bye"); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList<StringList, string>(injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - IList<string> actual = ((StringClass)i.GetInstance(typeof(StringClass))).StringList; - - Assert.IsTrue(actual.Contains("hi")); - Assert.IsTrue(actual.Contains("hello")); - Assert.IsTrue(actual.Contains("bye")); - Assert.AreEqual(actual.Count, 3); - } - - [TestMethod] - public void TestObjectInjectWithInjectableSubclassesMultipleInstances() - { - IList<string> injected = new List<string>(); - injected.Add(typeof(TestSetInjection.Integer1).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Integer1).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Float1).AssemblyQualifiedName); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindIntNamedParam<TestSetInjection.Integer1.NamedInt>("5"); - cb.BindNamedParam<TestSetInjection.Float1.NamedFloat, float>("12.5"); - cb.BindList<ListOfClasses, INumber>(injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Count == 3); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(5))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(5))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Float1(12.5f))); - } - - [TestMethod] - public void TestBindConstructor() - { - ICsConfigurationBuilder b = TangFactory.GetTang().NewConfigurationBuilder(); - b.BindConstructor<TestExternalConstructors.A, TestExternalConstructors.ACons>(); - b.BindConstructor<TestExternalConstructors.B, TestExternalConstructors.BCons>(); - - TangFactory.GetTang().NewInjector(b.Build()).GetInstance(typeof(TestExternalConstructors.B)); - TangFactory.GetTang().NewInjector(b.Build()).GetInstance(typeof(TestExternalConstructors.A)); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Format/TestConfigurationModule.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Format/TestConfigurationModule.cs b/lang/cs/Tests/TangTests/Format/TestConfigurationModule.cs deleted file mode 100644 index 94d3ad2..0000000 --- a/lang/cs/Tests/TangTests/Format/TestConfigurationModule.cs +++ /dev/null @@ -1,522 +0,0 @@ -/** - * 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; -using System.Collections.Generic; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Exceptions; -using Org.Apache.Reef.Tang.Formats; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Format -{ - public interface IFoo - { - int getFooness(); - } - - interface ISuper - { - } - - [TestClass] - public class TestConfigurationModule - { - [ClassInitialize] - public static void ClassSetup(TestContext context) - { - } - - [ClassCleanup] - public static void ClassCleanup() - { - } - - [TestInitialize()] - public void TestSetup() - { - } - - [TestCleanup()] - public void TestCleanup() - { - } - - [TestMethod] - public void SmokeTest() - { - // Here we set some configuration values. In true tang style, - // you won't be able to set them more than once ConfigurationModule's - // implementation is complete. - Type fooType = typeof(Org.Apache.Reef.Tang.Test.Format.IFoo); - - IConfiguration c = MyConfigurationModule.Conf - .Set(MyConfigurationModule.TheFoo, GenericType<FooImpl>.Class) - .Set(MyConfigurationModule.FooNess, "12") - .Build(); - IFoo f = (IFoo)TangFactory.GetTang().NewInjector(c).GetInstance(fooType); - Assert.AreEqual(f.getFooness(), 12); - } - - [TestMethod] - public void SmokeTestConfig() - { - // Here we set some configuration values. In true tang style, - // you won't be able to set them more than once ConfigurationModule's - // implementation is complete. - Type fooType = typeof(Org.Apache.Reef.Tang.Test.Format.IFoo); - - IConfiguration c = MyConfigurationModule.Conf - .Set(MyConfigurationModule.TheFoo, GenericType<FooImpl>.Class) - .Set(MyConfigurationModule.FooNess, "12") - .Build(); - IFoo f = (IFoo)TangFactory.GetTang().NewInjector(c).GetInstance(fooType); - Assert.AreEqual(f.getFooness(), 12); - AvroConfigurationSerializer serializerCs = new AvroConfigurationSerializer(); - - serializerCs.ToFileStream(c, "TangTestCs.avroconf"); - var c3 = serializerCs.FromFileStream("TangTestCs.avroconf"); - IFoo f3 = (IFoo)TangFactory.GetTang().NewInjector(c3).GetInstance(fooType); - Assert.AreEqual(f3.getFooness(), 12); - - serializerCs.ToFile(c, "TangTestCs1.avro"); - var c4 = serializerCs.FromFile("TangTestCs1.avro"); - IFoo f4 = (IFoo)TangFactory.GetTang().NewInjector(c4).GetInstance(fooType); - Assert.AreEqual(f4.getFooness(), 12); - - IConfigurationSerializer serializerImpl = (IConfigurationSerializer)TangFactory.GetTang().NewInjector().GetInstance(typeof(IConfigurationSerializer)); - serializerImpl.ToFile(c, "TangTestCs1.avro"); - var c5 = serializerImpl.FromFile("TangTestCs1.avro"); - IFoo f5 = (IFoo)TangFactory.GetTang().NewInjector(c5).GetInstance(fooType); - Assert.AreEqual(f5.getFooness(), 12); - - //this is to test the file generated from Java. name,value b=must be recognized by C# class hierarchy - AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); - var avroConfig = serializer.AvroDeseriaizeFromFile("Evaluator.conf"); - Assert.IsNotNull(avroConfig); - } - - [TestMethod] - public void OmitOptionalTest() - { - Type fooType = typeof(Org.Apache.Reef.Tang.Test.Format.IFoo); - - IConfiguration c = MyConfigurationModule.Conf - .Set(MyConfigurationModule.TheFoo, GenericType<FooImpl>.Class) - .Build(); - IFoo f = (IFoo)TangFactory.GetTang().NewInjector(c).GetInstance(fooType); - Assert.AreEqual(f.getFooness(), 42); - } - - [TestMethod] - public void OmitRequiredTest() - { - string msg = null; - try - { - MyConfigurationModule.Conf - .Set(MyConfigurationModule.FooNess, "12") - .Build(); - msg = "Attempt to build configuration before setting required option(s): { THE_FOO }"; - } - catch (Exception) - { - } - Assert.IsNull(msg); - } - - [TestMethod] - public void BadConfTest() - { - string msg = null; - try - { - object obj = MyMissingBindConfigurationModule.BadConf; - msg = "Found declared options that were not used in binds: { FOO_NESS }" + obj; - } - catch (Exception) - { - } - Assert.IsNull(msg); - } - - [TestMethod] - public void NonExistentStringBindOK() - { - new MyBadConfigurationModule().BindImplementation(GenericType<IFoo>.Class, "i.do.not.exist"); - } - - [TestMethod] - public void NonExistentStringBindNotOK() - { - string msg = null; - try - { - new MyBadConfigurationModule().BindImplementation(GenericType<IFoo>.Class, "i.do.not.exist").Build(); - msg = "ConfigurationModule refers to unknown class: i.do.not.exist"; - } - catch (Exception) - { - } - Assert.IsNull(msg); - } - - [TestMethod] - public void MultiBindTest() - { - // Here we set some configuration values. In true tang style, - // you won't be able to set them more than once ConfigurationModule's - // implementation is complete. - IConfiguration c = MultiBindConfigurationModule.Conf - .Set(MultiBindConfigurationModule.TheFoo, GenericType<FooImpl>.Class) - .Set(MultiBindConfigurationModule.FOONESS, "12") - .Build(); - IFoo f = (IFoo)TangFactory.GetTang().NewInjector(c).GetInstance(typeof(IFoo)); - IFoo g = (IFoo)TangFactory.GetTang().NewInjector(c).GetInstance(typeof(object)); - Assert.AreEqual(f.getFooness(), 12); - Assert.AreEqual(g.getFooness(), 12); - Assert.IsFalse(f == g); - } - - [TestMethod] - public void ForeignSetTest() - { - string msg = null; - try - { - MultiBindConfigurationModule.Conf.Set(MyConfigurationModule.TheFoo, GenericType<FooImpl>.Class); - msg = "Unknown Impl/Param when setting RequiredImpl. Did you pass in a field from some other module?"; - } - catch (Exception) - { - } - Assert.IsNull(msg); - } - - [TestMethod] - public void ForeignBindTest() - { - string msg = null; - try - { - new MyConfigurationModule().BindImplementation(GenericType<object>.Class, MultiBindConfigurationModule.TheFoo); - msg = "Unknown Impl/Param when binding RequiredImpl. Did you pass in a field from some other module?"; - } - catch (Exception) - { - } - Assert.IsNull(msg); - } - - [TestMethod] - public void SingletonTest() - { - IConfiguration c = new MyConfigurationModule() - .BindImplementation(GenericType<IFoo>.Class, MyConfigurationModule.TheFoo) - .BindNamedParameter(GenericType<Fooness>.Class, MyConfigurationModule.FooNess) - .Build() - .Set(MyConfigurationModule.TheFoo, GenericType<FooImpl>.Class) - .Build(); - IInjector i = TangFactory.GetTang().NewInjector(c); - Assert.IsTrue(i.GetInstance(typeof(IFoo)) == i.GetInstance(typeof(IFoo))); - } - - [TestMethod] - public void ImmutablilityTest() - { - // builder methods return copies; the original module is immutable - ConfigurationModule builder1 = MyConfigurationModule.Conf - .Set(MyConfigurationModule.TheFoo, GenericType<FooImpl>.Class); - - Assert.IsFalse(builder1 == MyConfigurationModule.Conf); - - IConfiguration config1 = builder1.Build(); - - // reusable - IConfiguration config2 = MyConfigurationModule.Conf - .Set(MyConfigurationModule.TheFoo, GenericType<FooAltImpl>.Class) - .Build(); - - // instantiation of each just to be sure everything is fine in this situation - IInjector i1 = TangFactory.GetTang().NewInjector(config1); - IInjector i2 = TangFactory.GetTang().NewInjector(config2); - Assert.AreEqual(42, ((IFoo)i1.GetInstance(typeof(IFoo))).getFooness()); - Assert.AreEqual(7, ((IFoo)i2.GetInstance(typeof(IFoo))).getFooness()); - } - - [TestMethod] - public void SetParamTest() - { - IConfiguration c = SetConfigurationModule.CONF - .Set(SetConfigurationModule.P, "a") - .Set(SetConfigurationModule.P, "b") - .Build(); - - ISet<string> s = (ISet<string>)TangFactory.GetTang().NewInjector(c).GetNamedInstance(typeof(SetName)); - Assert.AreEqual(s.Count, 2); - Assert.IsTrue(s.Contains("a")); - Assert.IsTrue(s.Contains("b")); - } - - [TestMethod] - public void SetClassTest() - { - IConfiguration c = SetClassConfigurationModule.CONF - .Set(SetClassConfigurationModule.P, GenericType<SubA>.Class) - .Set(SetClassConfigurationModule.P, GenericType<SubB>.Class) - .Build(); - ISet<ISuper> s = (ISet<ISuper>)TangFactory.GetTang().NewInjector(c).GetNamedInstance(typeof(SetClass)); - Assert.AreEqual(2, s.Count); - - bool sawA = false, sawB = false; - foreach (ISuper sup in s) - { - if (sup is SubA) - { - sawA = true; - } - else if (sup is SubB) - { - sawB = true; - } - else - { - Assert.Fail(); - } - } - Assert.IsTrue(sawA && sawB); - } - - [TestMethod] - public void SetClassRoundTripTest() - { - IConfiguration c = SetClassConfigurationModule.CONF - .Set(SetClassConfigurationModule.P, GenericType<SubA>.Class) - .Set(SetClassConfigurationModule.P, GenericType<SubB>.Class) - .Build(); - IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(c); - - AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); - IConfiguration c2 = serializer.FromString(serializer.ToString(cb.Build())); - - //ConfigurationFile.AddConfiguration(cb, ConfigurationFile.ToConfigurationString(c)); - ISet<ISuper> s = (ISet<ISuper>)TangFactory.GetTang().NewInjector(c2).GetNamedInstance(typeof(SetClass)); - Assert.AreEqual(2, s.Count); - bool sawA = false, sawB = false; - foreach (ISuper sup in s) - { - if (sup is SubA) - { - sawA = true; - } - else if (sup is SubB) - { - sawB = true; - } - else - { - Assert.Fail(); - } - } - Assert.IsTrue(sawA && sawB); - } - - [TestMethod] - public void ErrorOnStaticTimeSet() - { - string msg = null; - try - { - StaticTimeSet.CONF.AssertStaticClean(); - msg = - " Detected statically set ConfigurationModule Parameter / Implementation. set() should only be used dynamically. Use bind...() instead."; - } - catch (ClassHierarchyException) - { - } - Assert.IsNull(msg); - } - - [TestMethod] - public void ErrorOnSetMerge() - { - ConfigurationModuleBuilder cb = null; - try - { - ConfigurationModuleBuilder b = new ConfigurationModuleBuilder(); - cb = b.Merge(StaticTimeSet.CONF); - } - catch (ClassHierarchyException e) - { - System.Diagnostics.Debug.WriteLine(e); - } - Assert.IsNull(cb); - } - } - - [NamedParameter("Fooness", "Fooness", "42")] - public class Fooness : Name<int> - { - } - - public class FooImpl : IFoo - { - private readonly int fooness; - - [Inject] - FooImpl([Parameter(typeof(Fooness))] int fooness) - { - this.fooness = fooness; - } - - public int getFooness() - { - return this.fooness; - } - } - - public class FooAltImpl : IFoo - { - private readonly int fooness; - - [Inject] - FooAltImpl([Parameter(Value = typeof(Fooness))] int fooness) - { - this.fooness = fooness; - } - - public int getFooness() - { - return 7; - } - } - - public sealed class MyConfigurationModule : ConfigurationModuleBuilder - { - // Tell us what implementation you want, or else!! - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly RequiredImpl<IFoo> TheFoo = new RequiredImpl<IFoo>(); - - // If you want, you can change the fooness. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly OptionalParameter<int> FooNess = new OptionalParameter<int>(); - - // This binds the above to tang configuration stuff. You can use parameters more than - // once, but you'd better use them all at least once, or I'll throw exceptions at you. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly ConfigurationModule Conf = new MyConfigurationModule() - .BindImplementation(GenericType<IFoo>.Class, MyConfigurationModule.TheFoo) - .BindNamedParameter(GenericType<Fooness>.Class, MyConfigurationModule.FooNess) - .Build(); - } - - public class MyMissingBindConfigurationModule : ConfigurationModuleBuilder - { - // Tell us what implementation you want, or else!! - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly RequiredImpl<IFoo> TheFoo = new RequiredImpl<IFoo>(); - - // If you want, you can change the fooness. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly OptionalParameter<int> FooNess = new OptionalParameter<int>(); - - // This conf doesn't use FOO_NESS. Expect trouble below - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly ConfigurationModule BadConf = new MyMissingBindConfigurationModule() - .BindImplementation(GenericType<IFoo>.Class, MyMissingBindConfigurationModule.TheFoo) - .Build(); - } - - public class MyBadConfigurationModule : ConfigurationModuleBuilder - { - } - - public class MultiBindConfigurationModule : ConfigurationModuleBuilder - { - // Tell us what implementation you want, or else!! - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly RequiredImpl<IFoo> TheFoo = new RequiredImpl<IFoo>(); - - // If you want, you can change the fooness. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly OptionalParameter<int> FOONESS = new OptionalParameter<int>(); - - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Required by Tang")] - public static readonly ConfigurationModule Conf = new MultiBindConfigurationModule() - .BindImplementation(GenericType<IFoo>.Class, MultiBindConfigurationModule.TheFoo) - .BindImplementation(GenericType<object>.Class, MultiBindConfigurationModule.TheFoo) - .BindNamedParameter(GenericType<Fooness>.Class, MultiBindConfigurationModule.FOONESS) - .Build(); - } - - [NamedParameter] - class SetName : Name<ISet<string>> - { - } - - class SetConfigurationModule : ConfigurationModuleBuilder - { - public static readonly RequiredParameter<string> P = new RequiredParameter<string>(); - - public static readonly ConfigurationModule CONF = new SetConfigurationModule() - .BindSetEntry(GenericType<SetName>.Class, SetConfigurationModule.P) - .Build(); - } - - [NamedParameter] - class SetClass : Name<ISet<ISuper>> - { - } - - class SetClassConfigurationModule : ConfigurationModuleBuilder - { - public static readonly RequiredParameter<ISuper> P = new RequiredParameter<ISuper>(); - public static readonly ConfigurationModule CONF = new SetClassConfigurationModule() - .BindSetEntry(GenericType<SetClass>.Class, SetClassConfigurationModule.P) - .Build(); - } - - class SubA : ISuper - { - [Inject] - public SubA() - { - } - } - - class SubB : ISuper - { - [Inject] - public SubB() - { - } - } - - class StaticTimeSet : ConfigurationModuleBuilder - { - public static readonly OptionalImpl<ISuper> X = new OptionalImpl<ISuper>(); - public static readonly ConfigurationModule CONF = new StaticTimeSet() - .BindImplementation(GenericType<ISuper>.Class, X) - .Build() - .Set(X, GenericType<SubA>.Class); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Format/TestConfigurationModuleForList.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Format/TestConfigurationModuleForList.cs b/lang/cs/Tests/TangTests/Format/TestConfigurationModuleForList.cs deleted file mode 100644 index b560ec0..0000000 --- a/lang/cs/Tests/TangTests/Format/TestConfigurationModuleForList.cs +++ /dev/null @@ -1,145 +0,0 @@ -/** - * 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; -using System.Collections.Generic; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Formats; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Format -{ - interface IListSuper - { - } - - [TestClass] - public class TestConfigurationModuleForList - { - //ConfigurationModuleBuilder BindList<U, T>(GenericType<U> iface, IParam<IList<T>> opt) - //public ConfigurationModule Set<T>(IImpl<IList<T>> opt, IList<string> impl) - [TestMethod] - public void ListParamTest() - { - IList<string> v = new List<string>(); - v.Add("a"); - v.Add("b"); - - IConfiguration c = ListConfigurationModule.CONF - .Set(ListConfigurationModule.P, v) - .Build(); - - IList<string> s = (IList<string>)TangFactory.GetTang().NewInjector(c).GetNamedInstance(typeof(ListName)); - Assert.AreEqual(s.Count, 2); - Assert.IsTrue(s.Contains("a")); - Assert.IsTrue(s.Contains("b")); - } - - // public ConfigurationModuleBuilder BindList<U, T>(GenericType<U> iface, IImpl<IList<T>> opt) where U : Name<IList<T>> - // public ConfigurationModule Set<T>(IImpl<IList<T>> opt, IList<Type> impl) - [TestMethod] - public void ListImplTest() - { - IList<Type> v = new List<Type>(); - v.Add(typeof(ListSubA)); - v.Add(typeof(ListSubB)); - - IConfiguration c = ListClassConfigurationModule.CONF - .Set(ListClassConfigurationModule.P, v) - .Build(); - - IList<IListSuper> s = (IList<IListSuper>)TangFactory.GetTang().NewInjector(c).GetNamedInstance(typeof(ListClass)); - Assert.AreEqual(s.Count, 2); - Assert.IsTrue(s[0] is ListSubA); - Assert.IsTrue(s[1] is ListSubB); - } - - //public ConfigurationModuleBuilder BindList<U, T>(GenericType<U> iface, IList<string> impl) - [TestMethod] - public void ListStringTest() - { - IConfiguration c = ListIntConfigurationModule.CONF - .Build(); - - IList<int> i = (IList<int>)TangFactory.GetTang().NewInjector(c).GetNamedInstance(typeof(ListIntName)); - Assert.AreEqual(i.Count, 2); - Assert.IsTrue(i.Contains(1)); - Assert.IsTrue(i.Contains(2)); - } - } - - [NamedParameter] - class ListName : Name<IList<string>> - { - } - - class ListConfigurationModule : ConfigurationModuleBuilder - { - public static readonly RequiredParameter<IList<string>> P = new RequiredParameter<IList<string>>(); - - public static readonly ConfigurationModule CONF = new ListConfigurationModule() - .BindList(GenericType<ListName>.Class, ListConfigurationModule.P) - .Build(); - } - - [NamedParameter] - class ListClass : Name<IList<IListSuper>> - { - } - - class ListClassConfigurationModule : ConfigurationModuleBuilder - { - public static readonly RequiredImpl<IList<IListSuper>> P = new RequiredImpl<IList<IListSuper>>(); - - public static readonly ConfigurationModule CONF = new ListClassConfigurationModule() - .BindList(GenericType<ListClass>.Class, ListClassConfigurationModule.P) - .Build(); - } - - class ListSubA : IListSuper - { - [Inject] - public ListSubA() - { - } - } - - class ListSubB : IListSuper - { - [Inject] - public ListSubB() - { - } - } - - [NamedParameter] - class ListIntName : Name<IList<int>> - { - } - - class ListIntConfigurationModule : ConfigurationModuleBuilder - { - public static readonly ConfigurationModule CONF = new ListIntConfigurationModule() - .BindList<ListIntName, int>(GenericType<ListIntName>.Class, (new List<string>(new string[] { "1", "2" }))) - .Build(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Format/TestTaskConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Format/TestTaskConfiguration.cs b/lang/cs/Tests/TangTests/Format/TestTaskConfiguration.cs deleted file mode 100644 index 7d77602..0000000 --- a/lang/cs/Tests/TangTests/Format/TestTaskConfiguration.cs +++ /dev/null @@ -1,389 +0,0 @@ -/** - * 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; -using System.Collections.Generic; -using Org.Apache.Reef.Tasks; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Formats; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Format -{ - public interface ISuspendEvent - { - string GetId(); - } - - public interface IDriverMessage - { - string GetId(); - } - - public interface ITaskMessageSource - { - string GetId(); - } - - public interface ITaskStop - { - string GetId(); - } - - public interface IEventHandler<T> - { - void OnNext(T t); - } - - public interface ITaskStart - { - string GetId(); - } - - public interface ICloseEvent - { - string GetId(); - } - - [TestClass] - public class TestTaskConfiguration - { - [TestMethod] - public void TaskConfigurationTestWith3Parameters() - { - TaskConfigurationWith3Parameters.Conf - .Set(TaskConfigurationWith3Parameters.ONCLOSE, GenericType<TaskCloseHandler>.Class) - .Build(); - } - - [TestMethod] - public void TaskConfigurationWithMyEventHandlerTest() - { - TaskConfigurationWithMyEventHandler.Conf - .Set(TaskConfigurationWithMyEventHandler.ONCLOSE2, GenericType<MyTaskCloseHandler>.Class) - .Build(); - } - - [TestMethod] - public void TaskConfigurationTest() - { - IConfiguration conf1 = TaskConfiguration.Conf - .Set(TaskConfiguration.IDENTIFIER, "sample task") - .Set(TaskConfiguration.TASK, GenericType<HelloTask>.Class) - .Set(TaskConfiguration.ONCLOSE, GenericType<TaskCloseHandler>.Class) - .Set(TaskConfiguration.MEMENTO, "Test") - .Set(TaskConfiguration.ONSUSPEND, GenericType<SuspendHandler>.Class) - .Set(TaskConfiguration.ONMESSAGE, - GenericType<DriverMessageHandler>.Class) - .Set(TaskConfiguration.ONSENDMESSAGE, GenericType<TaskMsg>.Class) - .Set(TaskConfiguration.ONTASKSTARTED, - GenericType<TaskStartHandler>.Class) - .Set(TaskConfiguration.ONTASKSTOP, - GenericType<TaskStopHandler>.Class) - .Build(); - - IInjector injector1 = TangFactory.GetTang().NewInjector(conf1); - var task1 = (Org.Apache.Reef.Tasks.HelloTask)injector1.GetInstance(typeof(ITask)); - Assert.IsNotNull(task1); - - var serializer = new AvroConfigurationSerializer(); - byte[] bytes = serializer.ToByteArray(conf1); - IConfiguration conf2 = serializer.FromByteArray(bytes); - - IInjector injector2 = TangFactory.GetTang().NewInjector(conf2); - var task2 = (Org.Apache.Reef.Tasks.HelloTask)injector2.GetInstance(typeof(ITask)); - Assert.IsNotNull(task2); - } - - [TestMethod] - public void TaskConfigurationSerializationTest() - { - IConfiguration conf1 = TaskConfiguration.Conf - .Set(TaskConfiguration.IDENTIFIER, "sample task") - .Set(TaskConfiguration.TASK, GenericType<HelloTask>.Class) - .Set(TaskConfiguration.ONCLOSE, GenericType<TaskCloseHandler>.Class) - .Set(TaskConfiguration.MEMENTO, "Test") - .Set(TaskConfiguration.ONSUSPEND, GenericType<SuspendHandler>.Class) - .Set(TaskConfiguration.ONMESSAGE, GenericType<DriverMessageHandler>.Class) - .Set(TaskConfiguration.ONSENDMESSAGE, GenericType<TaskMsg>.Class) - .Set(TaskConfiguration.ONTASKSTARTED, GenericType<TaskStartHandler>.Class) - .Set(TaskConfiguration.ONTASKSTOP, GenericType<TaskStopHandler>.Class) - .Build(); - - IInjector injector1 = TangFactory.GetTang().NewInjector(conf1); - var task1 = (Org.Apache.Reef.Tasks.HelloTask)injector1.GetInstance(typeof(ITask)); - Assert.IsNotNull(task1); - - var serializer = new AvroConfigurationSerializer(); - byte[] bytes = serializer.ToByteArray(conf1); - IConfiguration conf2 = serializer.FromByteArray(bytes); - - IInjector injector2 = TangFactory.GetTang().NewInjector(conf2); - var task2 = (Org.Apache.Reef.Tasks.HelloTask)injector2.GetInstance(typeof(ITask)); - Assert.IsNotNull(task2); - - serializer.ToFileStream(conf1, "TaskConfiguration.bin"); - IConfiguration conf3 = serializer.FromFileStream("TaskConfiguration.bin"); - - IInjector injector3 = TangFactory.GetTang().NewInjector(conf3); - var task3 = (Org.Apache.Reef.Tasks.HelloTask)injector3.GetInstance(typeof(ITask)); - Assert.IsNotNull(task3); - } - } - - public class TaskConfigurationWith3Parameters : ConfigurationModuleBuilder - { - public static readonly OptionalImpl<IEventHandler<ICloseEvent>> ONCLOSE = new OptionalImpl<IEventHandler<ICloseEvent>>(); - - public static ConfigurationModule Conf - { - get - { - return new TaskConfigurationWith3Parameters() - .BindNamedParameter<TaskConfigurationOptions.CloseHandler, IEventHandler<ICloseEvent>, IEventHandler<ICloseEvent>>(GenericType<TaskConfigurationOptions.CloseHandler>.Class, ONCLOSE) - .Build(); - } - } - } - - public class TaskConfiguration : ConfigurationModuleBuilder - { - public static readonly OptionalImpl<IEventHandler<ICloseEvent>> ONCLOSE = new OptionalImpl<IEventHandler<ICloseEvent>>(); - public static readonly RequiredParameter<string> IDENTIFIER = new RequiredParameter<string>(); - public static readonly RequiredImpl<ITask> TASK = new RequiredImpl<ITask>(); - public static readonly OptionalImpl<IEventHandler<ISuspendEvent>> ONSUSPEND = new OptionalImpl<IEventHandler<ISuspendEvent>>(); - public static readonly OptionalImpl<IEventHandler<IDriverMessage>> ONMESSAGE = new OptionalImpl<IEventHandler<IDriverMessage>>(); - public static readonly OptionalParameter<string> MEMENTO = new OptionalParameter<string>(); - public static readonly OptionalImpl<ITaskMessageSource> ONSENDMESSAGE = new OptionalImpl<ITaskMessageSource>(); - public static readonly OptionalImpl<IEventHandler<ITaskStart>> ONTASKSTARTED = new OptionalImpl<IEventHandler<ITaskStart>>(); - public static readonly OptionalImpl<IEventHandler<ITaskStop>> ONTASKSTOP = new OptionalImpl<IEventHandler<ITaskStop>>(); - - public static ConfigurationModule Conf - { - get - { - return new TaskConfiguration() - .BindNamedParameter(GenericType<TaskConfigurationOptions.Identifier>.Class, IDENTIFIER) - .BindImplementation(GenericType<ITask>.Class, TASK) - .BindNamedParameter(GenericType<TaskConfigurationOptions.Memento>.Class, MEMENTO) - .BindNamedParameter(GenericType<TaskConfigurationOptions.CloseHandler>.Class, ONCLOSE) - .BindNamedParameter(GenericType<TaskConfigurationOptions.SuspendHandler>.Class, ONSUSPEND) - .BindNamedParameter(GenericType<TaskConfigurationOptions.MessageHandler>.Class, ONMESSAGE) - .BindSetEntry(GenericType<TaskConfigurationOptions.TaskMessageSources>.Class, ONSENDMESSAGE) - .BindSetEntry(GenericType<TaskConfigurationOptions.StartHandlers>.Class, ONTASKSTARTED) - .BindSetEntry(GenericType<TaskConfigurationOptions.StopHandlers>.Class, ONTASKSTOP) - .Build(); - } - } - } - - public class TaskConfigurationWithMyEventHandler : ConfigurationModuleBuilder - { - public static readonly OptionalImpl<MyEventHandler<ICloseEvent>> ONCLOSE2 = new OptionalImpl<MyEventHandler<ICloseEvent>>(); - - public static ConfigurationModule Conf - { - get - { - return new TaskConfigurationWithMyEventHandler() - .BindNamedParameter<MyTaskConfigurationOptions.MyCloseHandler, MyEventHandler<ICloseEvent>, IEventHandler<ICloseEvent>>(GenericType<MyTaskConfigurationOptions.MyCloseHandler>.Class, ONCLOSE2) - .Build(); - } - } - } - - public class MyEventHandler<T> : IEventHandler<T> - { - public void OnNext(T t) - { - } - } - - public class TaskConfigurationOptions - { - [NamedParameter(DefaultValue = "Unnamed Task", Documentation = "The Identifier of the Task")] - public class Identifier : Name<string> - { - } - - [NamedParameter(Documentation = "The event handler that receives the close event", DefaultClass = typeof(DefaultCloseHandler))] - public class CloseHandler : Name<IEventHandler<ICloseEvent>> - { - } - - [NamedParameter(Documentation = "The memento to be used for the Task.")] - public class Memento : Name<string> - { - } - - [NamedParameter(Documentation = "The event handler that receives the suspend event", DefaultClass = typeof(DefaultSuspendHandler))] - public class SuspendHandler : Name<IEventHandler<ISuspendEvent>> - { - } - - [NamedParameter(Documentation = "The event handler that receives messages from the driver", DefaultClass = typeof(DefaultDriverMessageHandler))] - public class MessageHandler : Name<IEventHandler<IDriverMessage>> - { - } - - [NamedParameter(Documentation = "TaskMessageSource instances.")] - public class TaskMessageSources : Name<ISet<ITaskMessageSource>> - { - } - - [NamedParameter(Documentation = "The set of event handlers for the TaskStart event.")] - public class StartHandlers : Name<ISet<IEventHandler<ITaskStart>>> - { - } - - [NamedParameter(Documentation = "The set of event handlers for the TaskStop event.")] - public class StopHandlers : Name<ISet<IEventHandler<ITaskStop>>> - { - } - } - - public class MyTaskConfigurationOptions - { - [NamedParameter(Documentation = "The event handler that receives the close event", DefaultClass = typeof(MyDefaultCloseHandler))] - public class MyCloseHandler : Name<IEventHandler<ICloseEvent>> - { - } - } - - public class DefaultCloseHandler : IEventHandler<ICloseEvent> - { - [Inject] - public DefaultCloseHandler() - { - } - - public void OnNext(ICloseEvent closeEvent) - { - } - } - - public class MyDefaultCloseHandler : MyEventHandler<ICloseEvent> - { - [Inject] - public MyDefaultCloseHandler() - { - } - } - - public class TaskCloseHandler : IEventHandler<ICloseEvent> - { - [Inject] - public TaskCloseHandler() - { - } - - public void OnNext(ICloseEvent closeEvent) - { - } - } - - public class MyTaskCloseHandler : MyEventHandler<ICloseEvent> - { - [Inject] - public MyTaskCloseHandler() - { - } - } - - public class DefaultSuspendHandler : IEventHandler<ISuspendEvent> - { - [Inject] - public DefaultSuspendHandler() - { - } - - public void OnNext(ISuspendEvent suspendEvent) - { - throw new Exception("No handler for SuspendEvent registered. event: " + suspendEvent); - } - } - - public class SuspendHandler : IEventHandler<ISuspendEvent> - { - public void OnNext(ISuspendEvent suspendEvent) - { - } - } - - public class DefaultDriverMessageHandler : IEventHandler<IDriverMessage> - { - [Inject] - public DefaultDriverMessageHandler() - { - } - - public void OnNext(IDriverMessage driverMessage) - { - throw new Exception("No DriverMessage handler bound. Message received:" + driverMessage); - } - } - - public class DriverMessageHandler : IEventHandler<IDriverMessage> - { - public void OnNext(IDriverMessage driverMessage) - { - } - } - - public class TaskStartHandler : IEventHandler<ITaskStart> - { - public void OnNext(ITaskStart t) - { - throw new NotImplementedException(); - } - } - - public class TaskStopHandler : IEventHandler<ITaskStop> - { - public void OnNext(ITaskStop t) - { - throw new NotImplementedException(); - } - } - - public class TaskMsg : ITask, ITaskMessageSource - { - [Inject] - public TaskMsg() - { - } - - public byte[] Call(byte[] memento) - { - throw new NotImplementedException(); - } - - public string GetId() - { - throw new NotImplementedException(); - } - - public void Dispose() - { - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestAmbigousConstructors.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestAmbigousConstructors.cs b/lang/cs/Tests/TangTests/Injection/TestAmbigousConstructors.cs deleted file mode 100644 index feb34ab..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestAmbigousConstructors.cs +++ /dev/null @@ -1,80 +0,0 @@ -/** - * 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; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Exceptions; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Injection -{ - [TestClass] - public class TestAmbigousConstructors - { - [TestMethod] - public void AmbigousConstructorTest() - { - //Cannot inject Org.Apache.Reef.Tang.Test.Injection.AmbigousConstructorClass, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //Ambiguous subplan Org.Apache.Reef.Tang.Test.Injection.AmbigousConstructorClass, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - // new Org.Apache.Reef.Tang.Test.Injection.AmbigousConstructorClass(System.String Org.Apache.Reef.Tang.Test.Injection.AmbigousConstructorClass+NamedString = foo, System.Int32 Org.Apache.Reef.Tang.Test.Injection.AmbigousConstructorClass+NamedInt = 8) - // new Org.Apache.Reef.Tang.Test.Injection.AmbigousConstructorClass(System.Int32 Org.Apache.Reef.Tang.Test.Injection.AmbigousConstructorClass+NamedInt = 8, System.String Org.Apache.Reef.Tang.Test.Injection.AmbigousConstructorClass+NamedString = foo) - //] - AmbigousConstructorClass obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<AmbigousConstructorClass.NamedString, string>(GenericType<AmbigousConstructorClass.NamedString>.Class, "foo"); - cb.BindNamedParameter<AmbigousConstructorClass.NamedInt, int>(GenericType<AmbigousConstructorClass.NamedInt>.Class, "8"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<AmbigousConstructorClass>(); - } - catch (InjectionException e) - { - System.Diagnostics.Debug.WriteLine(e); - } - Assert.IsNull(obj); - } - } - - class AmbigousConstructorClass - { - [Inject] - public AmbigousConstructorClass([Parameter(typeof(NamedString))] string s, [Parameter(typeof(NamedInt))] int i) - { - } - - [Inject] - public AmbigousConstructorClass([Parameter(typeof(NamedInt))] int i, [Parameter(typeof(NamedString))] string s) - { - } - - [NamedParameter] - public class NamedString : Name<string> - { - } - - [NamedParameter] - public class NamedInt : Name<int> - { - } - } -} \ No newline at end of file
