Exemplo 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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        public void event_all_modules_loaded_is_catched_upon_every_success()
        {
            NomadKernel kernel = SetupMockedKernel();

            // subscribe kernel for event
            bool hasBeenLoaded = false;

            kernel.EventAggregator.Subscribe <NomadAllModulesLoadedMessage>((message) =>
            {
                Assert.AreNotEqual(0, message.ModuleInfos.Count());
                hasBeenLoaded = true;
            });

            //  compiling simple modules
            const string dir         = @"Modules\Kernel\SimpleAllModulesLoadedAwarenessTestModules\Simple\";
            const string fileName    = "AllModulesLoadedEventAwareModule.dll";
            const string module1Name = "SimpleModule1.dll";
            const string module2Name = "SimpleModule2.dll";
            const string keyFile     = @"newkey.xml";

            CompileSimpleModules(dir, keyFile, module1Name, module2Name);

            // compiling aware module
            var compiler = new ModuleCompiler
            {
                OutputDirectory =
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                 @"Modules\Kernel\SimpleAllModulesLoadedAwarenessTestModules\Aware\")
            };

            compiler.OutputName = Path.Combine(compiler.OutputDirectory, fileName);

            string modulePath = compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\Kernel\AllModulesLoadedEventAwareModule.cs");

            KeysGeneratorProgram.Main(new[] { keyFile });
            compiler.GenerateManifestForModule(modulePath, keyFile);
            // set up module which subscribes for event

            // loading aware module
            IModuleDiscovery setUpDiscovery = SetUpDiscovery(new ModuleInfo(modulePath));

            Assert.DoesNotThrow(() => kernel.LoadModules(setUpDiscovery));

            // loading simple modules
            var directoryDiscovery = new DirectoryModuleDiscovery(dir, SearchOption.TopDirectoryOnly);

            Assert.DoesNotThrow(() => kernel.LoadModules(directoryDiscovery));

            //verify the method being called in a module.
            var carrier = (MessageCarrier)kernel.ModuleAppDomain.CreateInstanceAndUnwrap(
                typeof(MessageCarrier).Assembly.FullName, typeof(MessageCarrier).FullName);

            Assert.AreEqual(
                new[] { "AllModulesLoadedEventAwareModule", "AllModulesLoadedEventAwareModule" },
                carrier.List.ToArray());
            Assert.IsTrue(hasBeenLoaded);
        }
