Exemplo n.º 1
0
        public void TestRepeatedNamedArgs()
        {
            IInjector i = tang.NewInjector();

            i.BindVolatileParameter(GenericType <RepeatedNamedSingletonArgs.A> .Class,
                                    (MustBeSingleton)i.GetInstance(typeof(MustBeSingleton)));
            i.BindVolatileParameter(GenericType <RepeatedNamedSingletonArgs.B> .Class,
                                    (MustBeSingleton)i.GetInstance(typeof(MustBeSingleton)));
            i.GetInstance(typeof(RepeatedNamedSingletonArgs));
        }
Exemplo n.º 2
0
        public void TestWantSomeHandlersBadOrder()
        {
            IInjector i  = TangFactory.GetTang().NewInjector();
            var       o1 = i.GetInstance <IAHandler>();
            var       o2 = i.GetInstance <IBHandler>();
            var       o3 = i.GetInstance <WantSomeFutureHandlers>();

            Assert.IsTrue(o1 is AHandlerImpl);
            Assert.IsTrue(o2 is BHandlerImpl);
            Assert.IsNotNull(o3);
        }
Exemplo n.º 3
0
        public void SingletonTest()
        {
            IConfiguration c = new MyConfigurationModule()
                               .BindImplementation(GenericType <IFoo> .Class, MyConfigurationModule.TheFoo)
                               .BindNamedParameter(GenericType <Fooness> .Class, MyConfigurationModule.FooNess)
                               .Build()
                               .Set(MyConfigurationModule.TheFoo, GenericType <FooImpl> .Class)
                               .Build();
            IInjector i = TangFactory.GetTang().NewInjector(c);

            Assert.IsTrue(i.GetInstance(typeof(IFoo)) == i.GetInstance(typeof(IFoo)));
        }
Exemplo n.º 4
0
        public void TestReuseFailedInjector()
        {
            IInjector i = TangFactory.GetTang().NewInjector();

            try
            {
                i.GetInstance <Fail>();
                Assert.Fail("Injecting Fail should not have worked!");
            } catch (InjectionException)
            {
                i.GetInstance <Pass>();
            }
        }
Exemplo n.º 5
0
        internal static void TestRun(IConfiguration driverConfig, Type globalAssemblyType, int numberOfEvaluator, string jobIdentifier = "myDriver", string runOnYarn = "local", string runtimeFolder = DefaultRuntimeFolder)
        {
            IInjector injector          = TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(runOnYarn, numberOfEvaluator, runtimeFolder));
            var       reefClient        = injector.GetInstance <IREEFClient>();
            var       jobRequestBuilder = injector.GetInstance <JobRequestBuilder>();
            var       jobSubmission     = jobRequestBuilder
                                          .AddDriverConfiguration(driverConfig)
                                          .AddGlobalAssemblyForType(globalAssemblyType)
                                          .SetJobIdentifier(jobIdentifier)
                                          .Build();

            reefClient.SubmitAndGetJobStatus(jobSubmission);
        }
