Exemple #1
0
        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();
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public static IConfiguration GetConfiguration(byte[] configStream)
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            AddConfigurationFromStream(cb, configStream);
            return(cb.Build());
        }
Exemple #4
0
        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);
        }
Exemple #6
0
        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());
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        public void TestBoolParameterWithDefault()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
            var       o = i.GetInstance <BooleanTest>();

            o.Verify(false);
        }
Exemple #9
0
        public void TestOptionalParameterWithDefault()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
            var       o = i.GetInstance <StringTest>();

            o.Verify(" ");
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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));
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        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);
        }
Exemple #18
0
        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");
        }
Exemple #19
0
        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);
        }
Exemple #20
0
        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);
        }
Exemple #21
0
        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');
        }
Exemple #22
0
        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);
        }
Exemple #24
0
        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);
        }
Exemple #25
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());
        }
Exemple #26
0
        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);
        }
Exemple #28
0
        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);
        }
Exemple #29
0
        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);
        }
Exemple #30
0
        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());
        }