Exemplo n.º 5
0
        public void event_after_successful_module_loading_is_published()
        {
            NomadKernel kernel = SetupMockedKernel();

            // subscribe for message in kernel
            bool hasBeenLoaded = false;
            kernel.EventAggregator.Subscribe<NomadAllModulesLoadedMessage>( (message) =>
            {

                Assert.AreEqual(3,message.ModuleInfos.Count());
                hasBeenLoaded = true;
            });

            //  compile module for event aggregation
            const string dir = @"Modules\Kernel\AllModulesLoadedAwarenessTestModules\";
            const string awareModuleName = "AllModulesLoadedEventAwareModule.dll";
            const string module1Name = "SimpleModule1.dll";
            const string module2Name = "SimpleModule2.dll";
            const string keyFile = @"newkey.xml";

            CompileSimpleModules(dir, keyFile, module1Name, module2Name);

            var compiler = new ModuleCompiler
                               {
                                   OutputDirectory =
                                       Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir)
                               };

            compiler.OutputName = Path.Combine(compiler.OutputDirectory, awareModuleName);

            string modulePath = compiler.GenerateModuleFromCode(
                @"..\Source\Nomad.Tests\FunctionalTests\Data\Kernel\AllModulesLoadedEventAwareModule.cs");

            KeysGeneratorProgram.Main(new[] {keyFile});
            compiler.GenerateManifestForModule(modulePath, keyFile);

            var directoryDiscovery = new DirectoryModuleDiscovery(dir, SearchOption.TopDirectoryOnly);

            // loading modules
            Assert.DoesNotThrow(() => kernel.LoadModules(directoryDiscovery));

            //verify the method being called in a module.
            var carrier = (MessageCarrier) kernel.ModuleAppDomain.CreateInstanceAndUnwrap(
                typeof (MessageCarrier).Assembly.FullName, typeof (MessageCarrier).FullName);

            Assert.AreEqual(new[] {"AllModulesLoadedEventAwareModule"}, carrier.List.ToArray());
            Assert.IsTrue(hasBeenLoaded);
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
        public void failing_update_beacause_of_the_missing_dependencies()
        {
            // create the updater module
            string updaterDir = NomadConfigurationSettings.ModuleDirectoryPath;

            ModuleCompiler.SetUpModuleWithManifest(updaterDir,
                                                   @"..\Source\Nomad.Tests\FunctionalTests\Data\Updater\UpdaterModule.cs");

            // version for modules A, B and C
            const string versionString = "1.0.0.0";

            // create modules A with version v0 (this version and dependencies are only in manifest - not in assembly)
            var moduelADir           = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleADir");
            var moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider             = GetVersionProviderForVersion(versionString);
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible2", versionString);

            ModuleCompiler.SetUpModuleWithManifest(moduelADir, ModuleCompiler.DefaultSimpleModuleSource, moduleAConfiguration);

            // create module B with the same setting as A (with version v0)
            var moduelBDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleBDir");

            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider             = GetVersionProviderForVersion(versionString);
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible3", versionString);

            ModuleCompiler.SetUpModuleWithManifest(moduelBDir, ModuleCompiler.DefaultSimpleModuleSourceAlternative, moduleAConfiguration);

            // create module C with no dependency on any other module with version v0
            var moduleCDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleCDir");

            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion(versionString);
            ModuleCompiler.SetUpModuleWithManifest(moduleCDir, ModuleCompiler.DefaultSimpleModuleSourceLastAlternative, moduleAConfiguration);

            // create module B in version v1 which depends on module C in version v1
            var moduleBVersionUpperDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleBUpperDir");

            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider             = GetVersionProviderForVersion("2.0.0.0");
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible3", "2.0.0.0");

            ModuleCompiler.SetUpModuleWithManifest(moduleBVersionUpperDir, ModuleCompiler.DefaultSimpleModuleSourceAlternative, moduleAConfiguration);

            // put module B into repository
            var bRepoModuleInfo = new DirectoryModuleDiscovery(moduleBVersionUpperDir, SearchOption.TopDirectoryOnly)
                                  .GetModules()
                                  .Select(x => x)
                                  .Single();


            ModulesRepository.Setup(x => x.GetAvailableModules())
            .Returns(new AvailableModules(new List <ModuleManifest>()
            {
                bRepoModuleInfo.Manifest
            }));

            ModulesRepository
            .Setup(x => x.GetModule(It.IsAny <string>()))
            .Returns(new ModulePackage()
            {
                ModuleManifest = bRepoModuleInfo.Manifest,
                ModuleZip      = GetZippedData(new List <ModuleInfo>()
                {
                    bRepoModuleInfo
                }, bRepoModuleInfo.Manifest.ModuleName)
            });

            // configure kernel
            NomadConfigurationSettings.UpdaterType = UpdaterType.Automatic;
            SetUpKernel();

            // load modules A,B,C in version v0 into Nomad
            var discovery = new CompositeModuleDiscovery(new DirectoryModuleDiscovery(moduelADir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(moduelBDir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(moduleCDir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(updaterDir, SearchOption.TopDirectoryOnly));

            Kernel.LoadModules(discovery);

            // register for updates available message
            var hasBeenInvoked = false;

            Kernel.EventAggregator.Subscribe <NomadUpdatesReadyMessage>(message =>
            {
                hasBeenInvoked = true;
                Assert.IsTrue(message.Error, "The error should be reported");

                // list of non valid modules is accurate
                Assert.AreEqual("SimplestModulePossible2", message.ModuleManifests[0].ModuleName);
            });

            // initialize check updates (automatic mode)
            Kernel.EventAggregator.Publish(new BeginUpdateMessage());

            // verify that update can not be done
            Assert.IsTrue(hasBeenInvoked, "The updates ready message was not invoked");
            Assert.AreEqual(UpdaterStatus.Invalid, Kernel.ServiceLocator.Resolve <IUpdater>().Status);
        }
Exemplo n.º 8
0
        public void failing_update_beacause_of_the_missing_dependencies()
        {
            // create the updater module
            string updaterDir = NomadConfigurationSettings.ModuleDirectoryPath;
            ModuleCompiler.SetUpModuleWithManifest(updaterDir,
                                    @"..\Source\Nomad.Tests\FunctionalTests\Data\Updater\UpdaterModule.cs");

            // version for modules A, B and C
            const string versionString = "1.0.0.0";

            // create modules A with version v0 (this version and dependencies are only in manifest - not in assembly)
            var moduelADir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleADir");
            var moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion(versionString);
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible2",versionString);

            ModuleCompiler.SetUpModuleWithManifest(moduelADir,ModuleCompiler.DefaultSimpleModuleSource,moduleAConfiguration);

            // create module B with the same setting as A (with version v0)
            var moduelBDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleBDir");
            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion(versionString);
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible3", versionString);

            ModuleCompiler.SetUpModuleWithManifest(moduelBDir, ModuleCompiler.DefaultSimpleModuleSourceAlternative, moduleAConfiguration);

            // create module C with no dependency on any other module with version v0
            var moduleCDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath, @"ModuleCDir");
            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion(versionString);
            ModuleCompiler.SetUpModuleWithManifest(moduleCDir, ModuleCompiler.DefaultSimpleModuleSourceLastAlternative, moduleAConfiguration);

            // create module B in version v1 which depends on module C in version v1
            var moduleBVersionUpperDir = Path.Combine(NomadConfigurationSettings.ModuleDirectoryPath,@"ModuleBUpperDir");
            moduleAConfiguration = ManifestBuilderConfiguration.Default;

            moduleAConfiguration.VersionProvider = GetVersionProviderForVersion("2.0.0.0");
            moduleAConfiguration.ModulesDependenciesProvider = GetModuleDependenciesOnSingleModule("SimplestModulePossible3", "2.0.0.0");

            ModuleCompiler.SetUpModuleWithManifest(moduleBVersionUpperDir, ModuleCompiler.DefaultSimpleModuleSourceAlternative, moduleAConfiguration);

            // put module B into repository
            var bRepoModuleInfo = new DirectoryModuleDiscovery(moduleBVersionUpperDir, SearchOption.TopDirectoryOnly)
                .GetModules()
                .Select(x => x)
                .Single();

            ModulesRepository.Setup(x => x.GetAvailableModules())
                .Returns(new AvailableModules(new List<ModuleManifest>(){bRepoModuleInfo.Manifest}));

            ModulesRepository
                .Setup(x => x.GetModule(It.IsAny<string>()))
                .Returns(new ModulePackage()
                             {
                                 ModuleManifest = bRepoModuleInfo.Manifest,
                                 ModuleZip = GetZippedData(new List<ModuleInfo>(){bRepoModuleInfo},bRepoModuleInfo.Manifest.ModuleName )
                             });

            // configure kernel
            NomadConfigurationSettings.UpdaterType = UpdaterType.Automatic;
            SetUpKernel();

            // load modules A,B,C in version v0 into Nomad
            var discovery = new CompositeModuleDiscovery(new DirectoryModuleDiscovery(moduelADir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(moduelBDir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(moduleCDir, SearchOption.TopDirectoryOnly),
                                                         new DirectoryModuleDiscovery(updaterDir, SearchOption.TopDirectoryOnly));
            Kernel.LoadModules(discovery);

            // register for updates available message
            var hasBeenInvoked = false;
            Kernel.EventAggregator.Subscribe<NomadUpdatesReadyMessage>(message =>
                                                                           {
                                                                               hasBeenInvoked = true;
                                                                               Assert.IsTrue(message.Error,"The error should be reported");

                                                                               // list of non valid modules is accurate
                                                                               Assert.AreEqual("SimplestModulePossible2", message.ModuleManifests[0].ModuleName);
                                                                           });

            // initialize check updates (automatic mode)
            Kernel.EventAggregator.Publish(new BeginUpdateMessage());

            // verify that update can not be done
            Assert.IsTrue(hasBeenInvoked,"The updates ready message was not invoked");
            Assert.AreEqual(UpdaterStatus.Invalid,Kernel.ServiceLocator.Resolve<IUpdater>().Status);
        }