Exemplo n.º 6
0
        public GroupCommClient(
            [Parameter(typeof(GroupCommConfigurationOptions.SerializedGroupConfigs))] ISet <string> groupConfigs,
            [Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId,
            StreamingNetworkService <GeneralGroupCommunicationMessage> networkService,
            AvroConfigurationSerializer configSerializer,
            IInjector injector)
        {
            _commGroups     = new Dictionary <string, ICommunicationGroupClientInternal>();
            _networkService = networkService;

            foreach (string serializedGroupConfig in groupConfigs)
            {
                IConfiguration groupConfig     = configSerializer.FromString(serializedGroupConfig);
                IInjector      groupInjector   = injector.ForkInjector(groupConfig);
                var            commGroupClient = (ICommunicationGroupClientInternal)groupInjector.GetInstance <ICommunicationGroupClient>();
                _commGroups[commGroupClient.GroupName] = commGroupClient;
            }

            networkService.Register(new StringIdentifier(taskId));

            foreach (var group in _commGroups.Values)
            {
                group.WaitingForRegistration();
            }
        }
Exemplo n.º 7
0
        public void TestActivityConfigWithSeperateAssembly()
        {
            Type activityInterfaceType = typeof(com.microsoft.reef.activity.IActivity);
            var  a            = Assembly.Load(@"com.microsoft.reef.activity");
            Type activityType = a.GetType("com.microsoft.reef.activity.HelloActivity");

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file2, file3 });

            cb.BindImplementation(activityInterfaceType, activityType);
            IConfiguration conf = cb.Build();

            ConfigurationFile.WriteConfigurationFile(conf, "activityConf1.txt");
            IDictionary <string, string> p = ReadFromFile("activityConf1.txt");

            IInjector injector    = tang.NewInjector(new string[] { file2, file3 }, "activityConf1.txt");
            var       activityRef = (com.microsoft.reef.activity.IActivity)injector.GetInstance(activityInterfaceType);

            //combined line sample
            var o = (com.microsoft.reef.activity.IActivity)TangFactory.GetTang()
                    .NewInjector(new string[] { file2, file3 }, "activityConf1.txt")
                    .GetInstance(typeof(com.microsoft.reef.activity.IActivity));

            Assert.IsNotNull(activityRef);
            //byte[] b = new byte[10];
            //activityRef.Call(b);
        }
Exemplo n.º 8
0
        public void TestActivityConfiguration()
        {
            Type activityInterfaceType = typeof(com.microsoft.reef.activity.IActivity);
            var  a            = Assembly.Load(@"com.microsoft.reef.activity");
            var  a1           = Assembly.Load(@"com.microsoft.reef.activityInterface");
            Type activityType = a.GetType("com.microsoft.reef.activity.HelloActivity");
            //Type activityType = typeof(com.microsoft.reef.activity.HelloActivity);

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file2, file3 });

            cb.BindImplementation(activityInterfaceType, activityType);
            Type namedParameter = a1.GetType(@"com.microsoft.reef.driver.activity.ActivityConfigurationOptions+Identifier");

            cb.BindNamedParameter(namedParameter, "Hello Activity");
            IConfiguration conf = cb.Build();

            ConfigurationFile.WriteConfigurationFile(conf, "activityConf.txt");
            IDictionary <string, string> p = ReadFromFile("activityConf.txt");


            ITang tang1 = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { file2, file3 });

            ConfigurationFile.AddConfiguration(cb1, "activityConf.txt");
            IConfiguration conf1 = cb1.Build();

            IInjector injector    = tang1.NewInjector(conf1);
            var       activityRef = (com.microsoft.reef.activity.IActivity)injector.GetInstance(activityInterfaceType);

            Assert.IsNotNull(activityRef);

            //byte[] b = new byte[10];
            //activityRef.Call(b);
        }
Exemplo n.º 9
0
        public void TestTimerConfigurationWithClassHierarchy()
        {
            Type timerType      = typeof(Com.Microsoft.Tang.Examples.Timer);
            Type namedParameter = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds");

            ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(file);

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(classHierarchyImpl);

            cb.BindNamedParameter(namedParameter, "1");
            IConfiguration conf = cb.Build();

            ConfigurationFile.WriteConfigurationFile(conf, "timerConfH.txt");
            IDictionary <string, string> p = ReadFromFile("timerConfH.txt");

            ITang tang1 = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { file });

            ConfigurationFile.AddConfiguration(cb1, "timerConfH.txt");
            IConfiguration conf1 = cb1.Build();

            IInjector injector = tang1.NewInjector(conf1);
            var       timer    = (Com.Microsoft.Tang.Examples.Timer)injector.GetInstance(timerType);

            Assert.IsNotNull(timer);
            timer.sleep();
        }
