Ejemplo n.º 1
0
        private static void Main()
        {
            // signing the assemblies and creating the manifest using manifestBuilder api
            GenerateManifestUsingApi("DistributablePublisherModule.dll", @"..\Modules\Publisher");

            // using default configuration
            string publisherSite = "net.tcp://127.0.0.1:6666/IDEA";
            NomadConfiguration config2 = NomadConfiguration.Default;
            config2.DistributedConfiguration = DistributedConfiguration.Default;
            config2.DistributedConfiguration.LocalURI = new Uri(publisherSite);

            // adding listener address to known sites.
            const string listenerSite = "net.tcp://127.0.0.1:5555/IDEA";
            config2.DistributedConfiguration.URLs.Add(listenerSite);
            var kernel = new NomadKernel(config2);

            // loading modules using single module discovery pattern
            var discovery =
                new DirectoryModuleDiscovery(@"..\Modules\Publisher", SearchOption.TopDirectoryOnly);
            kernel.LoadModules(discovery);

            Console.WriteLine("Publisher kernel ready");
            //wait for input
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        private static void Main()
        {
            // signing the assemblies and creating the manifest using manifestBuilder api
            GenerateManifestUsingApi("WpfApplicationModule.exe", @".\Modules\WpfApplication");
            GenerateManifestUsingApi("WpfButtonModule.dll", @".\Modules\WpfButton");
            GenerateManifestUsingApi("WpfUpdaterModule.dll", @".\Modules\WpfUpdater");

            // setting up configuration for repository
            NomadConfiguration configuration = NomadConfiguration.Default;
            configuration.ModuleRepository = new WebModulesRepository("http://*****:*****@".\Modules\WpfApplication\WpfApplicationModule.exe"),
                new SingleModuleDiscovery(@".\Modules\WpfButton\WpfButtonModule.dll"),
                new SingleModuleDiscovery(@".\Modules\WpfUpdater\WpfUpdaterModule.dll")
                );

            kernel.LoadModules(discovery);

            // FIXME: what about ending the thread here ?
        }
        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");
        }
Ejemplo n.º 4
0
        public void injecting_nomad_configuration_freezes_the_configuration()
        {
            //Use default configuration
            NomadConfiguration configuration = NomadConfiguration.Default;

            Assert.IsFalse(configuration.IsFrozen);
            _nomadKernel = new NomadKernel(configuration);
            Assert.IsTrue(configuration.IsFrozen);
        }
        public virtual void SetUp()
        {
            // prepare configuration
            NomadConfiguration configuration = NomadConfiguration.Default;
            configuration.ModuleFilter = new CompositeModuleFilter();
            configuration.DependencyChecker = new DependencyChecker();

            // initialize kernel
            Kernel = new NomadKernel(configuration);

            // domain
            Domain = Kernel.ModuleAppDomain;
        }
Ejemplo n.º 6
0
        private static void Main()
        {
            // use default configuration for kernel
            var kernel = new NomadKernel();

            // load the Application_WPF_Shell
            kernel.LoadModules(new SingleModuleDiscovery(@".\Application_WPF_Shell\Application_WPF_Shell.exe"));

            kernel.LoadModules(new CompositeModuleDiscovery(
                new SingleModuleDiscovery(@".\FileLoaderModule\FileLoaderModule.dll"),
                new SingleModuleDiscovery(@".\GraphicFilesHandlerModule\GraphicFilesHandlerModule.dll"),
                new SingleModuleDiscovery(@".\TextFileHandlerModule\TextFileHandlerModule.dll"),
                new SingleModuleDiscovery(@".\ListingAllLoadedModule\ListingAllLoadedModule.dll"),
                new SingleModuleDiscovery(@".\ThreadedToolbarControlledModule\ThreadedToolbarControlledModule.dll")
                ));
        }
Ejemplo n.º 7
0
        public void two_service_hosts_work_simultanously_on_different_ports()
        {
            string site1 = "net.tcp://127.0.0.1:5555/IDEA";
            string site2 = "net.tcp://127.0.0.1:6666/IDEA";
            NomadConfiguration config = NomadConfiguration.Default;
            config.DistributedConfiguration = DistributedConfiguration.Default;
            config.DistributedConfiguration.LocalURI = new Uri(site1);
            Assert.DoesNotThrow(() => ListenerKernel = new NomadKernel(config));

            NomadConfiguration config2 = NomadConfiguration.Default;
            config2.DistributedConfiguration = DistributedConfiguration.Default;
            config2.DistributedConfiguration.LocalURI = new Uri(site2);
            config2.DistributedConfiguration.URLs.Add(site1);
            Assert.DoesNotThrow(() => PublisherKernel = new NomadKernel(config2));

            PublisherKernel.EventAggregator.Publish(new NomadSimpleMessage("Hello from kernel2"));
        }
