public void local_module_published_once_one_module_revieved()
        {
            PrepareSharedLibrary();

            string publishingModuleSrc = GetSourceCodePath(typeof (SDPublishingModule));
            string listeningModuleSrc = GetSourceCodePath(typeof (SDListeningModule));

            string listener1 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 1);
            string listener2 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 2);

            string publisherDll = Compiler.GenerateModuleFromCode(publishingModuleSrc, _sharedDll);
            ManifestBuilderConfiguration manifestConfiguration = ManifestBuilderConfiguration.Default;
            manifestConfiguration.ModulesDependenciesProvider = new SingleModulesDependencyProvider();
            Compiler.GenerateManifestForModule(publisherDll, KeyFile, manifestConfiguration);

            // use the default Nomad Configuration
            ListenerKernel = new NomadKernel();
            IModuleDiscovery listnerDiscovery =
                new CompositeModuleDiscovery(new SingleModuleDiscovery(listener1),
                                             new SingleModuleDiscovery(listener2)
                                             );

            ListenerKernel.LoadModules(listnerDiscovery);
            DistributedMessageCarrier firstCarrier = CreateCarrier(ListenerKernel);

            IModuleDiscovery publisherDiscovery = new SingleModuleDiscovery(publisherDll);
            ListenerKernel.LoadModules(publisherDiscovery);

            Thread.Sleep(PUBLISH_TIMEOUT);
            int firstMsg = firstCarrier.GetStatus.Count;

            Assert.AreEqual(5, firstMsg, "The number of delivered messages is not exactly 5");
        }