Exemplo n.º 10
0
        public void TestTweetConfiguration()
        {
            Type  tweeterType          = typeof(Com.Microsoft.Tang.Examples.Tweeter);
            Type  namedParameter       = asm.GetType(@"Com.Microsoft.Tang.Examples.Tweeter+PhoneNumber");
            ITang tang                 = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file });

            cb.BindImplementation(typeof(TweetFactory), typeof(MockTweetFactory));
            cb.BindImplementation(typeof(SMS), typeof(MockSMS));
            cb.BindNamedParameter(namedParameter, "8675309");
            IConfiguration conf = cb.Build();

            ConfigurationFile.WriteConfigurationFile(conf, "tweeterConf.txt");
            IDictionary <string, string> p = ReadFromFile("tweeterConf.txt");

            ITang tang1 = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { file });

            ConfigurationFile.AddConfiguration(cb1, "tweeterConf.txt");
            IConfiguration conf1 = cb1.Build();

            IInjector injector = tang1.NewInjector(conf1);
            var       tweeter  = (Com.Microsoft.Tang.Examples.Tweeter)injector.GetInstance(tweeterType);

            tweeter.sendMessage();
        }
Exemplo n.º 11
0
        public void TestHelloStreamingActivityWithBinding()
        {
            Type activityInterfaceType = typeof(com.microsoft.reef.activity.IActivity);
            var  a  = Assembly.Load(@"com.microsoft.reef.activity");
            var  a1 = Assembly.Load(@"com.microsoft.reef.activityInterface");

            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { file2, file3 });

            Type activityType = a.GetType("com.microsoft.reef.activity.StreamActivity1");

            cb.BindImplementation(activityInterfaceType, activityType);
            Type namedParameterId = a1.GetType(@"com.microsoft.reef.driver.activity.ActivityConfigurationOptions+Identifier");

            cb.BindNamedParameter(namedParameterId, "Hello Stereaming");
            Type namedParameterIp = a.GetType(@"com.microsoft.reef.activity.StreamActivity1+IpAddress");

            cb.BindNamedParameter(namedParameterIp, "127.0.0.0");

            IConfiguration conf        = cb.Build();
            IInjector      injector    = tang.NewInjector(conf);
            var            activityRef = (com.microsoft.reef.activity.IActivity)injector.GetInstance(activityInterfaceType);

            Assert.IsNotNull(activityRef);

            byte[] b = new byte[10];
            //activityRef.Call(b);
        }
