Esempio n. 1
0
        public void TestSetOfTimeshiftMultipleInstances()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            // when adding another Timeshift into the set for named parameter SetOfTimeshifts, it ends up the same entry.
            cb.BindSetEntry <SetOfTimeshifts, Timeshift, ITimeshift>(GenericType <SetOfTimeshifts> .Class, GenericType <Timeshift> .Class);
            cb.BindSetEntry <SetOfTimeshifts, Timeshift, ITimeshift>(GenericType <SetOfTimeshifts> .Class, GenericType <Timeshift> .Class);
            cb.BindNamedParameter <Timeshift.TimeshiftLinkId, string>(GenericType <Timeshift.TimeshiftLinkId> .Class, "123")
            .BindNamedParameter <Timeshift.TimeshiftInTicks, long>(GenericType <Timeshift.TimeshiftInTicks> .Class, "10");

            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());

            ISet <ITimeshift> actual = i.GetInstance <SetofTimeShiftClass>().Timeshifts;

            Assert.True(actual.Count == 1);
        }
Esempio n. 2
0
        public void TestObjectInjectBound()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.BindSetEntry <SetOfClasses, Integer, INumber>(GenericType <SetOfClasses> .Class, GenericType <Integer> .Class);
            cb.BindSetEntry <SetOfClasses, Float, INumber>(GenericType <SetOfClasses> .Class, GenericType <Float> .Class);

            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());

            i.BindVolatileInstance(GenericType <Integer> .Class, new Integer(4));
            i.BindVolatileInstance(GenericType <Float> .Class, new Float(42.0001f));

            ISet <INumber> actual   = i.GetInstance <Pool>().Numbers;
            ISet <INumber> expected = new HashSet <INumber>();

            expected.Add(new Integer(4));
            expected.Add(new Float(42.0001f));
            Assert.True(Utilities.Utilities.Equals <INumber>(actual, expected));
        }
Esempio n. 3
0
        public void TestStringInjectRoundTrip()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.BindSetEntry <SetOfNumbers, string>(GenericType <SetOfNumbers> .Class, "four");
            cb.BindSetEntry <SetOfNumbers, string>(GenericType <SetOfNumbers> .Class, "five");
            cb.BindSetEntry <SetOfNumbers, string>(GenericType <SetOfNumbers> .Class, "six");

            string s = ConfigurationFile.ToConfigurationString(cb.Build());
            ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder();

            ConfigurationFile.AddConfigurationFromString(cb2, s);

            ISet <string> actual =
                ((Box)TangFactory.GetTang().NewInjector(cb2.Build()).GetInstance(typeof(Box))).Numbers;

            Assert.True(actual.Contains("four"));
            Assert.True(actual.Contains("five"));
            Assert.True(actual.Contains("six"));
        }
Esempio n. 4
0
        public void TestSetOfTimeshiftMultipleSubClasses()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            // Adding implementations from different subclasses
            cb.BindSetEntry <SetOfTimeshifts, Timeshift, ITimeshift>(GenericType <SetOfTimeshifts> .Class, GenericType <Timeshift> .Class);
            cb.BindSetEntry <SetOfTimeshifts, Timeshift1, ITimeshift>(GenericType <SetOfTimeshifts> .Class, GenericType <Timeshift1> .Class);

            cb.BindNamedParameter <Timeshift.TimeshiftLinkId, string>(GenericType <Timeshift.TimeshiftLinkId> .Class, "123")
            .BindNamedParameter <Timeshift.TimeshiftInTicks, long>(GenericType <Timeshift.TimeshiftInTicks> .Class, "10");

            cb.BindNamedParameter <Timeshift1.TimeshiftLinkId, string>(GenericType <Timeshift1.TimeshiftLinkId> .Class, "456")
            .BindNamedParameter <Timeshift1.TimeshiftInTicks, long>(GenericType <Timeshift1.TimeshiftInTicks> .Class, "20");

            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());

            ISet <ITimeshift> actual = i.GetInstance <SetofTimeShiftClass>().Timeshifts;

            Assert.True(actual.Count == 2);
        }
Esempio n. 5
0
        public void testStringInjectBound()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.BindSetEntry <SetOfNumbers, string>(GenericType <SetOfNumbers> .Class, "four");
            cb.BindSetEntry <SetOfNumbers, string>(GenericType <SetOfNumbers> .Class, "five");
            cb.BindSetEntry <SetOfNumbers, string>(GenericType <SetOfNumbers> .Class, "six");

            Box           b        = (Box)TangFactory.GetTang().NewInjector(cb.Build()).GetInstance(typeof(Box));
            ISet <string> actual   = b.Numbers;
            ISet <string> expected = new HashSet <string>();

            expected.Add("four");
            expected.Add("five");
            expected.Add("six");

            Assert.IsTrue(actual.Contains("four"));
            Assert.IsTrue(actual.Contains("five"));
            Assert.IsTrue(actual.Contains("six"));
        }
Esempio n. 6
0
        public void TestSetOfTimeshift()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.BindSetEntry <SetOfTimeshifts, Timeshift, ITimeshift>(GenericType <SetOfTimeshifts> .Class, GenericType <Timeshift> .Class)
            .BindNamedParameter <Timeshift.TimeshiftLinkId, string>(GenericType <Timeshift.TimeshiftLinkId> .Class, "123")
            .BindNamedParameter <Timeshift.TimeshiftInTicks, long>(GenericType <Timeshift.TimeshiftInTicks> .Class, "10");

            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());

            ISet <ITimeshift> actual = i.GetInstance <SetofTimeShiftClass>().Timeshifts;

            Assert.True(actual.Count == 1);
        }
