public void TestTimerConfiguration() { Type timerType = typeof(Timer); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); cb.BindNamedParameter <Timer.Seconds, Int32>(GenericType <Timer.Seconds> .Class, "2"); IConfiguration conf = cb.Build(); ConfigurationFile.WriteConfigurationFile(conf, "timerConf.txt"); IDictionary <string, string> p = ConfigurationFile.FromFile("timerConf.txt"); ITang tang1 = TangFactory.GetTang(); ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Examples }); ConfigurationFile.AddConfigurationFromFile(cb1, "timerConf.txt"); IConfiguration conf1 = cb1.Build(); IInjector injector = tang.NewInjector(conf1); var timer = (Timer)injector.GetInstance(timerType); Assert.IsNotNull(timer); timer.sleep(); }
public void TestMultipleConfiguration() { Type activityInterfaceType = typeof(ITask); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Common, FileNames.Tasks }); cb.BindImplementation(GenericType <ITask> .Class, GenericType <HelloTask> .Class); cb.BindNamedParameter <TaskConfigurationOptions.Identifier, string>( GenericType <TaskConfigurationOptions.Identifier> .Class, "Hello Task"); IConfiguration conf = cb.Build(); IConfiguration httpConfiguraiton = HttpHandlerConfiguration.CONF .Set(HttpHandlerConfiguration.P, GenericType <HttpServerReefEventHandler> .Class) .Set(HttpHandlerConfiguration.P, GenericType <HttpServerNrtEventHandler> .Class) .Build(); IInjector injector = TangFactory.GetTang().NewInjector(new IConfiguration[] { conf, httpConfiguraiton }); var activityRef = (ITask)injector.GetInstance(activityInterfaceType); Assert.IsNotNull(activityRef); RuntimeClock clock = injector.GetInstance <RuntimeClock>(); var rh = clock.ClockRuntimeStartHandler.Get(); Assert.AreEqual(rh.Count, 1); }
public static IConfiguration GetConfiguration(byte[] configStream) { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); AddConfigurationFromStream(cb, configStream); return(cb.Build()); }
public ForksInjectorInConstructor(IInjector i) { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { @"Org.Apache.REEF.Tang.Examples" }); //// cb.BindImplementation(Number.class, typeof(Int32)); i.ForkInjector(cb.Build()); }
public void TestInterface() { g(typeof(A)); g(typeof(MyInterface <int>)); g(typeof(MyInterface <string>)); g(typeof(B)); ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(); cb.BindImplementation(GenericType <MyInterface <string> > .Class, GenericType <MyImplString> .Class); cb.BindImplementation(GenericType <MyInterface <int> > .Class, GenericType <MyImplInt> .Class); IConfiguration conf = cb.Build(); IInjector i = tang.NewInjector(conf); var a = (A)i.GetInstance(typeof(A)); var implString = (MyImplString)i.GetInstance(typeof(MyImplString)); var implInt = (MyImplString)i.GetInstance(typeof(MyImplString)); var b = (B)i.GetInstance(typeof(B)); var c = (C)i.GetInstance(typeof(C)); Assert.IsNotNull(a); Assert.IsNotNull(implString); Assert.IsNotNull(implInt); Assert.IsNotNull(b); Assert.IsNotNull(c); }
public void TestNamedParameterInjectionFutureDefaultImpl() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); PickyFuturist f = (PickyFuturist)i.GetInstance(typeof(PickyFuturist)); Assert.IsNotNull(f.getMyCar()); }
public void TestBextendsAinjectA() { ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(); cb.BindImplementation(GenericType <BextendsAinjectA.A> .Class, GenericType <BextendsAinjectA.A> .Class); BextendsAinjectA.A a = tang.NewInjector(cb.Build()).GetInstance <BextendsAinjectA.A>(); Assert.IsNotNull(a); }
public void TestBoolParameterWithDefault() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); var o = i.GetInstance <BooleanTest>(); o.Verify(false); }
public void TestOptionalParameterWithDefault() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); var o = i.GetInstance <StringTest>(); o.Verify(" "); }
public void TestBindImplementation() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); cb.BindImplementation <Interf, Impl>(); Interf o = TangFactory.GetTang().NewInjector(cb.Build()).GetInstance <Interf>(); Assert.True(o is Impl); }
public void TestSetOfClassWithDefault() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); ISet <INumber> actual = i.GetInstance <Pool1>().Numbers; Assert.NotNull(actual); }
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); }
public void TestMultipleLayersFromInterface() { ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(); cb.BindImplementation(GenericType <IMultiLayer> .Class, GenericType <LowerLayerImpl> .Class); IMultiLayer o = tang.NewInjector(cb.Build()).GetInstance <IMultiLayer>(); Assert.IsNotNull(o); }
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 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)); }
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); }
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.Equal(id, trackingId); }
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"); }
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); }
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); }
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'); }
public void TestBindStringNamedParam() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); cb.BindStringNamedParam <StringTest.NamedString>("foo"); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); var o = i.GetInstance <StringTest>(); o.Verify("foo"); }
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); }
public void TestSetOfTimeshiftWithEmptySet() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); ISet <ITimeshift> actual = i.GetInstance <SetofTimeShiftClassWithoutDefault>().Timeshifts; Assert.True(actual.Count == 0); }
public void TestNamedParameterInjectionFuture() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); cb.BindImplementation(GenericType <FlyingCar> .Class, GenericType <FlyingCar> .Class); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); PickyFuturist f = (PickyFuturist)i.GetInstance(typeof(PickyFuturist)); Assert.IsNotNull(f.getMyCar()); }
public void TestBindIntNamedParam() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); cb.BindIntNamedParam <Int32Test.NamedInt>("8"); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); var o = i.GetInstance <Int32Test>(); o.Verify(8); }
public void testEndToEnd() { ITang tang = TangFactory.GetTang(); ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new Type[] { typeof(BarParser) }); cb.BindNamedParameter <SomeNamedFoo, Foo>(GenericType <SomeNamedFoo> .Class, "hdfs://woot"); ILikeBars ilb = tang.NewInjector(cb.Build()).GetInstance <ILikeBars>(); Assert.IsNotNull(ilb); }
public void TestBindNamedParam() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); cb.BindNamedParam <BooleanTest.NamedBool, bool>("true"); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); var o = i.GetInstance <BooleanTest>(); o.Verify(true); }
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); }
public void testFutures() { ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); IInjector i2 = TangFactory.GetTang().NewInjector(cb.Build()); Futurist f = (Futurist)i.GetInstance(typeof(Futurist)); Assert.IsTrue(f == f.getMyCar().getDriver()); Assert.IsTrue(f.getMyCar() == f.getMyCar().getDriver().getMyCar()); Futurist f2 = (Futurist)i2.GetInstance(typeof(Futurist)); Assert.IsTrue(f2 == f2.getMyCar().getDriver()); Assert.IsTrue(f2.getMyCar() == f2.getMyCar().getDriver().getMyCar()); Assert.IsTrue(f != f2.getMyCar().getDriver()); Assert.IsTrue(f.getMyCar() != f2.getMyCar().getDriver().getMyCar()); }