Exemplo n.º 12
0
        public void TestOnlyIntParameter()
        {
            //Multiple infeasible plans: Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest
            //, Org.Apache.Reef.Tang.Test
            //, Version=1.0.0.0
            //, Culture=neutral
            //, PublicKeyToken=null:
            //  [ Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest = new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest
            //    ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool =
            //    , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = 8
            //    )
            //    | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest
            //    ( System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString =
            //    , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = 8
            //    )
            //    | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest
            //    ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool =
            //    , System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString =
            //    , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = 8
            //    )
            //  ]
            MultiConstructorTest obj = null;

            try
            {
                ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
                cb.BindNamedParameter <MultiConstructorTest.NamedInt, int>(GenericType <MultiConstructorTest.NamedInt> .Class, "8");
                IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
                obj = i.GetInstance <MultiConstructorTest>();
            }
            catch (InjectionException)
            {
            }
            Assert.IsNull(obj);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Create a new ContextRuntime.
        /// </summary>
        /// <param name="serviceInjector"></param>
        /// <param name="contextConfiguration">the Configuration for this context.</param>
        /// <param name="parentContext"></param>
        public ContextRuntime(
            IInjector serviceInjector,
            IConfiguration contextConfiguration,
            Optional <ContextRuntime> parentContext)
        {
            _serviceInjector = serviceInjector;

            // Note that for Service objects and handlers, we are not merging them into a separate
            // class (e.g. ServiceContainer) due to the inability to allow service stacking if an instance
            // of such a class were to be materialized. i.e. if a ServiceContainer object were initialized
            // and a child ServiceConfiguration is submitted, when the child service injector tries to
            // get the relevant handlers and services set, it will get the same set of handlers as
            // previously instantiated by the parent injector, and thus will not allow the stacking
            // of ServiceConfigurations.
            _injectedServices = serviceInjector.GetNamedInstance <ServicesSet, ISet <object> >();

            _serviceContextStartHandlers =
                serviceInjector.GetNamedInstance <ContextConfigurationOptions.StartHandlers, ISet <IObserver <IContextStart> > >();

            _serviceContextStopHandlers =
                serviceInjector.GetNamedInstance <ContextConfigurationOptions.StopHandlers, ISet <IObserver <IContextStop> > >();

            _serviceTaskStartHandlers =
                serviceInjector.GetNamedInstance <TaskConfigurationOptions.StartHandlers, ISet <IObserver <ITaskStart> > >();

            _serviceTaskStopHandlers =
                serviceInjector.GetNamedInstance <TaskConfigurationOptions.StopHandlers, ISet <IObserver <ITaskStop> > >();

            _contextInjector  = serviceInjector.ForkInjector(contextConfiguration);
            _contextLifeCycle = _contextInjector.GetInstance <ContextLifeCycle>();
            _parentContext    = parentContext;
            _contextLifeCycle.Start();
        }
Exemplo n.º 14
0
        public void TestActivityConfiguration()
        {
            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();

            ConfigurationFile.WriteConfigurationFile(conf, "TaskConf.txt");
            IDictionary <string, string> p = ConfigurationFile.FromFile("TaskConf.txt");

            ITang tang1 = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Common, FileNames.Tasks });

            ConfigurationFile.AddConfigurationFromFile(cb1, "TaskConf.txt");
            IConfiguration conf1 = cb1.Build();

            IInjector injector    = tang1.NewInjector(conf1);
            var       activityRef = (ITask)injector.GetInstance(activityInterfaceType);

            Assert.NotNull(activityRef);
        }
Exemplo n.º 15
0
        private CommunicationGroupClient(
            [Parameter(typeof(GroupCommConfigurationOptions.CommunicationGroupName))] string groupName,
            [Parameter(typeof(GroupCommConfigurationOptions.SerializedOperatorConfigs))] ISet <string> operatorConfigs,
            IGroupCommNetworkObserver groupCommNetworkObserver,
            AvroConfigurationSerializer configSerializer,
            ICommunicationGroupNetworkObserver commGroupNetworkHandler,
            IInjector injector)
        {
            _operators = new Dictionary <string, object>();

            GroupName = groupName;
            groupCommNetworkObserver.Register(groupName, commGroupNetworkHandler);

            foreach (string operatorConfigStr in operatorConfigs)
            {
                IConfiguration operatorConfig = configSerializer.FromString(operatorConfigStr);

                IInjector operatorInjector = injector.ForkInjector(operatorConfig);
                string    operatorName     = operatorInjector.GetNamedInstance <GroupCommConfigurationOptions.OperatorName, string>(
                    GenericType <GroupCommConfigurationOptions.OperatorName> .Class);
                string msgType = operatorInjector.GetNamedInstance <GroupCommConfigurationOptions.MessageType, string>(
                    GenericType <GroupCommConfigurationOptions.MessageType> .Class);

                Type groupCommOperatorGenericInterface = typeof(IGroupCommOperator <>);
                Type groupCommOperatorInterface        = groupCommOperatorGenericInterface.MakeGenericType(Type.GetType(msgType));
                var  operatorObj = operatorInjector.GetInstance(groupCommOperatorInterface);
                _operators.Add(operatorName, operatorObj);
            }
        }