Esempio n. 2
0
        public void module_publishes_module_listens()
        {
            // path for this test (using the test method name) use in each code
            PrepareSharedLibrary();

            string publishingModuleSrc = GetSourceCodePath(typeof (SimplePublishingModule));
            string listeningModuleSrc = GetSourceCodePath(typeof (SimpleListeningModule));

            string listener1 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 1);

            string publisherDll = Compiler.GenerateModuleFromCode(publishingModuleSrc, _sharedDll);
            ManifestBuilderConfiguration manifestConfiguration = ManifestBuilderConfiguration.Default;
            manifestConfiguration.ModulesDependenciesProvider = new SingleModulesDependencyProvider();
            Compiler.GenerateManifestForModule(publisherDll, KeyFile, manifestConfiguration);

            // create listener site
            string listenerSite = "net.tcp://127.0.0.1:5555/IDEA";

            // create published sites
            string publisherSite = "net.tcp://127.0.0.1:7777/IDEA";

            // create kernels with configuration
            NomadConfiguration config1 = NomadConfiguration.Default;
            config1.DistributedConfiguration = DistributedConfiguration.Default;
            config1.DistributedConfiguration.LocalURI = new Uri(listenerSite);
            ListenerKernel = new NomadKernel(config1);
            IModuleDiscovery listenerDiscovery = new SingleModuleDiscovery(listener1);
            ListenerKernel.LoadModules(listenerDiscovery);

            // create publishing kernel
            NomadConfiguration publisherConfig = NomadConfiguration.Default;
            publisherConfig.DistributedConfiguration = DistributedConfiguration.Default;
            publisherConfig.DistributedConfiguration.LocalURI = new Uri(publisherSite);
            publisherConfig.DistributedConfiguration.URLs.Add(listenerSite);
            PublisherKernel = new NomadKernel(publisherConfig);
            IModuleDiscovery publisherDiscovery = new SingleModuleDiscovery(publisherDll);
            PublisherKernel.LoadModules(publisherDiscovery);

            // assert the events being published
            AssertEventPublished(listener1, 5);
        }
        public void module_published_once_only_one_module_recieved()
        {
            // path for this test (using the test method name) use in each code
            PrepareSharedLibrary();

            string publishingModuleSrc = GetSourceCodePath(typeof (SDPublishingModule));
            string listeningModuleSrc = GetSourceCodePath(typeof (SDListeningModule));

            string listener1 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 1);
            string listener2 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 2);

            string publisherDll = Compiler.GenerateModuleFromCode(publishingModuleSrc, _sharedDll);
            ManifestBuilderConfiguration manifestConfiguration = ManifestBuilderConfiguration.Default;
            manifestConfiguration.ModulesDependenciesProvider = new SingleModulesDependencyProvider();
            Compiler.GenerateManifestForModule(publisherDll, KeyFile, manifestConfiguration);

            // create listeners sites
            string site1 = "net.tcp://127.0.0.1:5555/IDEA";
            string site2 = "net.tcp://127.0.0.1:6666/IDEA";

            // create published sites
            string publisherSite = "net.tcp://127.0.0.1:7777/IDEA";

            // create kernels with configuration
            NomadConfiguration config1 = NomadConfiguration.Default;
            config1.DistributedConfiguration = DistributedConfiguration.Default;
            config1.DistributedConfiguration.LocalURI = new Uri(site1);
            config1.DistributedConfiguration.URLs.Add(site2);
            config1.DistributedConfiguration.URLs.Add(publisherSite);
            ListenerKernel = new NomadKernel(config1);
            IModuleDiscovery listnerDiscovery = new SingleModuleDiscovery(listener1);
            ListenerKernel.LoadModules(listnerDiscovery);
            DistributedMessageCarrier firstCarrier = CreateCarrier(ListenerKernel);

            NomadConfiguration config2 = NomadConfiguration.Default;
            config2.DistributedConfiguration = DistributedConfiguration.Default;
            config2.DistributedConfiguration.LocalURI = new Uri(site2);
            config2.DistributedConfiguration.URLs.Add(site1);
            config2.DistributedConfiguration.URLs.Add(publisherSite);
            ListenerKernelSecond = new NomadKernel(config2);
            IModuleDiscovery listenerDiscovery2 = new SingleModuleDiscovery(listener2);
            ListenerKernelSecond.LoadModules(listenerDiscovery2);
            DistributedMessageCarrier secondCarrier = CreateCarrier(ListenerKernelSecond);

            // create publishing kernel
            NomadConfiguration publisherConfig = NomadConfiguration.Default;
            publisherConfig.DistributedConfiguration = DistributedConfiguration.Default;
            publisherConfig.DistributedConfiguration.LocalURI = new Uri(publisherSite);
            publisherConfig.DistributedConfiguration.URLs.Add(site1);
            publisherConfig.DistributedConfiguration.URLs.Add(site2);
            PublisherKernel = new NomadKernel(publisherConfig);
            IModuleDiscovery publisherDiscovery = new SingleModuleDiscovery(publisherDll);
            PublisherKernel.LoadModules(publisherDiscovery);

            // assert the events being published
            // wait for publishing messages etc
            Thread.Sleep(PUBLISH_TIMEOUT);
            int firstMsg = firstCarrier.GetStatus.Count;
            int secondMsg = secondCarrier.GetStatus.Count;

            Assert.AreEqual(5, firstMsg + secondMsg, "The number of delivered messages is not exactly 5");
        }
Esempio n. 4
0
        public void local_module_publishes_and_later_loaded_listener_module_receives_those_messages()
        {
            // path for this test (using the test method name) use in each code
            PrepareSharedLibrary();

            string publishingModuleSrc = GetSourceCodePath(typeof (BufferedPublishingModule));
            string listeningModuleSrc = GetSourceCodePath(typeof (SimpleListeningModule));

            string listener1 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 1);

            string publisherDll = Compiler.GenerateModuleFromCode(publishingModuleSrc, _sharedDll);
            ManifestBuilderConfiguration manifestConfiguration = ManifestBuilderConfiguration.Default;
            manifestConfiguration.ModulesDependenciesProvider = new SingleModulesDependencyProvider();
            Compiler.GenerateManifestForModule(publisherDll, KeyFile, manifestConfiguration);

            // preaparing modules discoveries.
            IModuleDiscovery listenerDiscovery = new SingleModuleDiscovery(listener1);
            IModuleDiscovery publisherDiscovery = new SingleModuleDiscovery(publisherDll);

            // create non-distributed kernel
            PublisherKernel = new NomadKernel();

            // publisher module load
            PublisherKernel.LoadModules(publisherDiscovery);

            // postponed listener module load
            PublisherKernel.LoadModules(listenerDiscovery);

            // assert the events being published
            var fi = new FileInfo(listener1 + "_CounterFile");
            if (fi.Exists)
            {
                using (StreamReader counterReader = fi.OpenText())
                {
                    int value = Convert.ToInt32(counterReader.ReadLine());
                    // Verifying that locally the event aggregator works properly
                    Assert.AreEqual(5, value);
                    counterReader.Close();
                }
            }
            else
            {
                Assert.Fail("No counter file from listener module in local postponed configuration");
            }
        }
