http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestMissingParamtersInNested.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestMissingParamtersInNested.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestMissingParamtersInNested.cs new file mode 100644 index 0000000..414552a --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestMissingParamtersInNested.cs @@ -0,0 +1,143 @@ +/** + * 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; +using Org.Apache.REEF.Tang.Implementations.Tang; + +namespace Org.Apache.REEF.Tang.Tests.Injection +{ + [TestClass] + public class TestMissingParamtersInNested + { + [TestMethod] + public void InnerParameterTest() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<ReferencedClass.NamedInt, int>(GenericType<ReferencedClass.NamedInt>.Class, "8"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<ReferencedClass>(); + Assert.IsNotNull(o); + } + + [TestMethod] + public void NestedParameterTest() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<OuterClass.NamedString, string>(GenericType<OuterClass.NamedString>.Class, "foo"); + cb.BindNamedParameter<ReferencedClass.NamedInt, int>(GenericType<ReferencedClass.NamedInt>.Class, "8"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<OuterClass>(); + Assert.IsNotNull(o); + } + + [TestMethod] + public void MissingAllParameterTest() + { + //Cannot inject Org.Apache.REEF.Tang.Tests.Injection.OuterClass, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: + //Org.Apache.REEF.Tang.Tests.Injection.ReferencedClass, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + //missing argument Org.Apache.REEF.Tang.Tests.Injection.ReferencedClass+NamedInt, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + OuterClass obj = null; + try + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + obj = i.GetInstance<OuterClass>(); + } + catch (InjectionException e) + { + System.Diagnostics.Debug.WriteLine(e); + } + Assert.IsNull(obj); + } + + [TestMethod] + public void MissingInnerParameterTest() + { + //Cannot inject Org.Apache.REEF.Tang.Tests.Injection.OuterClass, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: + //Org.Apache.REEF.Tang.Tests.Injection.ReferencedClass, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + //missing argument Org.Apache.REEF.Tang.Tests.Injection.ReferencedClass+NamedInt, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + OuterClass obj = null; + try + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<OuterClass.NamedString, string>(GenericType<OuterClass.NamedString>.Class, "foo"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + obj = i.GetInstance<OuterClass>(); + } + catch (InjectionException e) + { + System.Diagnostics.Debug.WriteLine(e); + } + Assert.IsNull(obj); + } + + [TestMethod] + public void MissingOuterParameterTest() + { + //Cannot inject Org.Apache.REEF.Tang.Tests.Injection.OuterClass, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: + //Org.Apache.REEF.Tang.Tests.Injection.OuterClass, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + //missing argument Org.Apache.REEF.Tang.Tests.Injection.OuterClass+NamedString, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + OuterClass obj = null; + try + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<ReferencedClass.NamedInt, int>(GenericType<ReferencedClass.NamedInt>.Class, "8"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + obj = i.GetInstance<OuterClass>(); + } + catch (InjectionException e) + { + System.Diagnostics.Debug.WriteLine(e); + } + Assert.IsNull(obj); + } + } + + class OuterClass + { + [Inject] + public OuterClass([Parameter(typeof(NamedString))] string s, ReferencedClass refCls) + { + } + + [NamedParameter] + public class NamedString : Name<string> + { + } + } + + class ReferencedClass + { + [Inject] + public ReferencedClass([Parameter(typeof(NamedInt))] int i) + { + } + + [NamedParameter] + public class NamedInt : Name<int> + { + } + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestMultipleConstructors.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestMultipleConstructors.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestMultipleConstructors.cs new file mode 100644 index 0000000..e0c5fd6 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestMultipleConstructors.cs @@ -0,0 +1,361 @@ +/** + * 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; +using Org.Apache.REEF.Tang.Implementations.Tang; + +namespace Org.Apache.REEF.Tang.Tests.Injection +{ + public interface IH + { + } + + [TestClass] + public class TestMultipleConstructors + { + [TestMethod] + public void TestMissingAllParameters() + { + //Multiple infeasible plans: Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + //, Org.Apache.REEF.Tang.Test + //, Version=1.0.0.0 + //, Culture=neutral + //, PublicKeyToken=null: + + // [ Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest = new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool = + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString = + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool = + // , System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString = + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // ] + MultiConstructorTest obj = null; + try + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + obj = i.GetInstance<MultiConstructorTest>(); + } + catch (InjectionException) + { + } + Assert.IsNull(obj); + } + + [TestMethod] + public void TestMissingIntParameter() + { + //Multiple infeasible plans: Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + //, Org.Apache.REEF.Tang.Test + //, Version=1.0.0.0 + //, Culture=neutral + //, PublicKeyToken=null: + // [ Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest = new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool = False + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString = foo + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool = False + // , System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString = foo + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // ] + MultiConstructorTest obj = null; + try + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<MultiConstructorTest.NamedString, string>(GenericType<MultiConstructorTest.NamedString>.Class, "foo"); + cb.BindNamedParameter<MultiConstructorTest.NamedBool, bool>(GenericType<MultiConstructorTest.NamedBool>.Class, "true"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + obj = i.GetInstance<MultiConstructorTest>(); + } + catch (InjectionException) + { + } + Assert.IsNull(obj); + } + + [TestMethod] + public void TestOnlyBoolParameter() + { + //Multiple infeasible plans: Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + //, Org.Apache.REEF.Tang.Test + //, Version=1.0.0.0 + //, Culture=neutral + //, PublicKeyToken=null: + // [ Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest = new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool = False + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString = + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool = False + // , System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString = + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = + // ) + // ] + MultiConstructorTest obj = null; + try + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<MultiConstructorTest.NamedBool, bool>(GenericType<MultiConstructorTest.NamedBool>.Class, "true"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + obj = i.GetInstance<MultiConstructorTest>(); + } + catch (InjectionException) + { + } + Assert.IsNull(obj); + } + + [TestMethod] + public void TestOnlyIntParameter() + { + //Multiple infeasible plans: Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + //, Org.Apache.REEF.Tang.Test + //, Version=1.0.0.0 + //, Culture=neutral + //, PublicKeyToken=null: + // [ Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest = new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool = + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = 8 + // ) + // | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString = + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = 8 + // ) + // | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest + // ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool = + // , System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString = + // , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt = 8 + // ) + // ] + MultiConstructorTest obj = null; + try + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<MultiConstructorTest.NamedInt, int>(GenericType<MultiConstructorTest.NamedInt>.Class, "8"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + obj = i.GetInstance<MultiConstructorTest>(); + } + catch (InjectionException) + { + } + Assert.IsNull(obj); + } + + [TestMethod] + public void TestMultipleConstructor() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<MultiConstructorTest.NamedString, string>(GenericType<MultiConstructorTest.NamedString>.Class, "foo"); + cb.BindNamedParameter<MultiConstructorTest.NamedInt, int>(GenericType<MultiConstructorTest.NamedInt>.Class, "8"); + cb.BindNamedParameter<MultiConstructorTest.NamedBool, bool>(GenericType<MultiConstructorTest.NamedBool>.Class, "true"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<MultiConstructorTest>(); + o.Verify("foo", 8, true); + } + + [TestMethod] + public void TestMultiLayersWithMiddleLayerFirst() + { + TangImpl.Reset(); + ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); + cb2.BindImplementation(typeof(IH), typeof(M)); + IInjector i2 = TangFactory.GetTang().NewInjector(cb2.Build()); + var o2 = i2.GetInstance<IH>(); + Assert.IsTrue(o2 is M); + + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindImplementation(typeof(IH), typeof(L)); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<IH>(); + Assert.IsTrue(o is L); + } + + [TestMethod] + public void TestMultiLayersWithLowerLayerFirst() + { + TangImpl.Reset(); + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindImplementation(typeof(IH), typeof(L)); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<IH>(); + Assert.IsTrue(o is L); + + ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); + cb2.BindImplementation(typeof(IH), typeof(M)); + IInjector i2 = TangFactory.GetTang().NewInjector(cb2.Build()); + var o2 = i2.GetInstance<IH>(); + Assert.IsTrue(o2 is M); + } + + [TestMethod] + public void TestMultiLayersWithBindImpl() + { + TangImpl.Reset(); + + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindImplementation(typeof(IH), typeof(L)); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<IH>(); + Assert.IsTrue(o is L); + + ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); + cb2.BindImplementation(typeof(IH), typeof(M)); + cb2.BindImplementation(typeof(M), typeof(L)); //construcotr of L is explicitly bound + IInjector i2 = TangFactory.GetTang().NewInjector(cb2.Build()); + var o2 = i2.GetInstance<IH>(); + Assert.IsTrue(o2 is L); + } + + [TestMethod] + public void TestMultiLayersWithNoInjectableDefaultConstructor() + { + TangImpl.Reset(); + + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindImplementation(typeof(IH), typeof(L1)); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<IH>(); + Assert.IsNotNull(o); + + ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); + cb2.BindImplementation(typeof(IH), typeof(M1)); //M1 doesn't have injectable default constructor, no implementation L1 is bound to M1 + IInjector i2 = TangFactory.GetTang().NewInjector(cb2.Build()); + string msg = null; + try + { + var o2 = i2.GetInstance<IH>(); + Assert.IsTrue(o2 is L1); + } + catch (Exception e) + { + //Cannot inject Org.Apache.REEF.Tang.Tests.Injection.IH, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: + //No known implementations / injectable constructors for Org.Apache.REEF.Tang.Tests.Injection.M1, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + msg = e.Message; + } + Assert.IsNotNull(msg); + } + } + + public class MultiConstructorTest + { + private readonly string str; + private readonly int iVal; + private readonly bool bVal; + + [Inject] + public MultiConstructorTest([Parameter(typeof(NamedBool))] bool b, [Parameter(typeof(NamedInt))] int i) + { + this.bVal = b; + this.iVal = i; + this.bVal = false; + } + + [Inject] + public MultiConstructorTest([Parameter(typeof(NamedString))] string s, [Parameter(typeof(NamedInt))] int i) + { + this.str = s; + this.iVal = i; + this.bVal = false; + } + + [Inject] + public MultiConstructorTest([Parameter(typeof(NamedBool))] bool b, [Parameter(typeof(NamedString))] string s, [Parameter(typeof(NamedInt))] int i) + { + this.str = s; + this.iVal = i; + this.bVal = b; + } + + public void Verify(string s, int i, bool b) + { + Assert.AreEqual(str, s); + Assert.AreEqual(iVal, i); + Assert.AreEqual(bVal, b); + } + + [NamedParameter] + public class NamedString : Name<string> + { + } + + [NamedParameter] + public class NamedInt : Name<int> + { + } + + [NamedParameter] + public class NamedBool : Name<bool> + { + } + } + + class M : IH + { + [Inject] + public M() + { + } + } + + class L : M + { + [Inject] + public L() + { + } + } + + class M1 : IH + { + public M1() + { + } + } + + class L1 : M1 + { + [Inject] + public L1() + { + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestNamedParameter.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestNamedParameter.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestNamedParameter.cs new file mode 100644 index 0000000..e4dcd50 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestNamedParameter.cs @@ -0,0 +1,358 @@ +/** + * 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.Implementations; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Util; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.REEF.Tang.Implementations.Tang; + +namespace Org.Apache.REEF.Tang.Tests.Injection +{ + [TestClass] + public class TestNamedParameter + { + [TestMethod] + public void TestOptionalParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<StringTest.NamedString, string>(GenericType<StringTest.NamedString>.Class, "foo"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<StringTest>(); + o.Verify("foo"); + } + + [TestMethod] + public void TestOptionalParameterWithDefault() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<StringTest>(); + o.Verify(" "); + } + + [TestMethod] + public void TestBoolParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<BooleanTest.NamedBool, bool>(GenericType<BooleanTest.NamedBool>.Class, "true"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<BooleanTest>(); + o.Verify(true); + } + + [TestMethod] + public void TestBoolUpperCaseParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<BooleanTest.NamedBool, bool>(GenericType<BooleanTest.NamedBool>.Class, "True"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<BooleanTest>(); + o.Verify(true); + } + + [TestMethod] + public void TestBoolParameterWithDefault() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<BooleanTest>(); + o.Verify(false); + } + + [TestMethod] + public void TestByteParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<ByteTest.NamedByte, byte>(GenericType<ByteTest.NamedByte>.Class, "6"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<ByteTest>(); + o.Verify(6); + } + + [TestMethod] + public void TestByteArrayParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + string input = "abcde"; + cb.BindNamedParameter<ByteArrayTest.NamedByteArray, byte[]>(GenericType<ByteArrayTest.NamedByteArray>.Class, input); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<ByteArrayTest>(); + + byte[] bytes = new byte[input.Length * sizeof(char)]; + System.Buffer.BlockCopy(input.ToCharArray(), 0, bytes, 0, bytes.Length); + Assert.IsTrue(o.Verify(bytes)); + } + + [TestMethod] + public void TestCharParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<CharTest.NamedChar, char>(GenericType<CharTest.NamedChar>.Class, "C"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<CharTest>(); + o.Verify('C'); + } + + [TestMethod] + public void TestShortParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<Int16Test.NamedShort, short>(GenericType<Int16Test.NamedShort>.Class, "8"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<Int16Test>(); + o.Verify(8); + } + + [TestMethod] + public void TestIntParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<Int32Test.NamedInt, int>(GenericType<Int32Test.NamedInt>.Class, "8"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<Int32Test>(); + o.Verify(8); + } + + [TestMethod] + public void TestLongParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<Int64Test.NamedLong, long>(GenericType<Int64Test.NamedLong>.Class, "8777"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<Int64Test>(); + o.Verify(8777); + } + + [TestMethod] + public void TestFloatParameter() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindNamedParameter<FloatTest.NamedSingle, float>(GenericType<FloatTest.NamedSingle>.Class, "3.5"); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + var o = i.GetInstance<FloatTest>(); + float x = 3.5F; + o.Verify(x); + } + } + + public class StringTest + { + private readonly string str; + + [Inject] + public StringTest([Parameter(typeof(NamedString))] string s) + { + this.str = s; + } + + public void Verify(string s) + { + Assert.AreEqual(s, str); + } + + [NamedParameter(DefaultValue = " ")] + public class NamedString : Name<string> + { + } + } + + public class CharTest + { + private readonly char c; + + [Inject] + public CharTest([Parameter(typeof(NamedChar))] char c) + { + this.c = c; + } + + public void Verify(char s) + { + Assert.AreEqual(s, c); + } + + [NamedParameter(DefaultValue = " ")] + public class NamedChar : Name<char> + { + } + } + + public class ByteTest + { + private readonly byte b; + + [Inject] + public ByteTest([Parameter(typeof(NamedByte))] byte b) + { + this.b = b; + } + + public void Verify(byte v) + { + Assert.AreEqual(v, b); + } + + [NamedParameter(DefaultValue = "7")] + public class NamedByte : Name<byte> + { + } + } + + public class BooleanTest + { + private readonly bool b; + + [Inject] + public BooleanTest([Parameter(typeof(NamedBool))] bool b) + { + this.b = b; + } + + public void Verify(bool v) + { + Assert.AreEqual(v, b); + } + + [NamedParameter(DefaultValue = "false")] + public class NamedBool : Name<bool> + { + } + } + + public class ByteArrayTest + { + private readonly byte[] b; + + [Inject] + public ByteArrayTest([Parameter(typeof(NamedByteArray))] byte[] b) + { + this.b = b; + } + + public bool Verify(byte[] v) + { + if (v.Length != b.Length) + { + return false; + } + + for (int i = 0; i < v.Length; i++) + { + if (v[i] != b[i]) + { + return false; + } + } + + return true; + } + + [NamedParameter] + public class NamedByteArray : Name<byte[]> + { + } + } + + public class Int16Test + { + private readonly short s; + + [Inject] + public Int16Test([Parameter(typeof(NamedShort))] short s) + { + this.s = s; + } + + public void Verify(short v) + { + Assert.AreEqual(v, s); + } + + [NamedParameter(DefaultValue = "3")] + public class NamedShort : Name<short> + { + } + } + + public class Int32Test + { + private readonly int i; + + [Inject] + public Int32Test([Parameter(typeof(NamedInt))] int i) + { + this.i = i; + } + + public void Verify(int v) + { + Assert.AreEqual(v, i); + } + + [NamedParameter(DefaultValue = "3")] + public class NamedInt : Name<int> + { + } + } + + public class Int64Test + { + private readonly long l; + + [Inject] + public Int64Test([Parameter(typeof(NamedLong))] long l) + { + this.l = l; + } + + public void Verify(int v) + { + Assert.AreEqual(v, l); + } + + [NamedParameter(DefaultValue = "34567")] + public class NamedLong : Name<long> + { + } + } + + public class FloatTest + { + private readonly float f; + + [Inject] + public FloatTest([Parameter(typeof(NamedSingle))] float f) + { + this.f = f; + } + + public void Verify(float v) + { + Assert.AreEqual(v, f); + } + + [NamedParameter(DefaultValue = "12.5")] + public class NamedSingle : Name<float> + { + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestSetInjection.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestSetInjection.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestSetInjection.cs new file mode 100644 index 0000000..2170638 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestSetInjection.cs @@ -0,0 +1,740 @@ +/** + * 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; +using Org.Apache.REEF.Tang.Implementations.Tang; + +namespace Org.Apache.REEF.Tang.Tests.Injection +{ + public interface INumber : IComparable + { + } + + public interface ITimeshift + { + string LinkId { get; } + + TimeSpan TimeshiftSpan { get; } + } + + [TestClass] + public class TestSetInjection + { + [TestMethod] + public void TestStringInjectDefault() + { + Box b = (Box)TangFactory.GetTang().NewInjector().GetInstance(typeof(Box)); + + ISet<string> actual = b.Numbers; + + ISet<string> expected = new HashSet<string>(); + expected.Add("one"); + expected.Add("two"); + expected.Add("three"); + + Assert.IsTrue(actual.Contains("one")); + Assert.IsTrue(actual.Contains("two")); + Assert.IsTrue(actual.Contains("three")); + //Assert.AreEqual(expected, actual); + } + + [TestMethod] + public void TestObjectInjectDefault() + { + IInjector i = TangFactory.GetTang().NewInjector(); + i.BindVolatileInstance(GenericType<Integer>.Class, new Integer(42)); + i.BindVolatileInstance(GenericType<Float>.Class, new Float(42.0001f)); + ISet<INumber> actual = ((Pool)i.GetInstance(typeof(Pool))).Numbers; + ISet<INumber> expected = new HashSet<INumber>(); + expected.Add(new Integer(42)); + expected.Add(new Float(42.0001f)); + + Assert.IsTrue(actual.Contains(new Integer(42))); + Assert.IsTrue(actual.Contains(new Float(42.0001f))); + //Assert.AreEqual(expected, actual); + } + + [TestMethod] + public void testStringInjectBound() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "four"); + cb.BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "five"); + cb.BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "six"); + + Box b = (Box)TangFactory.GetTang().NewInjector(cb.Build()).GetInstance(typeof(Box)); + ISet<string> actual = b.Numbers; + ISet<string> expected = new HashSet<string>(); + expected.Add("four"); + expected.Add("five"); + expected.Add("six"); + + Assert.IsTrue(actual.Contains("four")); + Assert.IsTrue(actual.Contains("five")); + Assert.IsTrue(actual.Contains("six")); + } + + [TestMethod] + public void TestObjectInjectBound() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindSetEntry<SetOfClasses, Integer, INumber>(GenericType<SetOfClasses>.Class, GenericType<Integer>.Class); + cb.BindSetEntry<SetOfClasses, Float, INumber>(GenericType<SetOfClasses>.Class, GenericType<Float>.Class); + + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + i.BindVolatileInstance(GenericType<Integer>.Class, new Integer(4)); + i.BindVolatileInstance(GenericType<Float>.Class, new Float(42.0001f)); + + ISet<INumber> actual = i.GetInstance<Pool>().Numbers; + ISet<INumber> expected = new HashSet<INumber>(); + expected.Add(new Integer(4)); + expected.Add(new Float(42.0001f)); + Assert.IsTrue(Utilities.Utilities.Equals<INumber>(actual, expected)); + } + + [TestMethod] + public void TestSetOfClassBound() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindSetEntry<SetOfClasses, Integer1, INumber>(GenericType<SetOfClasses>.Class, GenericType<Integer1>.Class) //bind an impl to the interface of the set + .BindNamedParameter<Integer1.NamedInt, int>(GenericType<Integer1.NamedInt>.Class, "4"); //bind parameter for the impl + + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + + ISet<INumber> actual = i.GetInstance<Pool>().Numbers; + ISet<INumber> expected = new HashSet<INumber>(); + expected.Add(new Integer1(4)); + + Assert.IsTrue(Utilities.Utilities.Equals<INumber>(actual, expected)); + } + + [TestMethod] + public void TestSetOfClassWithDefault() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + + ISet<INumber> actual = i.GetInstance<Pool1>().Numbers; + Assert.IsNotNull(actual); + } + + [TestMethod] + public void TestSetOfTimeshift() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + + cb.BindSetEntry<SetOfTimeshifts, Timeshift, ITimeshift>(GenericType<SetOfTimeshifts>.Class, GenericType<Timeshift>.Class) + .BindNamedParameter<Timeshift.TimeshiftLinkId, string>(GenericType<Timeshift.TimeshiftLinkId>.Class, "123") + .BindNamedParameter<Timeshift.TimeshiftInTicks, long>(GenericType<Timeshift.TimeshiftInTicks>.Class, "10"); + + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + + ISet<ITimeshift> actual = i.GetInstance<SetofTimeShiftClass>().Timeshifts; + Assert.IsTrue(actual.Count == 1); + } + + [TestMethod] + public void TestSetOfTimeshiftMultipleInstances() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + + //when adding another Timeshift into the set for named parameter SetOfTimeshifts, it ends up the same entry. + cb.BindSetEntry<SetOfTimeshifts, Timeshift, ITimeshift>(GenericType<SetOfTimeshifts>.Class, GenericType<Timeshift>.Class); + cb.BindSetEntry<SetOfTimeshifts, Timeshift, ITimeshift>(GenericType<SetOfTimeshifts>.Class, GenericType<Timeshift>.Class); + cb.BindNamedParameter<Timeshift.TimeshiftLinkId, string>(GenericType<Timeshift.TimeshiftLinkId>.Class, "123") + .BindNamedParameter<Timeshift.TimeshiftInTicks, long>(GenericType<Timeshift.TimeshiftInTicks>.Class, "10"); + + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + + ISet<ITimeshift> actual = i.GetInstance<SetofTimeShiftClass>().Timeshifts; + Assert.IsTrue(actual.Count == 1); + } + + [TestMethod] + public void TestSetOfTimeshiftMultipleSubClasses() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + + //Adding implementations from different subclasses + cb.BindSetEntry<SetOfTimeshifts, Timeshift, ITimeshift>(GenericType<SetOfTimeshifts>.Class, GenericType<Timeshift>.Class); + cb.BindSetEntry<SetOfTimeshifts, Timeshift1, ITimeshift>(GenericType<SetOfTimeshifts>.Class, GenericType<Timeshift1>.Class); + + cb.BindNamedParameter<Timeshift.TimeshiftLinkId, string>(GenericType<Timeshift.TimeshiftLinkId>.Class, "123") + .BindNamedParameter<Timeshift.TimeshiftInTicks, long>(GenericType<Timeshift.TimeshiftInTicks>.Class, "10"); + + cb.BindNamedParameter<Timeshift1.TimeshiftLinkId, string>(GenericType<Timeshift1.TimeshiftLinkId>.Class, "456") + .BindNamedParameter<Timeshift1.TimeshiftInTicks, long>(GenericType<Timeshift1.TimeshiftInTicks>.Class, "20"); + + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + + ISet<ITimeshift> actual = i.GetInstance<SetofTimeShiftClass>().Timeshifts; + Assert.IsTrue(actual.Count == 2); + } + + [TestMethod] + public void TestSetOfTimeshiftWithDefault() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + + ISet<ITimeshift> actual = i.GetInstance<SetofTimeShiftClass>().Timeshifts; + Assert.IsTrue(actual.Count == 1); + } + + [TestMethod] + public void TestSetOfTimeshiftWithEmptySet() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + + IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); + + ISet<ITimeshift> actual = i.GetInstance<SetofTimeShiftClassWithoutDefault>().Timeshifts; + Assert.IsTrue(actual.Count == 0); + } + + [TestMethod] + public void TestObjectInjectRoundTrip() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindSetEntry<SetOfClasses, Integer, INumber>(GenericType<SetOfClasses>.Class, GenericType<Integer>.Class); + cb.BindSetEntry<SetOfClasses, Float, INumber>(GenericType<SetOfClasses>.Class, GenericType<Float>.Class); + + AvroConfigurationSerializer serializer = new AvroConfigurationSerializer(); + IConfiguration c2 = serializer.FromString(serializer.ToString(cb.Build())); + + IInjector i = TangFactory.GetTang().NewInjector(c2); + i.BindVolatileInstance(GenericType<Integer>.Class, new Integer(4)); + i.BindVolatileInstance(GenericType<Float>.Class, new Float(42.0001f)); + + ISet<INumber> actual = i.GetInstance<Pool>().Numbers; + ISet<INumber> expected = new HashSet<INumber>(); + expected.Add(new Integer(4)); + expected.Add(new Float(42.0001f)); + Assert.IsTrue(Utilities.Utilities.Equals<INumber>(actual, expected)); + } + + [TestMethod] + public void TestStringInjectRoundTrip() + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); + cb.BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "four"); + cb.BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "five"); + cb.BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "six"); + + string s = ConfigurationFile.ToConfigurationString(cb.Build()); + ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); + ConfigurationFile.AddConfigurationFromString(cb2, s); + + ISet<string> actual = + ((Box)TangFactory.GetTang().NewInjector(cb2.Build()).GetInstance(typeof(Box))).Numbers; + + Assert.IsTrue(actual.Contains("four")); + Assert.IsTrue(actual.Contains("five")); + Assert.IsTrue(actual.Contains("six")); + } + + [TestMethod] + public void TestDefaultAsClass() + { + IInjector i = TangFactory.GetTang().NewInjector(); + i.BindVolatileInstance(GenericType<Integer>.Class, new Integer(1)); + i.BindVolatileInstance(GenericType<Float>.Class, new Float(2f)); + ISet<INumber> actual = + (ISet<INumber>) + i.GetNamedInstance<SetOfClassesDefaultClass, ISet<INumber>>(GenericType<SetOfClassesDefaultClass>.Class); + + ISet<INumber> expected = new HashSet<INumber>(); + expected.Add(new Integer(1)); + Assert.AreEqual(expected.Count, actual.Count); + Assert.IsTrue(actual.Contains(new Integer(1))); + } + + [TestMethod] + public void TestInjectionExtension() + { + IInjector i = TangFactory.GetTang().NewInjector(); + i.BindVolatileInstance<Integer>(new Integer(1)); + i.BindVolatileInstance<Float>(new Float(2f)); + ISet<INumber> actual = + (ISet<INumber>) + i.GetNamedInstance<SetOfClassesDefaultClass, ISet<INumber>>(); + + ISet<INumber> expected = new HashSet<INumber>(); + expected.Add(new Integer(1)); + Assert.AreEqual(expected.Count, actual.Count); + Assert.IsTrue(actual.Contains(new Integer(1))); + } + + [NamedParameter(DefaultValues = new string[] { "one", "two", "three" })] + public class SetOfNumbers : Name<ISet<string>> + { + } + + public class Box + { + [Inject] + public Box([Parameter(typeof(SetOfNumbers))] ISet<string> numbers) + { + this.Numbers = numbers; + } + + public ISet<string> Numbers { get; set; } + } + + [NamedParameter(DefaultClasses = new Type[] { typeof(Integer), typeof(Float) })] + public class SetOfClasses : Name<ISet<INumber>> + { + } + + public class Pool + { + [Inject] + private Pool([Parameter(typeof(SetOfClasses))] ISet<INumber> numbers) + { + this.Numbers = numbers; + } + + public ISet<INumber> Numbers { get; set; } + } + + [NamedParameter(DefaultClass = typeof(Integer))] + public class SetOfClassesDefaultClass : Name<ISet<INumber>> + { + } + + public class Integer : INumber + { + private int val; + + public Integer(int v) + { + val = v; + } + + public int CompareTo(object obj) + { + if (!(obj is Integer)) + { + return -1; + } + if (this.val == ((Integer)obj).val) + { + return 0; + } + + if (this.val < ((Integer)obj).val) + { + return -1; + } + + return 1; + } + + public override bool Equals(object obj) + { + if (!(obj is Integer)) + { + return false; + } + + if (this.val == ((Integer)obj).val) + { + return true; + } + + return false; + } + + public override int GetHashCode() + { + return val.GetHashCode(); + } + } + + public class Float : INumber + { + private float val; + + [Inject] + public Float(float v) + { + val = v; + } + + public int CompareTo(object obj) + { + if (!(obj is Float)) + { + return -1; + } + + if (val == ((Float)obj).val) + { + return 0; + } + + if (val < ((Float)obj).val) + { + return -1; + } + + return 1; + } + + public override bool Equals(object obj) + { + if (!(obj is Float)) + { + return false; + } + + if (this.val == ((Float)obj).val) + { + return true; + } + + return false; + } + + public override int GetHashCode() + { + return val.GetHashCode(); + } + } + + public class Integer1 : INumber + { + private int val; + + [Inject] + public Integer1([Parameter(typeof(NamedInt))] int v) + { + val = v; + } + + public int CompareTo(object obj) + { + if (!(obj is Integer1)) + { + return -1; + } + if (this.val == ((Integer1)obj).val) + { + return 0; + } + + if (this.val < ((Integer1)obj).val) + { + return -1; + } + + return 1; + } + + public override bool Equals(object obj) + { + if (!(obj is Integer1)) + { + return false; + } + + if (this.val == ((Integer1)obj).val) + { + return true; + } + + return false; + } + + public override int GetHashCode() + { + return val.GetHashCode(); + } + + [NamedParameter] + public class NamedInt : Name<int> + { + } + } + + public class Integer2 : INumber + { + private int val; + + [Inject] + public Integer2() + { + val = 0; + } + + public int CompareTo(object obj) + { + if (!(obj is Integer2)) + { + return -1; + } + if (this.val == ((Integer2)obj).val) + { + return 0; + } + + if (this.val < ((Integer2)obj).val) + { + return -1; + } + + return 1; + } + + public override bool Equals(object obj) + { + if (!(obj is Integer2)) + { + return false; + } + + if (this.val == ((Integer2)obj).val) + { + return true; + } + + return false; + } + + public override int GetHashCode() + { + return val.GetHashCode(); + } + } + + public class Integer3 : INumber + { + private int val; + + [Inject] + public Integer3([Parameter(typeof(NamedInt))] int v) + { + val = v; + } + + public int CompareTo(object obj) + { + if (!(obj is Integer)) + { + return -1; + } + if (this.val == ((Integer3)obj).val) + { + return 0; + } + + if (this.val < ((Integer3)obj).val) + { + return -1; + } + + return 1; + } + + public override bool Equals(object obj) + { + if (!(obj is Integer3)) + { + return false; + } + + if (this.val == ((Integer3)obj).val) + { + return true; + } + + return false; + } + + public override int GetHashCode() + { + return val.GetHashCode(); + } + + [NamedParameter] + public class NamedInt : Name<int> + { + } + } + + public class Float1 : INumber + { + private float val; + + [Inject] + public Float1([Parameter(typeof(NamedFloat))] float v) + { + val = v; + } + + public int CompareTo(object obj) + { + if (!(obj is Float)) + { + return -1; + } + + if (val == ((Float1)obj).val) + { + return 0; + } + + if (val < ((Float1)obj).val) + { + return -1; + } + + return 1; + } + + public override bool Equals(object obj) + { + if (!(obj is Float1)) + { + return false; + } + + if (this.val == ((Float1)obj).val) + { + return true; + } + + return false; + } + + public override int GetHashCode() + { + return val.GetHashCode(); + } + + [NamedParameter] + public class NamedFloat : Name<float> + { + } + } + + public class Pool1 + { + [Inject] + private Pool1([Parameter(typeof(SetOfClasseWithDefault))] ISet<INumber> numbers) + { + this.Numbers = numbers; + } + + public ISet<INumber> Numbers { get; set; } + } + + [NamedParameter(DefaultClass = typeof(Integer2))] + public class SetOfClasseWithDefault : Name<ISet<INumber>> + { + } + } + + public class Timeshift : ITimeshift + { + [Inject] + public Timeshift([Parameter(typeof(TimeshiftLinkId))] string linkId, [Parameter(typeof(TimeshiftInTicks))] long timeshiftInTicks) + { + this.LinkId = linkId; + this.TimeshiftSpan = TimeSpan.FromTicks(timeshiftInTicks); + } + + public string LinkId { get; private set; } + + public TimeSpan TimeshiftSpan { get; private set; } + + [NamedParameter("TimeshiftLinkId", "TimeshiftLinkId", "myid")] + public class TimeshiftLinkId : Name<string> + { + } + + [NamedParameter("TimeshiftInTicks", "TimeshiftInTicks", "10")] + public class TimeshiftInTicks : Name<long> + { + } + } + + public class Timeshift1 : ITimeshift + { + [Inject] + public Timeshift1([Parameter(typeof(TimeshiftLinkId))] string linkId, [Parameter(typeof(TimeshiftInTicks))] long timeshiftInTicks) + { + this.LinkId = linkId; + this.TimeshiftSpan = TimeSpan.FromTicks(timeshiftInTicks); + } + + public string LinkId { get; private set; } + + public TimeSpan TimeshiftSpan { get; private set; } + + [NamedParameter("TimeshiftLinkId1", "TimeshiftLinkId1", "myid")] + public class TimeshiftLinkId : Name<string> + { + } + + [NamedParameter("TimeshiftInTicks1", "TimeshiftInTicks1", "10")] + public class TimeshiftInTicks : Name<long> + { + } + } + + [NamedParameter(DefaultClass = typeof(Timeshift))] + public class SetOfTimeshifts : Name<ISet<ITimeshift>> + { + } + + public class SetofTimeShiftClass + { + [Inject] + public SetofTimeShiftClass([Parameter(typeof(SetOfTimeshifts))] ISet<ITimeshift> timeshifts) + { + this.Timeshifts = timeshifts; + } + + public ISet<ITimeshift> Timeshifts { get; set; } + } + [NamedParameter] + public class SetOfTimeshiftsWithoutDefaultClass : Name<ISet<ITimeshift>> + { + } + + public class SetofTimeShiftClassWithoutDefault + { + [Inject] + public SetofTimeShiftClassWithoutDefault([Parameter(typeof(SetOfTimeshiftsWithoutDefaultClass))] ISet<ITimeshift> timeshifts) + { + this.Timeshifts = timeshifts; + } + + public ISet<ITimeshift> Timeshifts { get; set; } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj b/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj new file mode 100644 index 0000000..2359a93 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Org.Apache.REEF.Tang.Tests.csproj @@ -0,0 +1,203 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +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. +--> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{D5EB94D0-3ABA-4853-9050-E36B196E17D2}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Apache.REEF.Tang.Tests</RootNamespace> + <AssemblyName>Org.Apache.REEF.Tang.Tests</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> + <RestorePackages>true</RestorePackages> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\bin\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\bin\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>..\bin\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>..\bin\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Microsoft.Hadoop.Avro"> + <HintPath>..\packages\Microsoft.Hadoop.Avro.1.4.0.0\lib\net40\Microsoft.Hadoop.Avro.dll</HintPath> + </Reference> + <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> + <Reference Include="Newtonsoft.Json"> + <HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> + <Reference Include="protobuf-net"> + <HintPath>..\packages\protobuf-net.2.0.0.668\lib\net40\protobuf-net.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="ClassHierarchy\TestAnonymousType.cs" /> + <Compile Include="ClassHierarchy\TestClassHierarchy.cs" /> + <Compile Include="ClassHierarchy\TestClassHierarchyRoundTrip.cs" /> + <Compile Include="ClassHierarchy\TestGeneric.cs" /> + <Compile Include="ClassHierarchy\TestMultipleInterface.cs" /> + <Compile Include="ClassHierarchy\TestParameterParser.cs" /> + <Compile Include="ClassHierarchy\TestSerilization.cs" /> + <Compile Include="Configuration\TestAvroConfiguration.cs" /> + <Compile Include="Configuration\TestAvroSerializerRoundTrip.cs" /> + <Compile Include="Configuration\TestConfiguration.cs" /> + <Compile Include="Configuration\TestCsConfigurationBuilderExtension.cs" /> + <Compile Include="Format\TestConfigurationModule.cs" /> + <Compile Include="Format\TestConfigurationModuleForList.cs" /> + <Compile Include="Format\TestTaskConfiguration.cs" /> + <Compile Include="Injection\TestAmbigousConstructors.cs" /> + <Compile Include="Injection\TestForkInjection.cs" /> + <Compile Include="Injection\TestInjection.cs" /> + <Compile Include="Injection\TestInjectionFuture.cs" /> + <Compile Include="Injection\TestListInjection.cs" /> + <Compile Include="Injection\TestMissingParameters.cs" /> + <Compile Include="Injection\TestMissingParamtersInNested.cs" /> + <Compile Include="Injection\TestMultipleConstructors.cs" /> + <Compile Include="Injection\TestNamedParameter.cs" /> + <Compile Include="Injection\TestSetInjection.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="ScenarioTest\HttpHandlerConfiguration.cs" /> + <Compile Include="ScenarioTest\HttpRuntimeConfiguration.cs" /> + <Compile Include="ScenarioTest\HttpRuntimeStartHandler.cs" /> + <Compile Include="ScenarioTest\HttpRuntimeStopHandler.cs" /> + <Compile Include="ScenarioTest\HttpServer.cs" /> + <Compile Include="ScenarioTest\IHttpHandler.cs" /> + <Compile Include="ScenarioTest\JettyHandler.cs" /> + <Compile Include="ScenarioTest\TestDefaultConstructor.cs" /> + <Compile Include="ScenarioTest\TestHttpService.cs" /> + <Compile Include="ScenarioTest\TestRuntimeClock.cs" /> + <Compile Include="ScenarioTest\TestTrackingURIProvider.cs" /> + <Compile Include="ScenarioTest\TrackingURIProvider.cs" /> + <Compile Include="ScenarioTest\TrackingYRIProvider.cs" /> + <Compile Include="SmokeTest\AnInterface.cs" /> + <Compile Include="SmokeTest\AnInterfaceImplementation.cs" /> + <Compile Include="SmokeTest\CyclicDependency.cs" /> + <Compile Include="SmokeTest\CyclicDependencyClassOne.cs" /> + <Compile Include="SmokeTest\CyclicDependencyClassTwo.cs" /> + <Compile Include="SmokeTest\Handler.cs" /> + <Compile Include="SmokeTest\InjectableClass.cs" /> + <Compile Include="SmokeTest\ListOfBaseTypes.cs" /> + <Compile Include="SmokeTest\ObjectTreeTest.cs" /> + <Compile Include="SmokeTest\RootImplementation.cs" /> + <Compile Include="SmokeTest\RootInterface.cs" /> + <Compile Include="SmokeTest\RoundTripTest.cs" /> + <Compile Include="SmokeTest\SetInterface.cs" /> + <Compile Include="SmokeTest\SetInterfaceImplOne.cs" /> + <Compile Include="SmokeTest\SetInterfaceImplTwo.cs" /> + <Compile Include="SmokeTest\SetOfBaseTypes.cs" /> + <Compile Include="SmokeTest\SetOfImplementations.cs" /> + <Compile Include="SmokeTest\TestConfigurationModuleBuilder.cs" /> + <Compile Include="Tang\TestDefaultImpementaion.cs" /> + <Compile Include="Tang\TestExternalConstructors.cs" /> + <Compile Include="Tang\TestLegacyConstructors.cs" /> + <Compile Include="Tang\TestTang.cs" /> + <Compile Include="Utilities\TestUtilities.cs" /> + <Compile Include="Utilities\Utilities.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="evaluator.conf"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + <None Include="packages.config"> + <SubType>Designer</SubType> + </None> + <None Include="simpleConstructorJavaProto.bin"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Org.Apache.REEF.Common\Org.Apache.REEF.Common.csproj"> + <Project>{545a0582-4105-44ce-b99c-b1379514a630}</Project> + <Name>Org.Apache.REEF.Common</Name> + </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Tang.Examples\Org.Apache.REEF.Tang.Examples.csproj"> + <Project>{711b7f32-196e-4c21-9dbd-ad59c4a7cf77}</Project> + <Name>Org.Apache.REEF.Tang.Examples</Name> + </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Tang\Org.Apache.REEF.Tang.csproj"> + <Project>{97dbb573-3994-417a-9f69-ffa25f00d2a6}</Project> + <Name>Org.Apache.REEF.Tang</Name> + </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Utilities\Org.Apache.REEF.Utilities.csproj"> + <Project>{79e7f89a-1dfb-45e1-8d43-d71a954aeb98}</Project> + <Name>Org.Apache.REEF.Utilities</Name> + </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Wake\Org.Apache.REEF.Wake.csproj"> + <Project>{cdfb3464-4041-42b1-9271-83af24cd5008}</Project> + <Name>Org.Apache.REEF.Wake</Name> + </ProjectReference> + <ProjectReference Include="..\Source\REEF\reef-tasks\Tasks\Tasks.csproj"> + <Project>{75503f90-7b82-4762-9997-94b5c68f15db}</Project> + <Name>Tasks</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Properties/AssemblyInfo.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..58c9f71 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +/** + * 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.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Org.Apache.REEF.Tang.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Org.Apache.REEF.Tang.Tests")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fd47238d-600b-42cd-b62d-0724171a2bc4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpHandlerConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpHandlerConfiguration.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpHandlerConfiguration.cs new file mode 100644 index 0000000..a5c57d0 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpHandlerConfiguration.cs @@ -0,0 +1,35 @@ +/** + * 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.Util; + +namespace Org.Apache.REEF.Tang.Tests.ScenarioTest +{ + public class HttpHandlerConfiguration : ConfigurationModuleBuilder + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Not Applicable")] + public static readonly OptionalParameter<IHttpHandler> P = new OptionalParameter<IHttpHandler>(); + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Not Applicable")] + public static readonly ConfigurationModule CONF = new HttpHandlerConfiguration().Merge(HttpRuntimeConfiguration.CONF) + .BindSetEntry<HttpEventHanlders, IHttpHandler>(GenericType<HttpEventHanlders>.Class, HttpHandlerConfiguration.P) + .Build(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeConfiguration.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeConfiguration.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeConfiguration.cs new file mode 100644 index 0000000..b463e4e --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeConfiguration.cs @@ -0,0 +1,36 @@ +/** + * 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.Formats; +using Org.Apache.REEF.Tang.Util; + +namespace Org.Apache.REEF.Tang.Tests.ScenarioTest +{ + public class HttpRuntimeConfiguration : ConfigurationModuleBuilder + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "Not Applicable")] + public static readonly ConfigurationModule CONF = new HttpRuntimeConfiguration() + .BindSetEntry<RuntimeStartHandler, HttpRunTimeStartHandler, IObserver<RuntimeStart>>( + GenericType<RuntimeStartHandler>.Class, GenericType<HttpRunTimeStartHandler>.Class) + .BindSetEntry<RuntimeStopHandler, HttpRunTimeStopHandler, IObserver<RuntimeStop>>( + GenericType<RuntimeStopHandler>.Class, GenericType<HttpRunTimeStopHandler>.Class) + .Build(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeStartHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeStartHandler.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeStartHandler.cs new file mode 100644 index 0000000..a5face9 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeStartHandler.cs @@ -0,0 +1,50 @@ +/** + * 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; + +namespace Org.Apache.REEF.Tang.Tests.ScenarioTest +{ + public class HttpRunTimeStartHandler : IObserver<RuntimeStart> + { + [Inject] + public HttpRunTimeStartHandler(HttpServer httpServer) + { + Server = httpServer; + } + + public HttpServer Server { get; set; } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnNext(RuntimeStart value) + { + Server.StartServer(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeStopHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeStopHandler.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeStopHandler.cs new file mode 100644 index 0000000..d5df7c0 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpRuntimeStopHandler.cs @@ -0,0 +1,50 @@ +/** + * 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; + +namespace Org.Apache.REEF.Tang.Tests.ScenarioTest +{ + public class HttpRunTimeStopHandler : IObserver<RuntimeStop> + { + [Inject] + public HttpRunTimeStopHandler(HttpServer httpServer) + { + Server = httpServer; + } + + public HttpServer Server { get; set; } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnNext(RuntimeStop value) + { + Server.StopServer(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpServer.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpServer.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpServer.cs new file mode 100644 index 0000000..06a5ed9 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/HttpServer.cs @@ -0,0 +1,49 @@ +/** + * 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.Annotations; + +namespace Org.Apache.REEF.Tang.Tests.ScenarioTest +{ + public class HttpServer + { + private Server _server; + + [Inject] + public HttpServer(JettyHandler jettyHandler) + { + JettyHandler = jettyHandler; + _server = new Server(8080); + _server.SetHandler(jettyHandler); + } + + public JettyHandler JettyHandler { get; set; } + + public void StartServer() + { + _server.Start(); + _server.Join(); + } + + public void StopServer() + { + _server.Stop(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/IHttpHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/IHttpHandler.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/IHttpHandler.cs new file mode 100644 index 0000000..6235555 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/IHttpHandler.cs @@ -0,0 +1,27 @@ +/** + * 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. + */ +namespace Org.Apache.REEF.Tang.Tests.ScenarioTest +{ + public interface IHttpHandler + { + string GetUriSpecification(); + + void OnHttpRequest(HttpRequest request, Httpresponse response); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/JettyHandler.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/JettyHandler.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/JettyHandler.cs new file mode 100644 index 0000000..312c46b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/JettyHandler.cs @@ -0,0 +1,44 @@ +/** + * 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.Annotations; + +namespace Org.Apache.REEF.Tang.Tests.ScenarioTest +{ + [NamedParameter()] + public class HttpEventHanlders : Name<ISet<IHttpHandler>> + { + } + + public class JettyHandler //: AbstractHandler + { + [Inject] + public JettyHandler([Parameter(typeof(HttpEventHanlders))] ISet<IHttpHandler> httpeventHanlders) + { + HttpeventHanlders = httpeventHanlders; + } + + public ISet<IHttpHandler> HttpeventHanlders { get; set; } + + public void handle() + { + } + } +} \ No newline at end of file