Exemplo n.º 16
0
        public void TaskConfigurationTest()
        {
            IConfiguration conf1 = TaskConfiguration.Conf
                                   .Set(TaskConfiguration.IDENTIFIER, "sample task")
                                   .Set(TaskConfiguration.TASK, GenericType <HelloTask> .Class)
                                   .Set(TaskConfiguration.ONCLOSE, GenericType <TaskCloseHandler> .Class)
                                   .Set(TaskConfiguration.MEMENTO, "Test")
                                   .Set(TaskConfiguration.ONSUSPEND, GenericType <SuspendHandler> .Class)
                                   .Set(TaskConfiguration.ONMESSAGE,
                                        GenericType <DriverMessageHandler> .Class)
                                   .Set(TaskConfiguration.ONSENDMESSAGE, GenericType <TaskMsg> .Class)
                                   .Set(TaskConfiguration.ONTASKSTARTED,
                                        GenericType <TaskStartHandler> .Class)
                                   .Set(TaskConfiguration.ONTASKSTOP,
                                        GenericType <TaskStopHandler> .Class)
                                   .Build();

            IInjector injector1 = TangFactory.GetTang().NewInjector(conf1);
            var       task1     = (HelloTask)injector1.GetInstance(typeof(ITask));

            Assert.NotNull(task1);

            var serializer = new AvroConfigurationSerializer();

            byte[]         bytes = serializer.ToByteArray(conf1);
            IConfiguration conf2 = serializer.FromByteArray(bytes);

            IInjector injector2 = TangFactory.GetTang().NewInjector(conf2);
            var       task2     = (HelloTask)injector2.GetInstance(typeof(ITask));

            Assert.NotNull(task2);
        }
Exemplo n.º 17
0
        public void OnNext(IDriverMessage value)
        {
            IDriverMessageHandler messageHandler = null;

            LOGGER.Log(Level.Info, "TaskRuntime::OnNext(IDriverMessage value)");
            try
            {
                messageHandler = _injector.GetInstance <IDriverMessageHandler>();
            }
            catch (Exception e)
            {
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.CaughtAndThrow(e, Level.Error, "Received Driver message, but unable to inject handler for driver message ", LOGGER);
            }
            if (messageHandler != null)
            {
                try
                {
                    messageHandler.Handle(value);
                }
                catch (Exception e)
                {
                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Warning, "Exception throw when handling driver message: " + e, LOGGER);
                    _currentStatus.RecordExecptionWithoutHeartbeat(e);
                }
            }
        }
Exemplo n.º 18
0
        public void TestMultiLayersWithNoInjectableDefaultConstructor()
        {
            TangImpl.Reset();

            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.BindImplementation(typeof(IH), typeof(L1));
            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
            var       o = i.GetInstance <IH>();

            Assert.NotNull(o);

            ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder();

            cb2.BindImplementation(typeof(IH), typeof(M1));  // M1 doesn't have injectable default constructor, no implementation L1 is bound to M1
            IInjector i2  = TangFactory.GetTang().NewInjector(cb2.Build());
            string    msg = null;

            try
            {
                var o2 = i2.GetInstance <IH>();
                Assert.True(o2 is L1);
            }
            catch (Exception e)
            {
                // Cannot inject Org.Apache.REEF.Tang.Tests.Injection.IH, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null:
                // No known implementations / injectable constructors for Org.Apache.REEF.Tang.Tests.Injection.M1, Org.Apache.REEF.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
                msg = e.Message;
            }
            Assert.NotNull(msg);
        }
