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/19 18:38:41 UTC
incubator-reef git commit: [REEF-161] Adding test cases for
BindVolatileParameter for set
Repository: incubator-reef
Updated Branches:
refs/heads/master d6c2c9e17 -> 6027631be
[REEF-161] Adding test cases for BindVolatileParameter for set
This PR is to add test cases for BindVolatileParameter in Tang.Tests.
Especially for the following two cases:
* For named parameter that is a ISet<Interface>.
* To inject an interface, whose implementation has a named parameter
that is a set of the same interface
JIRA:
[REEF-161] https://issues.apache.org/jira/browse/REEF-161
Pull Request:
This closes #82
Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/6027631b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/6027631b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/6027631b
Branch: refs/heads/master
Commit: 6027631be97e950746d97e5006adda547f05779d
Parents: d6c2c9e
Author: Julia Wang <jw...@yahoo.com>
Authored: Tue Feb 17 09:31:25 2015 -0800
Committer: Markus Weimer <we...@apache.org>
Committed: Thu Feb 19 09:36:33 2015 -0800
----------------------------------------------------------------------
.../Injection/TestSetInjection.cs | 56 ++++++++++++++++++--
1 file changed, 53 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/6027631b/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
index a360a13..0350249 100644
--- a/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestSetInjection.cs
+++ b/lang/cs/Org.Apache.REEF.Tang.Tests/Injection/TestSetInjection.cs
@@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Org.Apache.REEF.Tang.Annotations;
using Org.Apache.REEF.Tang.Formats;
@@ -57,7 +58,6 @@ namespace Org.Apache.REEF.Tang.Tests.Injection
Assert.IsTrue(actual.Contains("one"));
Assert.IsTrue(actual.Contains("two"));
Assert.IsTrue(actual.Contains("three"));
- //Assert.AreEqual(expected, actual);
}
[TestMethod]
@@ -73,11 +73,44 @@ namespace Org.Apache.REEF.Tang.Tests.Injection
Assert.IsTrue(actual.Contains(new Integer(42)));
Assert.IsTrue(actual.Contains(new Float(42.0001f)));
- //Assert.AreEqual(expected, actual);
+ Assert.AreEqual(actual.Count, expected.Count);
}
[TestMethod]
- public void testStringInjectBound()
+ public void TestBindVolatileParameterForSet()
+ {
+ IInjector i = TangFactory.GetTang().NewInjector();
+ ISet<INumber> numbers = new HashSet<INumber>();
+ numbers.Add(new Integer(42));
+ numbers.Add(new Float(42.0001f));
+ i.BindVolatileParameter(GenericType<SetOfClasses>.Class, numbers);
+ ISet<INumber> actual = ((Pool)i.GetInstance(typeof(Pool))).Numbers;
+
+ Assert.IsTrue(actual.Contains(new Integer(42)));
+ Assert.IsTrue(actual.Contains(new Float(42.0001f)));
+ }
+
+ [TestMethod]
+ public void TestInjectionWithSetFromSameInterface()
+ {
+ IConfiguration c = TangFactory.GetTang()
+ .NewConfigurationBuilder()
+ .BindImplementation(GenericType<INumber>.Class, GenericType<PoolNumber>.Class)
+ .Build();
+
+ IInjector i = TangFactory.GetTang().NewInjector(c);
+ ISet<INumber> numbers = new HashSet<INumber>();
+ numbers.Add(new Integer(42));
+ numbers.Add(new Float(42.0001f));
+ i.BindVolatileParameter(GenericType<SetOfClasses>.Class, numbers);
+ var actual = ((PoolNumber)i.GetInstance(typeof(INumber))).Numbers;
+
+ Assert.IsTrue(actual.Contains(new Integer(42)));
+ Assert.IsTrue(actual.Contains(new Float(42.0001f)));
+ }
+
+ [TestMethod]
+ public void TestStringInjectBound()
{
ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
cb.BindSetEntry<SetOfNumbers, string>(GenericType<SetOfNumbers>.Class, "four");
@@ -94,6 +127,7 @@ namespace Org.Apache.REEF.Tang.Tests.Injection
Assert.IsTrue(actual.Contains("four"));
Assert.IsTrue(actual.Contains("five"));
Assert.IsTrue(actual.Contains("six"));
+ Assert.AreEqual(actual.Count, expected.Count);
}
[TestMethod]
@@ -320,6 +354,22 @@ namespace Org.Apache.REEF.Tang.Tests.Injection
public ISet<INumber> Numbers { get; set; }
}
+ public class PoolNumber : INumber
+ {
+ [Inject]
+ private PoolNumber([Parameter(typeof(SetOfClasses))] ISet<INumber> numbers)
+ {
+ this.Numbers = numbers;
+ }
+
+ public ISet<INumber> Numbers { get; set; }
+
+ public int CompareTo(object obj)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
[NamedParameter(DefaultClass = typeof(Integer))]
public class SetOfClassesDefaultClass : Name<ISet<INumber>>
{