You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/02/05 22:05:58 UTC
[37/51] [partial] incubator-reef git commit: [REEF-131] Towards the
new .Net project structure This is to change .Net project structure for Tang,
Wake, REEF utilities, Common and Driver:
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestDefaultConstructor.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestDefaultConstructor.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestDefaultConstructor.cs
new file mode 100644
index 0000000..e8afdfb
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestDefaultConstructor.cs
@@ -0,0 +1,80 @@
+/**
+ * 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;
+using Org.Apache.REEF.Tang.Implementations;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+
+namespace Org.Apache.REEF.Tang.Tests.ScenarioTest
+{
+ [TestClass]
+ public class TestDefaultConstructor
+ {
+ [TestMethod]
+ public void TestDefaultCOnstructorWithoutBinding()
+ {
+ var r = (A)TangFactory.GetTang().NewInjector().GetInstance(typeof(A));
+ System.Diagnostics.Debug.WriteLine(r.Instance);
+ }
+ }
+
+ class A
+ {
+ [Inject]
+ public A()
+ {
+ Instance = "default";
+ }
+ [Inject]
+ public A(B b)
+ {
+ Instance = "non default";
+ }
+
+ public string Instance { get; set; }
+ }
+
+ class B
+ {
+ [Inject]
+ public B()
+ {
+ Instance = "default";
+ }
+ [Inject]
+ public B(C c)
+ {
+ Instance = "non default";
+ }
+
+ public string Instance { get; set; }
+ }
+
+ class C
+ {
+ [Inject]
+ public C()
+ {
+ Instance = "default";
+ }
+
+ public string Instance { 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/ScenarioTest/TestHttpService.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestHttpService.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestHttpService.cs
new file mode 100644
index 0000000..e7baeb1
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestHttpService.cs
@@ -0,0 +1,195 @@
+/**
+ * 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.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.ScenarioTest
+{
+ [TestClass]
+ public class TestHttpService
+ {
+ [TestMethod]
+ public void HttpEventHanldersTest()
+ {
+ ConfigurationModule module =
+ new ConfigurationModuleBuilder()
+ .BindSetEntry<HttpEventHanlders, HttpServerReefEventHandler, IHttpHandler>(GenericType<HttpEventHanlders>.Class, GenericType<HttpServerReefEventHandler>.Class)
+ .BindSetEntry<HttpEventHanlders, HttpServerNrtEventHandler, IHttpHandler>(GenericType<HttpEventHanlders>.Class, GenericType<HttpServerNrtEventHandler>.Class)
+ .Build();
+
+ IConfiguration c = module.Build();
+ var service = TangFactory.GetTang().NewInjector(c).GetInstance<HttpServer>();
+ Assert.IsNotNull(service);
+
+ var j = TangFactory.GetTang().NewInjector(c).GetInstance<HttpRunTimeStartHandler>();
+ Assert.IsNotNull(j);
+ }
+
+ [TestMethod]
+ public void RuntimeStartHandlerTest()
+ {
+ ConfigurationModule module =
+ new ConfigurationModuleBuilder()
+ .BindSetEntry<RuntimeStartHandler, HttpRunTimeStartHandler, IObserver<RuntimeStart>>(
+ GenericType<RuntimeStartHandler>.Class, GenericType<HttpRunTimeStartHandler>.Class)
+ .Build();
+ IConfiguration clockConfiguraiton = module.Build();
+
+ RuntimeClock clock = TangFactory.GetTang().NewInjector(clockConfiguraiton).GetInstance<RuntimeClock>();
+ var rh = clock.ClockRuntimeStartHandler.Get();
+ Assert.AreEqual(rh.Count, 1);
+ foreach (var e in rh)
+ {
+ Assert.IsTrue(e is HttpRunTimeStartHandler);
+ HttpRunTimeStartHandler r = (HttpRunTimeStartHandler)e;
+ var s = r.Server;
+ Assert.AreEqual(s.JettyHandler.HttpeventHanlders.Count, 0); // no handlers are bound
+ }
+ }
+
+ [TestMethod]
+ public void RuntimeStartStopHandlerTest()
+ {
+ IConfiguration clockConfiguraiton = HttpRuntimeConfiguration.CONF.Build();
+ RuntimeClock clock = TangFactory.GetTang().NewInjector(clockConfiguraiton).GetInstance<RuntimeClock>();
+ var starts = clock.ClockRuntimeStartHandler.Get();
+ var stops = clock.ClockRuntimeStopHandler.Get();
+
+ HttpRunTimeStartHandler start = null;
+ HttpRunTimeStopHandler stop = null;
+
+ Assert.AreEqual(starts.Count, 1);
+ foreach (var e in starts)
+ {
+ Assert.IsTrue(e is HttpRunTimeStartHandler);
+ start = (HttpRunTimeStartHandler)e;
+ }
+
+ Assert.AreEqual(stops.Count, 1);
+ foreach (var e in stops)
+ {
+ Assert.IsTrue(e is HttpRunTimeStopHandler);
+ stop = (HttpRunTimeStopHandler)e;
+ }
+
+ Assert.AreEqual(start.Server, stop.Server);
+ Assert.AreEqual(start.Server.JettyHandler.HttpeventHanlders, stop.Server.JettyHandler.HttpeventHanlders);
+ Assert.AreSame(start.Server, stop.Server);
+ }
+
+ [TestMethod]
+ public void RuntimeStartHandlerMergeTest()
+ {
+ IConfiguration clockConfiguraiton = HttpHandlerConfiguration.CONF
+ .Set(HttpHandlerConfiguration.P,
+ GenericType<HttpServerReefEventHandler>.Class)
+ .Set(HttpHandlerConfiguration.P,
+ GenericType<HttpServerNrtEventHandler>.Class)
+ .Build();
+
+ RuntimeClock clock = TangFactory.GetTang().NewInjector(clockConfiguraiton).GetInstance<RuntimeClock>();
+
+ var rh = clock.ClockRuntimeStartHandler.Get();
+ Assert.AreEqual(rh.Count, 1);
+ foreach (var e in rh)
+ {
+ Assert.IsTrue(e is HttpRunTimeStartHandler);
+ HttpRunTimeStartHandler r = (HttpRunTimeStartHandler)e;
+ var s = r.Server;
+ foreach (IHttpHandler h in s.JettyHandler.HttpeventHanlders)
+ {
+ System.Diagnostics.Debug.WriteLine(h.GetUriSpecification());
+ }
+ }
+ }
+ }
+
+ public class HttpRequest
+ {
+ }
+
+ public class Httpresponse
+ {
+ }
+
+ public class HttpServerReefEventHandler : IHttpHandler
+ {
+ [Inject]
+ public HttpServerReefEventHandler()
+ {
+ }
+
+ public string GetUriSpecification()
+ {
+ return "/Reef";
+ }
+
+ public void OnHttpRequest(HttpRequest request, Httpresponse response)
+ {
+ //handle the event
+ }
+ }
+
+ public class HttpServerNrtEventHandler : IHttpHandler
+ {
+ [Inject]
+ public HttpServerNrtEventHandler()
+ {
+ }
+
+ public string GetUriSpecification()
+ {
+ return "/NRT";
+ }
+
+ public void OnHttpRequest(HttpRequest request, Httpresponse response)
+ {
+ }
+ }
+
+ public class Server
+ {
+ public Server(int port)
+ {
+ }
+
+ public void Start()
+ {
+ }
+
+ public void Stop()
+ {
+ }
+
+ public void Join()
+ {
+ }
+
+ public void SetHandler(JettyHandler handler)
+ {
+ }
+ }
+}
\ 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/TestRuntimeClock.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestRuntimeClock.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestRuntimeClock.cs
new file mode 100644
index 0000000..6000a5a
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestRuntimeClock.cs
@@ -0,0 +1,255 @@
+/**
+ * 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.InjectionPlan;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+
+namespace Org.Apache.REEF.Tang.Tests.ScenarioTest
+{
+ [DefaultImplementation(typeof(RealTimer))]
+ public interface ITimer
+ {
+ int GetCurrent();
+
+ int GetDuration(int time);
+
+ bool IsReady(int time);
+ }
+
+ [DefaultImplementation(typeof(RuntimeClock))]
+ public interface IClock
+ {
+ DateTime CurrentTime();
+ }
+
+ public interface IEventHandler<T>
+ {
+ void OnNext(T value);
+ }
+
+ [TestClass]
+ public class TestSenarios
+ {
+ [TestMethod]
+ public void TestRuntimeClock()
+ {
+ var r = (RuntimeClock)TangFactory.GetTang().NewInjector().GetInstance(typeof(RuntimeClock));
+ Assert.IsNotNull(r);
+ r.CurrentTime();
+ }
+
+ [TestMethod]
+ public void TestEvaluatorRuntime()
+ {
+ ConfigurationModule module =
+ new ConfigurationModuleBuilder()
+ .BindSetEntry<RuntimeStartHandler, EvaluatorRuntime, IObserver<RuntimeStart>>(GenericType<RuntimeStartHandler>.Class, GenericType<EvaluatorRuntime>.Class)
+ .Build();
+ IConfiguration clockConfiguraiton = module.Build();
+
+ RuntimeClock clock = TangFactory.GetTang().NewInjector(clockConfiguraiton).GetInstance<RuntimeClock>();
+ var r = clock.ClockRuntimeStartHandler.Get();
+ Assert.AreEqual(r.Count, 1);
+ foreach (var e in r)
+ {
+ Assert.IsTrue(e is EvaluatorRuntime);
+ }
+ }
+ }
+
+ public class RuntimeClock : IClock
+ {
+ [Inject]
+ public RuntimeClock(ITimer timer,
+ [Parameter(typeof(StartHandler))] IInjectionFuture<ISet<IEventHandler<StartTime>>> startHandler,
+ [Parameter(typeof(RuntimeStartHandler))] IInjectionFuture<ISet<IObserver<RuntimeStart>>> runtimeStartHandler,
+ [Parameter(typeof(RuntimeStopHandler))] IInjectionFuture<ISet<IObserver<RuntimeStop>>> runtimeStopHandler)
+ {
+ this.ClockStartHandler = startHandler;
+ this.ClockRuntimeStartHandler = runtimeStartHandler;
+ this.ClockRuntimeStopHandler = runtimeStopHandler;
+ }
+
+ public IInjectionFuture<ISet<IObserver<RuntimeStart>>> ClockRuntimeStartHandler { get; set; }
+
+ public IInjectionFuture<ISet<IObserver<RuntimeStop>>> ClockRuntimeStopHandler { get; set; }
+
+ public IInjectionFuture<ISet<IEventHandler<StartTime>>> ClockStartHandler { get; set; }
+
+ public DateTime CurrentTime()
+ {
+ return DateTime.Now;
+ }
+ }
+
+ [NamedParameter(DefaultClass = typeof(MissingStartHandlerHandler),
+ Documentation = "Will be called upon the start event")]
+ public class StartHandler : Name<ISet<IEventHandler<StartTime>>>
+ {
+ }
+
+ /// <summary>
+ /// Bind this to an event handler to statically subscribe to the RuntimeStart Event
+ /// </summary>
+ [NamedParameter(Documentation = "Will be called upon the runtime start event",
+ DefaultClass = typeof(LoggingEventHandler<RuntimeStart>))]
+ public class RuntimeStartHandler : Name<ISet<IObserver<RuntimeStart>>>
+ {
+ }
+
+ [NamedParameter(documentation: "Will be called upon the runtime start event",
+ defaultClass: typeof(LoggingEventHandler<RuntimeStop>))]
+ public class RuntimeStopHandler : Name<ISet<IObserver<RuntimeStop>>>
+ {
+ }
+
+ public class StartTime : Time
+ {
+ public StartTime(long timestamp) : base(timestamp)
+ {
+ }
+ }
+
+ public class RuntimeStart : Time
+ {
+ public RuntimeStart(long timeStamp)
+ : base(timeStamp)
+ {
+ }
+ }
+
+ public class RuntimeStop : Time
+ {
+ public RuntimeStop(long timeStamp)
+ : base(timeStamp)
+ {
+ }
+ }
+
+ public class EvaluatorRuntime : IObserver<RuntimeStart>
+ {
+ [Inject]
+ public EvaluatorRuntime()
+ {
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnNext(RuntimeStart value)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public class LoggingEventHandler<T> : IObserver<T>
+ {
+ [Inject]
+ public LoggingEventHandler()
+ {
+ }
+
+ /// <summary>Logs the event</summary>
+ /// <param name="value">an event</param>
+ public void OnNext(T value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnError(Exception error)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void OnCompleted()
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public abstract class Time : IComparable<Time>
+ {
+ private long timestamp;
+
+ public Time(long timestamp)
+ {
+ this.timestamp = timestamp;
+ }
+
+ public long GetTimeStamp()
+ {
+ return this.timestamp;
+ }
+
+ public int CompareTo(Time other)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public class MissingStartHandlerHandler : IEventHandler<StartTime>
+ {
+ [Inject]
+ public MissingStartHandlerHandler()
+ {
+ }
+
+ public void OnNext(StartTime value)
+ {
+ }
+ }
+
+ public class RealTimer : ITimer
+ {
+ [Inject]
+ public RealTimer()
+ {
+ }
+
+ public int GetCurrent()
+ {
+ return DateTime.Now.Millisecond;
+ }
+
+ public int GetDuration(int time)
+ {
+ return time - GetCurrent();
+ }
+
+ public bool IsReady(int time)
+ {
+ return GetDuration(time) <= 0;
+ }
+ }
+}
\ 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/TestTrackingURIProvider.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestTrackingURIProvider.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestTrackingURIProvider.cs
new file mode 100644
index 0000000..3c110dd
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TestTrackingURIProvider.cs
@@ -0,0 +1,60 @@
+/**
+ * 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.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.ScenarioTest
+{
+ [TestClass]
+ public class TestTrackingURIProvider
+ {
+ [TestMethod]
+ public void TrackingIdThroughNamedParameterTest()
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ string trackingId = System.Environment.MachineName + ":8080";
+ cba.BindNamedParameter<TrackingId, string>(GenericType<TrackingId>.Class, trackingId);
+ string id = (string)TangFactory.GetTang().NewInjector(cba.Build()).GetNamedInstance(typeof(TrackingId));
+ Assert.AreEqual(id, trackingId);
+ }
+
+ [TestMethod]
+ public void DefaultTrackingIdThroughInterfaceTest()
+ {
+ string trackingId = System.Environment.MachineName + ":8080";
+ var id = TangFactory.GetTang().NewInjector().GetInstance<ITrackingURIProvider>();
+ Assert.AreEqual(id.GetURI(), trackingId);
+ }
+
+ [TestMethod]
+ public void TrackingIdThroughInterfaceTest()
+ {
+ ICsConfigurationBuilder cba = TangFactory.GetTang().NewConfigurationBuilder();
+ cba.BindNamedParameter<PortNumber, string>(GenericType<PortNumber>.Class, "8080");
+ string trackingId = System.Environment.MachineName + ":8080";
+ var id = TangFactory.GetTang().NewInjector().GetInstance<ITrackingURIProvider>();
+ Assert.AreEqual(id.GetURI(), trackingId);
+ }
+ }
+}
\ 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/TrackingURIProvider.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TrackingURIProvider.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TrackingURIProvider.cs
new file mode 100644
index 0000000..0c0d0f6
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TrackingURIProvider.cs
@@ -0,0 +1,63 @@
+/**
+ * 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
+{
+ [DefaultImplementation(typeof(DefaultTrackingURIProvider))]
+ public interface ITrackingURIProvider
+ {
+ string GetURI();
+ }
+
+ [NamedParameter(DefaultValue = " ")]
+ public class TrackingId : Name<string>
+ {
+ }
+
+ [NamedParameter(DefaultValue = "8080")]
+ public class PortNumber : Name<string>
+ {
+ }
+
+ public class DefaultTrackingURIProvider : ITrackingURIProvider
+ {
+ private string port;
+
+ [Inject]
+ public DefaultTrackingURIProvider([Parameter(typeof(PortNumber))] string port)
+ {
+ this.port = port;
+ }
+
+ public string GetURI()
+ {
+ try
+ {
+ return System.Environment.MachineName + ":" + port;
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+ }
+}
\ 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/TrackingYRIProvider.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TrackingYRIProvider.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TrackingYRIProvider.cs
new file mode 100644
index 0000000..81c9353
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ScenarioTest/TrackingYRIProvider.cs
@@ -0,0 +1,25 @@
+/**
+ * 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
+{
+ class TrackingYRIProvider
+ {
+ }
+}
\ 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/SmokeTest/AnInterface.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/AnInterface.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/AnInterface.cs
new file mode 100644
index 0000000..52f5629
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/AnInterface.cs
@@ -0,0 +1,29 @@
+/**
+ * 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.SmokeTest
+{
+ [DefaultImplementation(typeof(AnInterfaceImplementation))]
+ public interface IAnInterface
+ {
+ void AMethod();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/AnInterfaceImplementation.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/AnInterfaceImplementation.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/AnInterfaceImplementation.cs
new file mode 100644
index 0000000..d68eb36
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/AnInterfaceImplementation.cs
@@ -0,0 +1,65 @@
+/**
+ * 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.SmokeTest
+{
+ public class AnInterfaceImplementation : IAnInterface
+ {
+ private readonly int aMagicNumber;
+
+ [Inject]
+ AnInterfaceImplementation()
+ {
+ this.aMagicNumber = 42;
+ }
+
+ public void AMethod()
+ {
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null)
+ {
+ return false;
+ }
+
+ AnInterfaceImplementation that = (AnInterfaceImplementation)o;
+
+ if (aMagicNumber != that.aMagicNumber)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return aMagicNumber;
+ }
+ }
+}
\ 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/SmokeTest/CyclicDependency.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependency.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependency.cs
new file mode 100644
index 0000000..df910ac
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependency.cs
@@ -0,0 +1,70 @@
+/**
+ * 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.SmokeTest
+{
+ public class CyclicDependency
+ {
+ private readonly CyclicDependencyClassOne one;
+ private readonly CyclicDependencyClassTwo two;
+
+ [Inject]
+ CyclicDependency(CyclicDependencyClassOne one, CyclicDependencyClassTwo two)
+ {
+ this.one = one;
+ this.two = two;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null)
+ {
+ return false;
+ }
+
+ CyclicDependency that = (CyclicDependency)o;
+
+ if (!one.Equals(that.one))
+ {
+ return false;
+ }
+
+ if (!two.Equals(that.two))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ int result = one.GetHashCode();
+ result = (31 * result) + two.GetHashCode();
+ return result;
+ }
+ }
+}
\ 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/SmokeTest/CyclicDependencyClassOne.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependencyClassOne.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependencyClassOne.cs
new file mode 100644
index 0000000..e239eae
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependencyClassOne.cs
@@ -0,0 +1,61 @@
+/**
+ * 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.SmokeTest
+{
+ public class CyclicDependencyClassOne
+ {
+ private readonly CyclicDependencyClassTwo other;
+
+ [Inject]
+ CyclicDependencyClassOne(CyclicDependencyClassTwo other)
+ {
+ this.other = other;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null)
+ {
+ return false;
+ }
+
+ CyclicDependencyClassOne that = (CyclicDependencyClassOne)o;
+
+ if (!other.Equals(that.other))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return other.GetHashCode();
+ }
+ }
+}
\ 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/SmokeTest/CyclicDependencyClassTwo.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependencyClassTwo.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependencyClassTwo.cs
new file mode 100644
index 0000000..4019d2a
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/CyclicDependencyClassTwo.cs
@@ -0,0 +1,56 @@
+/**
+ * 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;
+using Org.Apache.REEF.Tang.Implementations;
+using Org.Apache.REEF.Tang.Implementations.InjectionPlan;
+
+namespace Org.Apache.REEF.Tang.Tests.SmokeTest
+{
+ public class CyclicDependencyClassTwo
+ {
+ private readonly IInjectionFuture<CyclicDependencyClassOne> other;
+
+ [Inject]
+ CyclicDependencyClassTwo(IInjectionFuture<CyclicDependencyClassOne> other)
+ {
+ this.other = other;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return other.GetHashCode();
+ }
+ }
+}
\ 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/SmokeTest/Handler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/Handler.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/Handler.cs
new file mode 100644
index 0000000..1cb0cf4
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/Handler.cs
@@ -0,0 +1,26 @@
+/**
+ * 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.SmokeTest
+{
+ public interface IHandler<T>
+ {
+ void Process(T value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/InjectableClass.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/InjectableClass.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/InjectableClass.cs
new file mode 100644
index 0000000..0e730c8
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/InjectableClass.cs
@@ -0,0 +1,60 @@
+/**
+ * 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.SmokeTest
+{
+ public class InjectableClass
+ {
+ private readonly int magicNumber = -42;
+
+ [Inject]
+ InjectableClass()
+ {
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null)
+ {
+ return false;
+ }
+
+ InjectableClass that = (InjectableClass)o;
+
+ if (magicNumber != that.magicNumber)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return magicNumber;
+ }
+ }
+}
\ 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/SmokeTest/ListOfBaseTypes.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/ListOfBaseTypes.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/ListOfBaseTypes.cs
new file mode 100644
index 0000000..ad64431
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/ListOfBaseTypes.cs
@@ -0,0 +1,108 @@
+/**
+ * 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.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Org.Apache.REEF.Tang.Annotations;
+
+namespace Org.Apache.REEF.Tang.Tests.SmokeTest
+{
+ public class ListOfBaseTypes
+ {
+ private readonly IList<int> integers;
+ private readonly IList<double> doubles;
+ private readonly IList<string> strings;
+ private readonly IList<int> moreIntegers;
+
+ [Inject]
+ private ListOfBaseTypes([Parameter(typeof(ListOfBaseTypes.Integers))] IList<int> integers,
+ [Parameter(typeof(ListOfBaseTypes.Doubles))] IList<double> doubles,
+ [Parameter(typeof(ListOfBaseTypes.Strings))] IList<string> strings,
+ [Parameter(typeof(ListOfBaseTypes.MoreIntegers))] IList<int> moreIntegers)
+ {
+ this.integers = integers;
+ this.doubles = doubles;
+ this.strings = strings;
+ this.moreIntegers = moreIntegers;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null || !(o is ListOfBaseTypes))
+ {
+ return false;
+ }
+
+ ListOfBaseTypes that = (ListOfBaseTypes)o;
+
+ if (!Utilities.Utilities.Equals(doubles, that.doubles))
+ {
+ return false;
+ }
+
+ if (!Utilities.Utilities.Equals(integers, that.integers))
+ {
+ return false;
+ }
+
+ if (!Utilities.Utilities.Equals(strings, that.strings))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ int result = integers.GetHashCode();
+ result = (31 * result) + doubles.GetHashCode();
+ result = (31 * result) + strings.GetHashCode();
+ return result;
+ }
+
+ [NamedParameter]
+ public class Integers : Name<IList<int>>
+ {
+ }
+
+ [NamedParameter(DefaultValues = new string[] { "1", "2", "3" })]
+ public class MoreIntegers : Name<IList<int>>
+ {
+ }
+
+ [NamedParameter]
+ public class Doubles : Name<IList<double>>
+ {
+ }
+
+ [NamedParameter]
+ public class Strings : Name<IList<string>>
+ {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/ObjectTreeTest.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/ObjectTreeTest.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/ObjectTreeTest.cs
new file mode 100644
index 0000000..ec3b7d2
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/ObjectTreeTest.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 Org.Apache.REEF.Tang.Implementations;
+using Org.Apache.REEF.Tang.Interface;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+
+namespace Org.Apache.REEF.Tang.Tests.SmokeTest
+{
+ [TestClass]
+ public class ObjectTreeTest
+ {
+ public static IConfiguration GetConfiguration()
+ {
+ return TestConfigurationModuleBuilder.CONF
+ .Set(TestConfigurationModuleBuilder.OPTIONALSTRING, TestConfigurationModuleBuilder.OptionaStringValue)
+ .Set(TestConfigurationModuleBuilder.REQUIREDSTRING, TestConfigurationModuleBuilder.RequiredStringValue)
+ .Build();
+ }
+
+ [TestMethod]
+ public void TestInstantiation()
+ {
+ IRootInterface root = TangFactory.GetTang().NewInjector(GetConfiguration()).GetInstance<IRootInterface>();
+ Assert.IsTrue(root.IsValid(), "Object instantiation left us in an inconsistent state.");
+ }
+
+ [TestMethod]
+ public void TestTwoInstantiations()
+ {
+ IRootInterface firstRoot = TangFactory.GetTang().NewInjector(GetConfiguration()).GetInstance<IRootInterface>();
+ IRootInterface secondRoot = TangFactory.GetTang().NewInjector(GetConfiguration()).GetInstance<IRootInterface>();
+
+ Assert.AreNotSame(firstRoot, secondRoot, "Two instantiations of the object tree should not be the same");
+ Assert.AreEqual(firstRoot, secondRoot, "Two instantiations of the object tree should be equal");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RootImplementation.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RootImplementation.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RootImplementation.cs
new file mode 100644
index 0000000..a0e2aed
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RootImplementation.cs
@@ -0,0 +1,178 @@
+/**
+ * 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.SmokeTest
+{
+ public class RootImplementation : IRootInterface
+ {
+ private readonly string requiredString;
+ private readonly string optionalString;
+ private readonly IAnInterface anInterface;
+ private readonly int anInt;
+ private readonly double aDouble;
+ private readonly InjectableClass injectableClass;
+ private readonly SetOfImplementations setOfImplementations;
+ private readonly SetOfBaseTypes setOfBaseTypes;
+ //private readonly ListOfBaseTypes listOfBaseTypes; //TODO: to recover once Avro NuGet support it
+ private readonly CyclicDependency cyclicDependency;
+
+ [Inject]
+ public RootImplementation([Parameter(typeof(TestConfigurationModuleBuilder.RequiredString))] string requiredString,
+ [Parameter(typeof(TestConfigurationModuleBuilder.OptionalString))] string optionalString,
+ [Parameter(typeof(TestConfigurationModuleBuilder.NamedParameterInteger))] int anInt,
+ [Parameter(typeof(TestConfigurationModuleBuilder.NamedParameterDouble))] double aDouble,
+ IAnInterface anInterface,
+ InjectableClass injectableClass,
+ SetOfImplementations setOfImplementations,
+ SetOfBaseTypes setOfBaseTypes,
+ //ListOfBaseTypes listOfBaseTypes, //TODO: to recover once Avro NuGet support it
+ CyclicDependency cyclicDependency)
+ {
+ this.requiredString = requiredString;
+ this.optionalString = optionalString;
+ this.anInterface = anInterface;
+ this.anInt = anInt;
+ this.aDouble = aDouble;
+ this.injectableClass = injectableClass;
+ this.setOfImplementations = setOfImplementations;
+ this.setOfBaseTypes = setOfBaseTypes;
+ //this.listOfBaseTypes = listOfBaseTypes; //TODO: to recover once Avro NuGet support it
+ this.cyclicDependency = cyclicDependency;
+ }
+
+ public bool IsValid()
+ {
+ if (!this.setOfImplementations.isValid())
+ {
+ return false;
+ }
+
+ if (!this.requiredString.Equals(TestConfigurationModuleBuilder.RequiredStringValue))
+ {
+ return false;
+ }
+
+ if (!this.optionalString.Equals(TestConfigurationModuleBuilder.OptionaStringValue))
+ {
+ return false;
+ }
+
+ if (this.anInterface == null)
+ {
+ return false;
+ }
+
+ if (this.aDouble != TestConfigurationModuleBuilder.NamedParameterDoubleValue)
+ {
+ return false;
+ }
+
+ if (this.anInt != TestConfigurationModuleBuilder.NamedParameterIntegerValue)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null)
+ {
+ return false;
+ }
+
+ RootImplementation that = (RootImplementation)o;
+
+ if (that.aDouble != aDouble)
+ {
+ return false;
+ }
+
+ if (anInt != that.anInt)
+ {
+ return false;
+ }
+
+ if (anInterface != null ? !anInterface.Equals(that.anInterface) : that.anInterface != null)
+ {
+ return false;
+ }
+
+ if (optionalString != null ? !optionalString.Equals(that.optionalString) : that.optionalString != null)
+ {
+ return false;
+ }
+
+ if (requiredString != null ? !requiredString.Equals(that.requiredString) : that.requiredString != null)
+ {
+ return false;
+ }
+
+ if (injectableClass != null ? !injectableClass.Equals(that.injectableClass) : that.injectableClass != null)
+ {
+ return false;
+ }
+
+ if (setOfImplementations != null
+ ? !setOfImplementations.Equals(that.setOfImplementations)
+ : that.setOfImplementations != null)
+ {
+ return false;
+ }
+
+ if (setOfBaseTypes != null ? !setOfBaseTypes.Equals(that.setOfBaseTypes) : that.setOfBaseTypes != null)
+ {
+ return false;
+ }
+
+ //TODO: to recover once Avro NuGet support it
+ //if (listOfBaseTypes != null ? !listOfBaseTypes.Equals(that.listOfBaseTypes) : that.listOfBaseTypes != null)
+ //{
+ // return false;
+ //}
+ if (cyclicDependency != null
+ ? !cyclicDependency.Equals(that.cyclicDependency)
+ : that.cyclicDependency != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ int result;
+ result = requiredString != null ? requiredString.GetHashCode() : 0;
+ result = (31 * result) + (optionalString != null ? optionalString.GetHashCode() : 0);
+ result = (31 * result) + (anInterface != null ? anInterface.GetHashCode() : 0);
+ result = (31 * result) + anInt;
+ result = (31 * result) + aDouble.GetHashCode();
+ return result;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RootInterface.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RootInterface.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RootInterface.cs
new file mode 100644
index 0000000..1132d72
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RootInterface.cs
@@ -0,0 +1,26 @@
+/**
+ * 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.SmokeTest
+{
+ public interface IRootInterface
+ {
+ bool IsValid();
+ }
+}
\ 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/SmokeTest/RoundTripTest.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RoundTripTest.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RoundTripTest.cs
new file mode 100644
index 0000000..d103158
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/RoundTripTest.cs
@@ -0,0 +1,41 @@
+/**
+ * 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.Implementations;
+using Org.Apache.REEF.Tang.Interface;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Org.Apache.REEF.Tang.Implementations.Tang;
+
+namespace Org.Apache.REEF.Tang.Tests.SmokeTest
+{
+ [TestClass]
+ public abstract class RoundTripTest
+ {
+ public abstract IConfiguration RoundTrip(IConfiguration configuration);
+
+ [TestMethod]
+ public void TestRoundTrip()
+ {
+ IConfiguration conf = ObjectTreeTest.GetConfiguration();
+ IRootInterface before = TangFactory.GetTang().NewInjector(conf).GetInstance<IRootInterface>();
+ IRootInterface after = TangFactory.GetTang().NewInjector(RoundTrip(conf)).GetInstance<IRootInterface>();
+ Assert.AreEqual(before, after, "Configuration conversion to and from Avro datatypes failed.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterface.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterface.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterface.cs
new file mode 100644
index 0000000..b4a35ee
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterface.cs
@@ -0,0 +1,31 @@
+/**
+ * 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;
+
+namespace Org.Apache.REEF.Tang.Tests.SmokeTest
+{
+ /**
+ * Interface used for the set injecttion test.
+ */
+ interface ISetInterface : IComparable
+ {
+ void AMethod();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterfaceImplOne.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterfaceImplOne.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterfaceImplOne.cs
new file mode 100644
index 0000000..c79b1f6
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterfaceImplOne.cs
@@ -0,0 +1,82 @@
+/**
+ * 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.SmokeTest
+{
+ public class SetInterfaceImplOne : ISetInterface
+ {
+ private readonly int magicNumber;
+
+ [Inject]
+ public SetInterfaceImplOne()
+ {
+ this.magicNumber = 42;
+ }
+
+ public void AMethod()
+ {
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null || !(o is SetInterfaceImplOne))
+ {
+ return false;
+ }
+
+ SetInterfaceImplOne that = (SetInterfaceImplOne)o;
+
+ if (magicNumber != that.magicNumber)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return magicNumber;
+ }
+
+ public int CompareTo(object obj)
+ {
+ if (this == obj)
+ {
+ return 0;
+ }
+
+ if (obj == null || !(obj is SetInterfaceImplOne))
+ {
+ return -1;
+ }
+
+ SetInterfaceImplOne that = (SetInterfaceImplOne)obj;
+
+ return magicNumber.CompareTo(that.magicNumber);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterfaceImplTwo.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterfaceImplTwo.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterfaceImplTwo.cs
new file mode 100644
index 0000000..86b61ef
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetInterfaceImplTwo.cs
@@ -0,0 +1,82 @@
+/**
+ * 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.SmokeTest
+{
+ public class SetInterfaceImplTwo : ISetInterface
+ {
+ private readonly double magicNumber;
+
+ [Inject]
+ SetInterfaceImplTwo()
+ {
+ this.magicNumber = 42.0;
+ }
+
+ public void AMethod()
+ {
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null || !(o is SetInterfaceImplTwo))
+ {
+ return false;
+ }
+
+ SetInterfaceImplTwo that = (SetInterfaceImplTwo)o;
+
+ if (that.magicNumber.CompareTo(magicNumber) != 0)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return magicNumber.GetHashCode();
+ }
+
+ public int CompareTo(object obj)
+ {
+ if (this == obj)
+ {
+ return 0;
+ }
+
+ if (obj == null || !(obj is SetInterfaceImplTwo))
+ {
+ return -1;
+ }
+
+ SetInterfaceImplTwo that = (SetInterfaceImplTwo)obj;
+
+ return that.magicNumber.CompareTo(magicNumber);
+ }
+ }
+}
\ 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/SmokeTest/SetOfBaseTypes.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetOfBaseTypes.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetOfBaseTypes.cs
new file mode 100644
index 0000000..fedbbd8
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetOfBaseTypes.cs
@@ -0,0 +1,105 @@
+/**
+ * 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;
+
+namespace Org.Apache.REEF.Tang.Tests.SmokeTest
+{
+ public class SetOfBaseTypes
+ {
+ private readonly ISet<int> integers;
+ private readonly ISet<double> doubles;
+ private readonly ISet<string> strings;
+ private readonly ISet<int> moreIntegers;
+
+ [Inject]
+ private SetOfBaseTypes([Parameter(typeof(Integers))] ISet<int> integers,
+ [Parameter(typeof(Doubles))] ISet<double> doubles,
+ [Parameter(typeof(Strings))] ISet<string> strings,
+ [Parameter(typeof(MoreIntegers))] ISet<int> moreIntegers)
+ {
+ this.integers = integers;
+ this.doubles = doubles;
+ this.strings = strings;
+ this.moreIntegers = moreIntegers;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null || !(o is SetOfBaseTypes))
+ {
+ return false;
+ }
+
+ SetOfBaseTypes that = (SetOfBaseTypes)o;
+
+ if (!Utilities.Utilities.Equals(doubles, that.doubles))
+ {
+ return false;
+ }
+
+ if (!Utilities.Utilities.Equals(integers, that.integers))
+ {
+ return false;
+ }
+
+ if (!Utilities.Utilities.Equals(strings, that.strings))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ int result = integers.GetHashCode();
+ result = (31 * result) + doubles.GetHashCode();
+ result = (31 * result) + strings.GetHashCode();
+ return result;
+ }
+
+ [NamedParameter]
+ public class Integers : Name<ISet<int>>
+ {
+ }
+
+ [NamedParameter(DefaultValues = new string[] { "1", "2", "3" })]
+ public class MoreIntegers : Name<ISet<int>>
+ {
+ }
+
+ [NamedParameter]
+ public class Doubles : Name<ISet<double>>
+ {
+ }
+
+ [NamedParameter]
+ public class Strings : Name<ISet<string>>
+ {
+ }
+ }
+}
\ 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/SmokeTest/SetOfImplementations.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetOfImplementations.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetOfImplementations.cs
new file mode 100644
index 0000000..947ff1a
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/SetOfImplementations.cs
@@ -0,0 +1,72 @@
+/**
+ * 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.SmokeTest
+{
+ public class SetOfImplementations
+ {
+ private readonly ISet<ISetInterface> theInstances;
+
+ [Inject]
+ SetOfImplementations([Parameter(typeof(TestConfigurationModuleBuilder.SetOfInstances))] ISet<ISetInterface> theInstances)
+ {
+ this.theInstances = theInstances;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+
+ if (o == null || !(o is SetOfImplementations))
+ {
+ return false;
+ }
+
+ SetOfImplementations that = (SetOfImplementations)o;
+
+ if (that.theInstances.Count != this.theInstances.Count)
+ {
+ return false;
+ }
+
+ if (!Utilities.Utilities.Equals<ISetInterface>(theInstances, that.theInstances))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public override int GetHashCode()
+ {
+ return theInstances.GetHashCode();
+ }
+
+ public bool isValid()
+ {
+ return this.theInstances.Count == 2;
+ }
+ }
+}
\ 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/SmokeTest/TestConfigurationModuleBuilder.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/TestConfigurationModuleBuilder.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/TestConfigurationModuleBuilder.cs
new file mode 100644
index 0000000..e08ef78
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/SmokeTest/TestConfigurationModuleBuilder.cs
@@ -0,0 +1,107 @@
+/**
+ * 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.Globalization;
+using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Tang.Formats;
+using Org.Apache.REEF.Tang.Util;
+using Org.Apache.REEF.Tang.Tests.Format;
+
+namespace Org.Apache.REEF.Tang.Tests.SmokeTest
+{
+ class TestConfigurationModuleBuilder : ConfigurationModuleBuilder
+ {
+ public static readonly string RequiredStringValue = "Required String Value";
+
+ public static readonly string OptionaStringValue = "Optional String Value";
+
+ public static readonly RequiredParameter<string> REQUIREDSTRING = new RequiredParameter<string>();
+
+ public static readonly OptionalParameter<string> OPTIONALSTRING = new OptionalParameter<string>();
+
+ public static readonly int NamedParameterIntegerValue = 42;
+
+ public static readonly double NamedParameterDoubleValue = 42.0;
+
+ public static ConfigurationModule CONF
+ {
+ get
+ {
+ return new TestConfigurationModuleBuilder()
+ .BindImplementation(GenericType<IRootInterface>.Class, GenericType<RootImplementation>.Class)
+ .BindNamedParameter<NamedParameterInteger, int>(GenericType<NamedParameterInteger>.Class, NamedParameterIntegerValue.ToString(CultureInfo.CurrentCulture))
+ .BindNamedParameter<NamedParameterDouble, double>(GenericType<NamedParameterDouble>.Class, NamedParameterDoubleValue.ToString(CultureInfo.CurrentCulture))
+ .BindSetEntry<SetOfInstances, SetInterfaceImplOne, ISetInterface>(GenericType<SetOfInstances>.Class, GenericType<SetInterfaceImplOne>.Class)
+ .BindSetEntry<SetOfInstances, SetInterfaceImplTwo, ISetInterface>(GenericType<SetOfInstances>.Class, GenericType<SetInterfaceImplTwo>.Class)
+ .BindNamedParameter(GenericType<RequiredString>.Class, REQUIREDSTRING)
+ .BindNamedParameter(GenericType<OptionalString>.Class, OPTIONALSTRING)
+ .BindSetEntry<SetOfBaseTypes.Integers, int>(GenericType<SetOfBaseTypes.Integers>.Class, "1")
+ .BindSetEntry<SetOfBaseTypes.Integers, int>(GenericType<SetOfBaseTypes.Integers>.Class, "2")
+ .BindSetEntry<SetOfBaseTypes.Integers, int>(GenericType<SetOfBaseTypes.Integers>.Class, "3")
+ .BindSetEntry<SetOfBaseTypes.Doubles, double>(GenericType<SetOfBaseTypes.Doubles>.Class, "1")
+ .BindSetEntry<SetOfBaseTypes.Doubles, double>(GenericType<SetOfBaseTypes.Doubles>.Class, "2")
+ .BindSetEntry<SetOfBaseTypes.Doubles, double>(GenericType<SetOfBaseTypes.Doubles>.Class, "3")
+ .BindSetEntry<SetOfBaseTypes.Strings, string>(GenericType<SetOfBaseTypes.Strings>.Class, "1")
+ .BindSetEntry<SetOfBaseTypes.Strings, string>(GenericType<SetOfBaseTypes.Strings>.Class, "2")
+ .BindSetEntry<SetOfBaseTypes.Strings, string>(GenericType<SetOfBaseTypes.Strings>.Class, "3")
+ .BindList<ListOfBaseTypes.Integers, int>(GenericType<ListOfBaseTypes.Integers>.Class, (new List<string>(new string[] { "1", "2", "3" })))
+ .BindList<ListOfBaseTypes.Doubles, double>(GenericType<ListOfBaseTypes.Doubles>.Class, (new List<string>(new string[] { "1", "2", "3" })))
+ .BindList<ListOfBaseTypes.Strings, string>(GenericType<ListOfBaseTypes.Strings>.Class, (new List<string>(new string[] { "1", "2", "3" })))
+ .Build();
+ }
+ }
+
+ [NamedParameter]
+ public class RequiredString : Name<string>
+ {
+ }
+
+ [NamedParameter]
+ public class SetOfInstances : Name<ISet<ISetInterface>>
+ {
+ }
+
+ [NamedParameter()]
+ public class NamedParameterDouble : Name<double>
+ {
+ }
+
+ [NamedParameter()]
+ public class IntegerHandler : Name<IHandler<int>>
+ {
+ }
+
+ [NamedParameter()]
+ public class StringHandler : Name<IHandler<string>>
+ {
+ }
+
+ [NamedParameter()]
+ public class NamedParameterInteger : Name<int>
+ {
+ }
+
+ [NamedParameter(DefaultValue = "default_string_default_value")]
+ public class OptionalString : Name<string>
+ {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestDefaultImpementaion.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestDefaultImpementaion.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestDefaultImpementaion.cs
new file mode 100644
index 0000000..848c99e
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestDefaultImpementaion.cs
@@ -0,0 +1,197 @@
+/**
+ * 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;
+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.Tang
+{
+ [DefaultImplementation(Name = "Org.Apache.REEF.Tang.Tests.Tang.HaveDefaultStringImplImpl")]
+ interface IHaveDefaultStringImpl
+ {
+ }
+
+ [DefaultImplementation(typeof(HaveDefaultImplImpl))]
+ interface IHaveDefaultImpl
+ {
+ }
+
+ interface IfaceWithDefault
+ {
+ }
+
+ [DefaultImplementation(typeof(AnInterfaceImplementation), "default")]
+ interface IAnInterface
+ {
+ void aMethod();
+ }
+
+ [TestClass]
+ public class TestDefaultImplmentation
+ {
+ [TestMethod]
+ public void TestDefaultConstructor()
+ {
+ ClassWithDefaultConstructor impl = (ClassWithDefaultConstructor)TangFactory.GetTang().NewInjector().GetInstance(typeof(ClassWithDefaultConstructor));
+ Assert.IsNotNull(impl);
+ }
+
+ [TestMethod]
+ public void TestDefaultImplementaion()
+ {
+ ClassWithDefaultConstructor impl = (ClassWithDefaultConstructor)TangFactory.GetTang().NewInjector().GetInstance(typeof(ClassWithDefaultConstructor));
+ Assert.IsNotNull(impl);
+ }
+
+ [TestMethod]
+ public void TestDefaultImplOnInterface()
+ {
+ IAnInterface impl = (IAnInterface)TangFactory.GetTang().NewInjector().GetInstance(typeof(IAnInterface));
+ Assert.IsNotNull(impl);
+ impl.aMethod();
+ }
+
+ [TestMethod]
+ public void TestGetInstanceOfNamedParameter()
+ {
+ IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+ IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
+ IfaceWithDefault iwd = i.GetNamedInstance<IfaceWithDefaultName, IfaceWithDefault>(GenericType<IfaceWithDefaultName>.Class);
+ Assert.IsNotNull(iwd);
+ }
+
+ [TestMethod]
+ public void TestCantGetInstanceOfNamedParameter()
+ {
+ string msg = null;
+ try
+ {
+ IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+ IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
+ i.GetInstance<IfaceWithDefaultName>();
+ msg = "getInstance() called on Name IfaceWithDefaultName Did you mean to call getNamedInstance() instead?";
+ }
+ catch (InjectionException e)
+ {
+ System.Diagnostics.Debug.WriteLine(e);
+ }
+ Assert.IsNull(msg);
+ }
+
+ [TestMethod]
+ public void TestCanGetDefaultedInterface()
+ {
+ Assert.IsNotNull(TangFactory.GetTang().NewInjector().GetInstance<IHaveDefaultImpl>());
+ }
+
+ [TestMethod]
+ public void TestCanOverrideDefaultedInterface()
+ {
+ ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+ cb.BindImplementation(GenericType<IHaveDefaultImpl>.Class, GenericType<OverrideDefaultImpl>.Class);
+ var o = TangFactory.GetTang().NewInjector(cb.Build()).GetInstance<IHaveDefaultImpl>();
+ Assert.IsTrue(o is OverrideDefaultImpl);
+ }
+
+ [TestMethod]
+ public void TestCanGetStringDefaultedInterface()
+ {
+ Assert.IsNotNull(TangFactory.GetTang().NewInjector().GetInstance<IHaveDefaultStringImpl>());
+ }
+
+ [TestMethod]
+ public void TestCanOverrideStringDefaultedInterface()
+ {
+ ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+ cb.BindImplementation(GenericType<IHaveDefaultStringImpl>.Class, GenericType<OverrideDefaultStringImpl>.Class);
+ var o = TangFactory.GetTang().NewInjector(cb.Build()).GetInstance<IHaveDefaultStringImpl>();
+ Assert.IsTrue(o is OverrideDefaultStringImpl);
+ }
+ }
+
+ public class AnInterfaceImplementation : IAnInterface
+ {
+ [Inject]
+ private AnInterfaceImplementation()
+ {
+ }
+
+ public void aMethod()
+ {
+ }
+ }
+
+ class IfaceWithDefaultDefaultImpl : IfaceWithDefault
+ {
+ [Inject]
+ IfaceWithDefaultDefaultImpl()
+ {
+ }
+ }
+
+ [NamedParameter(DefaultClass = typeof(IfaceWithDefaultDefaultImpl))]
+ class IfaceWithDefaultName : Name<IfaceWithDefault>
+ {
+ }
+
+ class HaveDefaultImplImpl : IHaveDefaultImpl
+ {
+ [Inject]
+ HaveDefaultImplImpl()
+ {
+ }
+ }
+
+ class OverrideDefaultImpl : IHaveDefaultImpl
+ {
+ [Inject]
+ public OverrideDefaultImpl()
+ {
+ }
+ }
+
+ class HaveDefaultStringImplImpl : IHaveDefaultStringImpl
+ {
+ [Inject]
+ HaveDefaultStringImplImpl()
+ {
+ }
+ }
+
+ class OverrideDefaultStringImpl : IHaveDefaultStringImpl
+ {
+ [Inject]
+ public OverrideDefaultStringImpl()
+ {
+ }
+ }
+
+ class ClassWithDefaultConstructor
+ {
+ [Inject]
+ public ClassWithDefaultConstructor()
+ {
+ }
+ }
+}
\ 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/Tang/TestExternalConstructors.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestExternalConstructors.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestExternalConstructors.cs
new file mode 100644
index 0000000..99377a2
--- /dev/null
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Tang/TestExternalConstructors.cs
@@ -0,0 +1,149 @@
+/**
+ * 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;
+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.Tang
+{
+ [TestClass]
+ public class TestExternalConstructors
+ {
+ static ITang tang;
+
+ [TestInitialize()]
+ public void TestSetup()
+ {
+ tang = TangFactory.GetTang();
+ }
+
+ [TestMethod]
+ public void TestBindConstructor()
+ {
+ ICsConfigurationBuilder b = TangFactory.GetTang().NewConfigurationBuilder();
+ b.BindConstructor(GenericType<A>.Class, GenericType<ACons>.Class);
+ b.BindConstructor(GenericType<B>.Class, GenericType<BCons>.Class);
+
+ TangFactory.GetTang().NewInjector(b.Build()).GetInstance(typeof(B));
+ }
+
+ [TestMethod]
+ public void TestSImpleExternalConstructor()
+ {
+ ICsConfigurationBuilder b = TangFactory.GetTang().NewConfigurationBuilder();
+ b.BindConstructor(GenericType<A>.Class, GenericType<ACons>.Class);
+ A aRef = (A)TangFactory.GetTang().NewInjector(b.Build()).GetInstance(typeof(A));
+ Assert.IsNotNull(aRef);
+ }
+
+ [TestMethod]
+ public void TestExternalLegacyConstructor()
+ {
+ ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
+ cb.BindConstructor(GenericType<ExternalConstructorExample.Legacy>.Class, GenericType<ExternalConstructorExample.LegacyWrapper>.Class);
+ IInjector i = tang.NewInjector(cb.Build());
+ i.BindVolatileInstance(GenericType<int>.Class, 42);
+ i.BindVolatileInstance(GenericType<string>.Class, "The meaning of life is ");
+ ExternalConstructorExample.Legacy l = i.GetInstance<ExternalConstructorExample.Legacy>();
+ Assert.AreEqual(42, l.X);
+ Assert.AreEqual("The meaning of life is ", l.Y);
+ }
+
+ public class A
+ {
+ public A()
+ {
+ }
+ }
+
+ public class B
+ {
+ public B(A a)
+ {
+ }
+ }
+
+ public class ACons : IExternalConstructor<A>
+ {
+ [Inject]
+ ACons()
+ {
+ }
+
+ public A NewInstance()
+ {
+ return new A();
+ }
+ }
+
+ public class BCons : IExternalConstructor<B>
+ {
+ private A a;
+ [Inject]
+ BCons(A a)
+ {
+ this.a = a;
+ }
+
+ public B NewInstance()
+ {
+ return new B(a);
+ }
+ }
+ }
+
+ class ExternalConstructorExample
+ {
+ public class Legacy
+ {
+ public Legacy(int x, string y)
+ {
+ this.X = x;
+ this.Y = y;
+ }
+
+ public int X { get; set; }
+
+ public string Y { get; set; }
+ }
+
+ public class LegacyWrapper : IExternalConstructor<Legacy>
+ {
+ [Inject]
+ LegacyWrapper(int x, string y)
+ {
+ this.X = x;
+ this.Y = y;
+ }
+
+ public int X { get; set; }
+
+ public string Y { get; set; }
+
+ public Legacy NewInstance()
+ {
+ return new Legacy(X, Y);
+ }
+ }
+ }
+}
\ No newline at end of file