Exemplo n.º 19
0
        public void TestDocumentLoadNamedParameterConfiguration()
        {
            Type  documentedLocalNamedParameterType = typeof(DocumentedLocalNamedParameter);
            ITang tang = TangFactory.GetTang();
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples });

            cb.BindNamedParameter <DocumentedLocalNamedParameter.Foo, string>(
                GenericType <DocumentedLocalNamedParameter.Foo> .Class, "Hello");
            IConfiguration conf = cb.Build();

            ConfigurationFile.WriteConfigurationFile(conf, "docLoadConf.txt");
            IDictionary <string, string> p = ConfigurationFile.FromFile("docLoadConf.txt");

            ITang tang1 = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Examples });

            ConfigurationFile.AddConfigurationFromFile(cb1, "docLoadConf.txt");
            IConfiguration conf1 = cb1.Build();

            IInjector injector = tang1.NewInjector(conf1);
            var       doc      = (DocumentedLocalNamedParameter)injector.GetInstance(documentedLocalNamedParameterType);

            Assert.NotNull(doc);
            var s = doc.ToString();
        }
Exemplo n.º 20
0
        public void TestTwoNamedStringArgsBindVolatile()
        {
            ICsConfigurationBuilder cb = tang.NewConfigurationBuilder();
            TwoNamedStringArgs      a  = tang.NewInjector(cb.Build()).GetInstance <TwoNamedStringArgs>();

            Assert.AreEqual("defaultA", a.a);
            Assert.AreEqual("defaultB", a.b);
            IInjector i = tang.NewInjector(cb.Build());

            i.BindVolatileParameter(GenericType <TwoNamedStringArgs.A> .Class, "not defaultA");
            i.BindVolatileParameter(GenericType <TwoNamedStringArgs.B> .Class, "not defaultB");
            Assert.AreEqual("not defaultA",
                            i.GetInstance <TwoNamedStringArgs>().a);
            Assert.AreEqual("not defaultB",
                            i.GetInstance <TwoNamedStringArgs>().b);
        }
Exemplo n.º 21
0
        public void TestMissingAllParameters()
        {
            // Multiple infeasible plans: Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest
            // , Org.Apache.REEF.Tang.Test
            // , Version=1.0.0.0
            // , Culture=neutral
            // , PublicKeyToken=null:
            // [ Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest = new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest
            //   ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool =
            //   , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt =
            //   )
            //   | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest
            //   ( System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString =
            //   , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt =
            //   )
            //   | new Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest
            //   ( System.Boolean Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedBool =
            //   , System.String Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedString =
            //   , System.Int32 Org.Apache.REEF.Tang.Tests.Injection.MultiConstructorTest+NamedInt =
            //   )
            // ]
            MultiConstructorTest obj = null;

            try
            {
                ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
                IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
                obj = i.GetInstance <MultiConstructorTest>();
            }
            catch (InjectionException)
            {
            }
            Assert.Null(obj);
        }
Exemplo n.º 22
0
 public void before()
 {
     context  = new Context();
     injector = context.injector;
     injector.Map <IDirectCommandMap>().ToType <DirectCommandMap>();
     subject = injector.GetInstance <IDirectCommandMap>() as DirectCommandMap;
 }
Exemplo n.º 23
0
        public void TestBoundToDelegatingInterface()
        {
            IInjector i = TangFactory.GetTang().NewInjector();
            C         c = (C)i.GetInstance(typeof(IBinj));

            Assert.IsNotNull(c);
        }