Esempio n. 7
0
        public void TestSetOfClassBound()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.BindSetEntry <SetOfClasses, Integer1, INumber>(GenericType <SetOfClasses> .Class, GenericType <Integer1> .Class) // bind an impl to the interface of the set
            .BindNamedParameter <Integer1.NamedInt, int>(GenericType <Integer1.NamedInt> .Class, "4");                          // bind parameter for the impl

            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());

            ISet <INumber> actual   = i.GetInstance <Pool>().Numbers;
            ISet <INumber> expected = new HashSet <INumber>();

            expected.Add(new Integer1(4));

            Assert.True(Utilities.Utilities.Equals <INumber>(actual, expected));
        }
Esempio n. 8
0
        public void TestBindSetEntryImplValue()
        {
            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();

            cb.BindSetEntry <TestSetInjection.SetOfClasses, TestSetInjection.Integer1, INumber>() // bind an impl to the interface of the set
            .BindIntNamedParam <TestSetInjection.Integer1.NamedInt>("4");                         // bind parameter for the impl

            IInjector i = TangFactory.GetTang().NewInjector(cb.Build());

            ISet <INumber> actual   = i.GetInstance <TestSetInjection.Pool>().Numbers;
            ISet <INumber> expected = new HashSet <INumber>();

            expected.Add(new TestSetInjection.Integer1(4));

            Assert.True(Utilities.Utilities.Equals <INumber>(actual, expected));
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the task configuration for the operator topology.
        /// </summary>
        /// <param name="taskId">The task identifier</param>
        /// <returns>The task configuration</returns>
        public IConfiguration GetTaskConfiguration(string taskId)
        {
            if (taskId == null)
            {
                throw new ArgumentException("TaskId is null when GetTaskConfiguration");
            }

            TaskNode selfTaskNode = GetTaskNode(taskId);

            if (selfTaskNode == null)
            {
                throw new ArgumentException("Task has not been added to the topology");
            }

            string   parentId;
            TaskNode parent = selfTaskNode.Parent;

            if (parent == null)
            {
                parentId = selfTaskNode.TaskId;
            }
            else
            {
                parentId = parent.TaskId;
            }

            //add parentid, if no parent, add itself
            ICsConfigurationBuilder confBuilder = TangFactory.GetTang().NewConfigurationBuilder()
                                                  .BindNamedParameter <GroupCommConfigurationOptions.TopologyRootTaskId, string>(
                GenericType <GroupCommConfigurationOptions.TopologyRootTaskId> .Class,
                parentId);

            //add all its children
            foreach (TaskNode childNode in selfTaskNode.GetChildren())
            {
                confBuilder.BindSetEntry <GroupCommConfigurationOptions.TopologyChildTaskIds, string>(
                    GenericType <GroupCommConfigurationOptions.TopologyChildTaskIds> .Class,
                    childNode.TaskId);
            }

            if (OperatorSpec is BroadcastOperatorSpec)
            {
                var broadcastSpec = OperatorSpec as BroadcastOperatorSpec;
                if (taskId.Equals(broadcastSpec.SenderId))
                {
                    confBuilder.BindImplementation(GenericType <IGroupCommOperator <T> > .Class, GenericType <BroadcastSender <T> > .Class);
                    SetMessageType(typeof(BroadcastSender <T>), confBuilder);
                }
                else
                {
                    confBuilder.BindImplementation(GenericType <IGroupCommOperator <T> > .Class, GenericType <BroadcastReceiver <T> > .Class);
                    SetMessageType(typeof(BroadcastReceiver <T>), confBuilder);
                }
            }
            else if (OperatorSpec is ReduceOperatorSpec)
            {
                var reduceSpec = OperatorSpec as ReduceOperatorSpec;
                if (taskId.Equals(reduceSpec.ReceiverId))
                {
                    confBuilder.BindImplementation(GenericType <IGroupCommOperator <T> > .Class, GenericType <ReduceReceiver <T> > .Class);
                    SetMessageType(typeof(ReduceReceiver <T>), confBuilder);
                }
                else
                {
                    confBuilder.BindImplementation(GenericType <IGroupCommOperator <T> > .Class, GenericType <ReduceSender <T> > .Class);
                    SetMessageType(typeof(ReduceSender <T>), confBuilder);
                }
            }
            else if (OperatorSpec is ScatterOperatorSpec)
            {
                ScatterOperatorSpec scatterSpec = OperatorSpec as ScatterOperatorSpec;
                if (taskId.Equals(scatterSpec.SenderId))
                {
                    confBuilder.BindImplementation(GenericType <IGroupCommOperator <T> > .Class, GenericType <ScatterSender <T> > .Class);
                    SetMessageType(typeof(ScatterSender <T>), confBuilder);
                }
                else
                {
                    confBuilder.BindImplementation(GenericType <IGroupCommOperator <T> > .Class, GenericType <ScatterReceiver <T> > .Class);
                    SetMessageType(typeof(ScatterReceiver <T>), confBuilder);
                }
            }
            else
            {
                throw new NotSupportedException("Spec type not supported");
            }

            return(Configurations.Merge(confBuilder.Build(), OperatorSpec.Configiration));
        }