Ejemplo n.º 8
0
        private static void Main()
        {
            // signing the assemblies and creating the manifest using manifestBuilder api
            GenerateManifestUsingApi("Controlling_Publisher_Module.dll", @".\Modules\ControllingPublisher");
            GenerateManifestUsingApi("Simple_Publisher_Module.dll", @".\Modules\SimplePublisher");

            // using default configuration
            var kernel = new NomadKernel();

            // loading modules using single module discovery pattern
            var discovery = new CompositeModuleDiscovery(
                new DirectoryModuleDiscovery(@".\Modules\ControllingPublisher", SearchOption.TopDirectoryOnly),
                new DirectoryModuleDiscovery(@".\Modules\SimplePublisher", SearchOption.TopDirectoryOnly));
            kernel.LoadModules(discovery);

            //wait for input
            Console.ReadLine();
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        private static void Main()
        {
            // signing the assemblies and creating the manifest using manifestBuilder api
            GenerateManifestUsingApi("DistributableListenerModule.dll", @"..\Modules\Listener");

            // using default distributed configuration
            string site1 = "net.tcp://127.0.0.1:5555/IDEA";
            NomadConfiguration config = NomadConfiguration.Default;
            config.DistributedConfiguration = DistributedConfiguration.Default;
            config.DistributedConfiguration.LocalURI = new Uri(site1);
            var kernel = new NomadKernel(config);

            // loading modules using single module discovery pattern
            var discovery =
                new DirectoryModuleDiscovery(@"..\Modules\Listener", SearchOption.TopDirectoryOnly);
            kernel.LoadModules(discovery);

            Console.WriteLine("Listener kernel ready");
            //wait for input
            Console.ReadLine();
        }
Ejemplo n.º 11
0
        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");
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 public void default_distributed_configuration_passes()
 {
     NomadConfiguration config = NomadConfiguration.Default;
     config.DistributedConfiguration = DistributedConfiguration.Default;
     Assert.DoesNotThrow(() => ListenerKernel = new NomadKernel(config));
 }
        private static void verifing_starting_appdomain_to_have_not_module_loading_implementation_loaded_callback()
        {
            SetUpInDomain();
            _nomadKernel = new NomadKernel(_configuration);

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                Assert.AreNotEqual(AssemblyFullName, asm.FullName);
            }
        }
        private static void unloading_modules_upon_request_callback()
        {
            SetUpInDomain();
            _nomadKernel = new NomadKernel(_configuration);

            var expectedModuleInfos = new[]
                                          {
                                              //Set Up modules to be loaded.
                                              new ModuleInfo(_assemblyFullPath),
                                              new ModuleInfo(_assemblyFullPath2),
                                          };

            SetUpModuleDiscovery(expectedModuleInfos);

            _nomadKernel.LoadModules(_moduleDiscoveryMock.Object);

            AppDomain moduleAppDomain = _nomadKernel.ModuleAppDomain;

            _nomadKernel.UnloadModules();

            Assert.AreNotSame(moduleAppDomain, _nomadKernel.ModuleAppDomain);
        }
        private static void loading_more_than_one_module_into_module_appdomain_callback()
        {
            SetUpInDomain();
            _nomadKernel = new NomadKernel(_configuration);

            var expectedModuleInfos = new[]
                                          {
                                              //Set Up modules to be loaded.
                                              new ModuleInfo(_assemblyFullPath),
                                              new ModuleInfo(_assemblyFullPath2),
                                          };

            SetUpModuleDiscovery(expectedModuleInfos);

            _nomadKernel.ModuleAppDomain.AssemblyLoad += (sender, args) => Assert.That(
                args.LoadedAssembly.FullName.
                    Equals(AssemblyFullName)
                ||
                args.LoadedAssembly.FullName.
                    Equals(AssemblyFullName2)
                                                                               );

            _nomadKernel.LoadModules(_moduleDiscoveryMock.Object);

            //Check for not loading assembly into kernel appDomain);););
            foreach (
                Assembly kernelAsm in _nomadKernel.KernelAppDomain.ReflectionOnlyGetAssemblies())
            {
                Assert.AreNotEqual(AssemblyFullName, kernelAsm.FullName,
                                   "The module assembly 1 has been loaded into KernelAppDomain.");
                Assert.AreNotEqual(AssemblyFullName2, kernelAsm.FullName,
                                   "The module assembly 2 has been loaded into KernelAppDomain.");
            }
        }
Ejemplo n.º 18
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");
            }
        }
Ejemplo n.º 19
0
 public void injecting_default_nomad_configuration_works_well()
 {
     //Use default configuration
     Assert.DoesNotThrow(() => _nomadKernel = new NomadKernel());
 }
Ejemplo n.º 20
0
        /// <summary>
        ///     Sets the kernel up with the provided in <see cref="NomadConfigurationSettings"/> configuration.
        /// </summary>
        protected void SetUpKernel()
        {
            Kernel = new NomadKernel(NomadConfigurationSettings);

            Domain = Kernel.KernelAppDomain;
        }
        private static void loading_module_into_module_appdomain_callback()
        {
            SetUpInDomain();

            _nomadKernel = new NomadKernel(_configuration);

            var expectedModuleInfos = new[]
                                          {
                                              //Set Up modules to be loaded.
                                              new ModuleInfo(_assemblyFullPath),
                                          };

            SetUpModuleDiscovery(expectedModuleInfos);

            _nomadKernel.ModuleAppDomain.AssemblyLoad +=
                (sender, args) => Assert.AreEqual(AssemblyFullName,
                                                  args.LoadedAssembly.
                                                      FullName,
                                                  "The module has not been loaded into Module AppDomain");

            _nomadKernel.ModuleAppDomain.UnhandledException +=
                (sender, args) => Assert.Fail("Exception has been thrown" + args.ToString());

            _nomadKernel.LoadModules(_moduleDiscoveryMock.Object);

            //Check for not loading assembly into kernel appDomain
            foreach (Assembly kernelAsm in _nomadKernel.KernelAppDomain.GetAssemblies())
            {
                Assert.AreNotEqual(AssemblyFullName, kernelAsm.FullName,
                                   "The module assembly has been loaded into KernelAppDomain.");
            }
        }
Ejemplo n.º 22
0
        protected DistributedMessageCarrier CreateCarrier(NomadKernel kernel)
        {
            var typeName = typeof(DistributedMessageCarrier).FullName;
            var asmName = typeof(DistributedMessageCarrier).Assembly.FullName;
            var carrier = kernel.ModuleAppDomain.CreateInstanceAndUnwrap(asmName, typeName);

            return (DistributedMessageCarrier) carrier;
        }