Exemplo n.º 24
0
        public GroupCommClient(
            [Parameter(typeof(GroupCommConfigurationOptions.SerializedGroupConfigs))] ISet <string> groupConfigs,
            [Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId,
            StreamingNetworkService <GeneralGroupCommunicationMessage> networkService,
            AvroConfigurationSerializer configSerializer,
            IInjector injector)
        {
            _commGroups     = new Dictionary <string, ICommunicationGroupClientInternal>();
            _networkService = networkService;

            foreach (string serializedGroupConfig in groupConfigs)
            {
                IConfiguration groupConfig     = configSerializer.FromString(serializedGroupConfig);
                IInjector      groupInjector   = injector.ForkInjector(groupConfig);
                var            commGroupClient = (ICommunicationGroupClientInternal)groupInjector.GetInstance <ICommunicationGroupClient>();
                _commGroups[commGroupClient.GroupName] = commGroupClient;
            }

            networkService.Register(new StringIdentifier(taskId));

            try
            {
                foreach (var group in _commGroups.Values)
                {
                    group.WaitingForRegistration();
                }
            }
            catch (SystemException e)
            {
                networkService.Unregister();
                networkService.Dispose();
                Exceptions.CaughtAndThrow(e, Level.Error, "In GroupCommClient, exception from WaitingForRegistration.", Logger);
            }
        }
Exemplo n.º 25
0
        public void TestTimerConfigurationWithClassHierarchy()
        {
            Type timerType = typeof(Timer);
            ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(FileNames.Examples);

            ITang          tang = TangFactory.GetTang();
            IConfiguration conf = tang.NewConfigurationBuilder(classHierarchyImpl)
                                  .BindNamedParameter <Timer.Seconds, int>(GenericType <Timer.Seconds> .Class, "1")
                                  .Build();

            ConfigurationFile.WriteConfigurationFile(conf, "timerConfH.txt");
            IDictionary <string, string> p = ConfigurationFile.FromFile("timerConfH.txt");

            ITang tang1 = TangFactory.GetTang();
            ICsConfigurationBuilder cb1 = tang1.NewConfigurationBuilder(new string[] { FileNames.Examples });

            ConfigurationFile.AddConfigurationFromFile(cb1, "timerConfH.txt");
            IConfiguration conf1 = cb1.Build();

            IInjector injector = tang1.NewInjector(conf1);
            var       timer    = (Timer)injector.GetInstance(timerType);

            Assert.NotNull(timer);
            timer.sleep();
        }
		public void before()
		{
			context = new Context();
			injector = context.injector;
			injector.Map<IDirectCommandMap>().ToType<DirectCommandMap>();
			subject = injector.GetInstance<IDirectCommandMap>() as DirectCommandMap;
		}
Exemplo n.º 27
0
        public void TestOptionalParameterWithDefault()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
            var       o = i.GetInstance <StringTest>();

            o.Verify(" ");
        }
        /*============================================================================*/
        /* Protected Functions                                                        */
        /*============================================================================*/

        protected object FromInjector(Type type)
        {
            if (!injector.HasDirectMapping(type))
            {
                injector.Map(type).AsSingleton();
            }
            return(injector.GetInstance(type));
        }
		/*============================================================================*/
		/* Constructor                                                                */
		/*============================================================================*/

		public MediatorFactory (IInjector injector)
		{
			_injector = injector;
			_manager = injector.HasMapping (typeof(IMediatorManager)) 
				? injector.GetInstance (typeof(IMediatorManager)) as IMediatorManager
				: new MediatorManager ();
			_manager.ViewRemoved += RemoveMediators;
		}
Exemplo n.º 30
0
        public void TestInjectInjector()
        {
            IInjector i  = TangFactory.GetTang().NewInjector();
            var       ii = (InjectInjector)i.GetInstance(typeof(InjectInjector));

            //// Assert.IsTrue(ii.i is IInjector);
            Assert.AreNotSame(i, ii.i);
        }
Exemplo n.º 31
0
        public void TestBoolParameterWithDefault()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
            var       o = i.GetInstance <BooleanTest>();

            o.Verify(false);
        }
Exemplo n.º 32
0
        public void TestWantSomeFutureHandlersAlreadyBoundVolatile()
        {
            IInjector i = TangFactory.GetTang().NewInjector();

            i.BindVolatileInstance(GenericType <IAHandler> .Class, new AHandlerImpl());
            i.BindVolatileInstance(GenericType <IBHandler> .Class, new BHandlerImpl());
            i.GetInstance <WantSomeFutureHandlers>();
        }
