public void Created(ISynchChannel channel)
 {
     if (_when(channel.Type1, channel.Type2))
     {
         channel.AddChannelObserver(Create());
     }
 }
Esempio n. 2
0
 private void DoSynchronized(IExecutive exec, ISynchChannel isc)
 {
     Debug.WriteLine("Pausing synchronized event at time " + exec.Now + ", and priority level " + exec.CurrentPriorityLevel + " on thread " + System.Threading.Thread.CurrentThread.GetHashCode());
     isc.Synchronize();
     if (_synchtime == new DateTime())
     {
         _synchtime = exec.Now;
     }
     else
     {
         Assert.IsTrue(_synchtime.Equals(exec.Now), "Synchronized event did not fire at the synchronization time");
     }
     _synchronized--;
     _submitted--;
     Debug.WriteLine("Running synchronized event at time " + exec.Now + ", sequence number " + isc.Sequencer + " and priority level " + exec.CurrentPriorityLevel + " on thread " + System.Threading.Thread.CurrentThread.GetHashCode());
 }
Esempio n. 3
0
        public void SetUpTest()
        {
            var type1Config = new TypeConfiguration <LocalTestResource, int>(ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1);

            _localEndpoint = new InMemoryCrudDataEndpoint <LocalTestResource, int>(type1Config, TestData.LocalResults);
            var endpoint1Config = new EndpointConfiguration <LocalTestResource, int>(
                type1Config,
                _localEndpoint);

            var type2Config = new TypeConfiguration <RemoteTestResource, int>(rtr => rtr.Id);

            _remoteEndpoint = new InMemoryCrudDataEndpoint <RemoteTestResource, int>(type2Config, TestData.RemoteResults);
            var endpoint2Config = new EndpointConfiguration <RemoteTestResource, int>(
                type2Config,
                _remoteEndpoint);

            // This clearly requires a configuration API.
            var channelConfig     = new ChannelConfiguration <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >(endpoint1Config, endpoint2Config, new TestResourceTranslator());
            var itemsPreprocessor = new ItemMatcher <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >(channelConfig);

            channelConfig.ItemsPreprocessor = itemsPreprocessor.Match;
            channelConfig.AddSynchAction(new SynchronizationResolver <ItemMatch <LocalTestResource, RemoteTestResource>, ChannelConfiguration <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> > >(
                                             channelConfig,
                                             (item, cfg) =>
            {
                return(item.Result1 == null);
            },
                                             (item, cfg) =>
            {
                var synchItem = item.Result1;
                cfg.TypeTranslator.TranslateBackward(item.Result2, ref synchItem);
                // Now the translate decides wether a new item has to be created, but the decision is there anyway because of the Create.
                cfg.Type1EndpointConfiguration.Endpoint.Create(synchItem);
                return(new SynchronizationResult(true));
            }
                                             ));

            //var t2epConfig = new EndpointConfiguration()
            _channelUnderTest = new OneWayPullChannel <LocalTestResource, RemoteTestResource, int, ItemMatch <LocalTestResource, RemoteTestResource> >(
                channelConfig,
                () => Task.FromResult(_localEndpoint.ReadAll().AsEnumerable()),
                () => Task.FromResult(_remoteEndpoint.ReadAll().AsEnumerable()));
        }
        public void SetUpTest()
        {
            var type1Config = new TypeConfiguration<LocalTestResource, int>(ltr => ltr.CorrelationId.HasValue ? ltr.CorrelationId.Value : -1);
            _localEndpoint = new InMemoryCrudDataEndpoint<LocalTestResource, int>(type1Config, TestData.LocalResults);
            var endpoint1Config = new EndpointConfiguration<LocalTestResource, int>(
                type1Config,
                _localEndpoint);

            var type2Config = new TypeConfiguration<RemoteTestResource, int>(rtr => rtr.Id);
            _remoteEndpoint = new InMemoryCrudDataEndpoint<RemoteTestResource, int>(type2Config, TestData.RemoteResults);
            var endpoint2Config = new EndpointConfiguration<RemoteTestResource, int>(
                type2Config,
                _remoteEndpoint);

            // This clearly requires a configuration API.
            var channelConfig = new ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(endpoint1Config, endpoint2Config, new TestResourceTranslator());
            var itemsPreprocessor = new ItemMatcher<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(channelConfig);
            channelConfig.ItemsPreprocessor = itemsPreprocessor.Match;
            channelConfig.AddSynchAction(new SynchronizationResolver<ItemMatch<LocalTestResource,RemoteTestResource>, ChannelConfiguration<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>>(
                channelConfig,
                (item, cfg) =>
                {
                    return item.Result1 == null;
                },
                (item, cfg) =>
                {
                    var synchItem = item.Result1;
                    cfg.TypeTranslator.TranslateBackward(item.Result2, ref synchItem);
                    // Now the translate decides wether a new item has to be created, but the decision is there anyway because of the Create.
                    cfg.Type1EndpointConfiguration.Endpoint.Create(synchItem);
                    return new SynchronizationResult(true);
                }
            ));

            //var t2epConfig = new EndpointConfiguration()
            _channelUnderTest = new OneWayPullChannel<LocalTestResource, RemoteTestResource, int, ItemMatch<LocalTestResource, RemoteTestResource>>(
                channelConfig,
                () => Task.FromResult(_localEndpoint.ReadAll().AsEnumerable()),
                () => Task.FromResult(_remoteEndpoint.ReadAll().AsEnumerable()));
        }
Esempio n. 5
0
        public void TestBaseFunctionality()
        {
            Model model = new Model();

            IExecutive exec = model.Executive;
            DateTime   now  = DateTime.Now;
            DateTime   when;
            double     priority;

            m_des = new DetachableEventSynchronizer(model);

            for (int i = 0; i < NUM_EVENTS; i++)
            {
                when     = new DateTime(now.Ticks + m_random.Next());
                priority = m_random.NextDouble();
                Debug.WriteLine("Primary requesting event service for " + when + ", at priority " + priority);
                object userData = null;
                if (m_random.Next(5) < 2)
                {
                    ISynchChannel isc = m_des.GetSynchChannel(priority);
                    userData = isc;
                    Debug.WriteLine("Creating synchronized event for time " + when);
                    _synchronized++;
                }
                exec.RequestEvent(new ExecEventReceiver(MyExecEventReceiver), when, priority, userData, ExecEventType.Detachable);
                _submitted++;
            }

            Assert.IsTrue(_submitted > 0, "There are no events submitted");
            Assert.IsTrue(_synchronized > 0, "There are no events synchronized");
            Assert.IsTrue(_secondary == 0, "There cannot be secondary events submitted yet");

            exec.Start();

            Assert.IsTrue(_submitted == 0, "Not all submitted events had been fired");
            Assert.IsTrue(_synchronized == 0, "Not all synchronized events had been fired");
            Assert.IsTrue(_secondary > 0, "There has not been a secondary events submitted");
        }