Esempio n. 5
0
        public void local_module_publishes_and_later_loaded_listener_module_does_not_receive_outdated_messages()
        {
            // path for this test (using the test method name) use in each code
            PrepareSharedLibrary();

            string publishingModuleSrc = GetSourceCodePath(typeof (InThePastPublishingModule));
            string listeningModuleSrc = GetSourceCodePath(typeof (SimpleListeningModule));

            string listener1 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 1);

            string publisherDll = Compiler.GenerateModuleFromCode(publishingModuleSrc, _sharedDll);
            ManifestBuilderConfiguration manifestConfiguration = ManifestBuilderConfiguration.Default;
            manifestConfiguration.ModulesDependenciesProvider = new SingleModulesDependencyProvider();
            Compiler.GenerateManifestForModule(publisherDll, KeyFile, manifestConfiguration);

            // preaparing modules discoveries.
            IModuleDiscovery listenerDiscovery = new SingleModuleDiscovery(listener1);
            IModuleDiscovery publisherDiscovery = new SingleModuleDiscovery(publisherDll);

            // create non-distributed kernel
            PublisherKernel = new NomadKernel();

            // publisher module load
            PublisherKernel.LoadModules(publisherDiscovery);

            // postponed listener module load
            PublisherKernel.LoadModules(listenerDiscovery);

            // assert the events being published
            var fi = new FileInfo(listener1 + "_CounterFile");
            Assert.False(fi.Exists);
        }
Esempio n. 6
0
        public void distributed_module_publishes_and_two_later_loaded_listener_modules_receive_those_messages()
        {
            // path for this test (using the test method name) use in each code
            PrepareSharedLibrary();

            string publishingModuleSrc = GetSourceCodePath(typeof (MixedBufferedPublishingModule));
            string listeningModuleSrc = GetSourceCodePath(typeof (SimpleListeningModule));

            string listener1 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 1);
            string listener2 = GenerateListener(RuntimePath, _sharedDll, listeningModuleSrc, 1);

            string publisherDll = Compiler.GenerateModuleFromCode(publishingModuleSrc, _sharedDll);
            ManifestBuilderConfiguration manifestConfiguration = ManifestBuilderConfiguration.Default;
            manifestConfiguration.ModulesDependenciesProvider = new SingleModulesDependencyProvider();
            Compiler.GenerateManifestForModule(publisherDll, KeyFile, manifestConfiguration);

            // create listener site
            string listenerSite = "net.tcp://127.0.0.1:5555/IDEA";

            // create published sites
            string publisherSite = "net.tcp://127.0.0.1:7777/IDEA";

            // create listener1 kernel
            NomadConfiguration config1 = NomadConfiguration.Default;
            config1.DistributedConfiguration = DistributedConfiguration.Default;
            config1.DistributedConfiguration.LocalURI = new Uri(listenerSite);
            ListenerKernel = new NomadKernel(config1);
            IModuleDiscovery listenerDiscovery = new SingleModuleDiscovery(listener1);
            ListenerKernel.LoadModules(listenerDiscovery);

            // create publishing kernel
            NomadConfiguration publisherConfig = NomadConfiguration.Default;
            publisherConfig.DistributedConfiguration = DistributedConfiguration.Default;
            publisherConfig.DistributedConfiguration.LocalURI = new Uri(publisherSite);
            publisherConfig.DistributedConfiguration.URLs.Add(listenerSite);
            PublisherKernel = new NomadKernel(publisherConfig);
            IModuleDiscovery publisherDiscovery = new SingleModuleDiscovery(publisherDll);
            PublisherKernel.LoadModules(publisherDiscovery);

            // postponed load of a second listener module
            IModuleDiscovery listenerDiscovery2 = new SingleModuleDiscovery(listener2);
            ListenerKernel.LoadModules(listenerDiscovery2);

            // assert the events being published
            AssertEventPublished(listener1);

            // assert that last loaded listener2 received valid events
            AssertEventPublished(listener2);
        }