Exemplo n.º 33
0
 /// <summary>
 /// Create a new ContextRuntime.
 /// </summary>
 /// <param name="serviceInjector"></param>
 /// <param name="contextConfiguration">the Configuration for this context.</param>
 /// <param name="parentContext"></param>
 public ContextRuntime(
         IInjector serviceInjector,
         IConfiguration contextConfiguration,
         Optional<ContextRuntime> parentContext)
 {
     _serviceInjector = serviceInjector;
     _contextInjector = serviceInjector.ForkInjector(contextConfiguration);
     _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
     _parentContext = parentContext;
     _contextLifeCycle.Start();
 }
Exemplo n.º 34
0
 /// <summary>
 /// Create a new ContextRuntime.
 /// </summary>
 /// <param name="serviceInjector"></param>
 /// <param name="contextConfiguration">the Configuration for this context.</param>
 /// <param name="parentContext"></param>
 public ContextRuntime(
         IInjector serviceInjector,
         IConfiguration contextConfiguration,
         Optional<ContextRuntime> parentContext)
 {
     _serviceInjector = serviceInjector;
     _injectedServices = Optional<ISet<object>>.Of(serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>());
     _contextInjector = serviceInjector.ForkInjector(contextConfiguration);
     _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
     _parentContext = parentContext;
     _contextLifeCycle.Start();
 }
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		public void Process(Object view, Type type, IInjector injector)
		{
			foreach (String fieldName in _fieldTypesByName.Keys)
			{
				FieldInfo field = view.GetType().GetField(fieldName);
				if (field != null)
				{
					object valueToInject = injector.GetInstance(_fieldTypesByName[fieldName]);
					if (valueToInject != null)
					{
						field.SetValue(view, valueToInject);
					}
				}
			}
		}
Exemplo n.º 36
0
        /// <summary>
        /// Create a new ContextRuntime.
        /// </summary>
        /// <param name="serviceInjector"></param>
        /// <param name="contextConfiguration">the Configuration for this context.</param>
        /// <param name="parentContext"></param>
        public ContextRuntime(
                IInjector serviceInjector,
                IConfiguration contextConfiguration,
                Optional<ContextRuntime> parentContext)
        {
            _serviceInjector = serviceInjector;

            // Note that for Service objects and handlers, we are not merging them into a separate
            // class (e.g. ServiceContainer) due to the inability to allow service stacking if an instance 
            // of such a class were to be materialized. i.e. if a ServiceContainer object were initialized
            // and a child ServiceConfiguration is submitted, when the child service injector tries to
            // get the relevant handlers and services set, it will get the same set of handlers as
            // previously instantiated by the parent injector, and thus will not allow the stacking
            // of ServiceConfigurations.
            _injectedServices = serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>();

            _serviceContextStartHandlers = 
                serviceInjector.GetNamedInstance<ContextConfigurationOptions.StartHandlers, ISet<IObserver<IContextStart>>>();

            _serviceContextStopHandlers = 
                serviceInjector.GetNamedInstance<ContextConfigurationOptions.StopHandlers, ISet<IObserver<IContextStop>>>();

            _serviceTaskStartHandlers = 
                serviceInjector.GetNamedInstance<TaskConfigurationOptions.StartHandlers, ISet<IObserver<ITaskStart>>>();

            _serviceTaskStopHandlers = 
                serviceInjector.GetNamedInstance<TaskConfigurationOptions.StopHandlers, ISet<IObserver<ITaskStop>>>();

            _contextInjector = serviceInjector.ForkInjector(contextConfiguration);
            _contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
            _parentContext = parentContext;

            try
            {
                _contextLifeCycle.Start();
            }
            catch (Exception e)
            {
                const string message = "Encountered Exception in ContextStartHandler.";
                if (ParentContext.IsPresent())
                {
                    throw new ContextStartHandlerException(
                        Id, Optional<string>.Of(ParentContext.Value.Id), message, e);
                }
                
                throw new ContextStartHandlerException(Id, Optional<string>.Empty(), message, e);
            }
        }