Esempio n. 1
0
        MiniContext(string name)
        {
            ServiceContainer = new SimpleServiceContainer();
            ServiceContainer.Add(RequirementLayerSerializer.Instance);
            ServiceContainer.Add(SimpleTypeFinder.Default);

            ConfigContainer = SharedDictionary.Create(ServiceContainer);
            ConfigManager   = ConfigurationManager.Create(ConfigContainer).ConfigManager;
        }
            void EntryInit()
            {
                var counter = SharedDictionary.Create <int, string>(this.Id.Runtime);

                counter.TryAdd(1, "M");
                var v = counter[2];

                this.Assert(v == "M");
            }
Esempio n. 3
0
            private void InitOnEntry()
            {
                var counter = SharedDictionary.Create <int, string>(this.Id.Runtime);

                counter.TryAdd(1, "M");

                // Key not present; will throw an exception.
                var v = counter[2];
            }
Esempio n. 4
0
 public void TestSharedDictionary6()
 {
     this.Test(r =>
     {
         var counter = SharedDictionary.Create <int, string>(r);
         r.CreateActor(typeof(M5), new E2(counter, false));
     },
               configuration: Configuration.Create().WithTestingIterations(50));
 }
Esempio n. 5
0
        public void TestMockSharedDictionary7()
        {
            var config = Configuration.Create().WithNumberOfIterations(50);
            var test   = new Action <PSharpRuntime>((r) => {
                var counter = SharedDictionary.Create <int, string>(r);
                r.CreateMachine(typeof(M6), new E1(counter));
            });

            base.AssertFailed(config, test, "Detected an assertion failure.");
        }
Esempio n. 6
0
        public void TestMockSharedDictionary6()
        {
            var config = Configuration.Create().WithNumberOfIterations(50);
            var test   = new Action <PSharpRuntime>((r) => {
                var counter = SharedDictionary.Create <int, string>(r);
                r.CreateMachine(typeof(M5), new E2(counter, false));
            });

            base.AssertSucceeded(config, test);
        }
Esempio n. 7
0
        MiniContext(string name)
        {
            ServiceContainer = new SimpleServiceContainer();

            ContextObject   = new object();
            ConfigContainer = SharedDictionary.Create(ServiceContainer);
            ConfigManager   = ConfigurationManager.Create(ConfigContainer).ConfigManager;
            PluginRunner    = new PluginRunner(ServiceContainer, ConfigManager);
            PluginRunner.Initialize(ContextObject);
            ServiceContainer.Add <IConfigContainer>(ConfigContainer);
        }
Esempio n. 8
0
            private void InitOnEntry()
            {
                var counter = SharedDictionary.Create <int, string>(this.Id.Runtime);

                this.CreateActor(typeof(N1), new E1(counter));
                counter.TryAdd(1, "M");

                var v = counter[1];

                this.Assert(v == "M", "Reached test assertion.");
            }
Esempio n. 9
0
 public void TestSharedDictionary7()
 {
     this.TestWithError(r =>
     {
         var counter = SharedDictionary.Create <int, string>(r);
         r.CreateActor(typeof(M6), new E1(counter));
     },
                        configuration: Configuration.Create().WithTestingIterations(50),
                        expectedError: "Reached test assertion.",
                        replay: true);
 }
Esempio n. 10
0
            void InitOnEntry()
            {
                var counter = SharedDictionary.Create <int, string>(this.Id.Runtime);

                this.CreateMachine(typeof(N1), new E1(counter));

                counter.TryAdd(1, "M");

                var v = counter[1];

                this.Assert(v == "M");
            }
Esempio n. 11
0
            private void InitOnEntry()
            {
                var counter = SharedDictionary.Create <int, string>(this.Id.Runtime);

                this.CreateMachine(typeof(N4), new E1(counter));

                counter.TryAdd(1, "M");

                var b = counter.TryRemove(1, out string v);

                this.Assert(b == false || v == "M");
                this.Assert(counter.Count == 0);
            }
Esempio n. 12
0
            void EntryInit()
            {
                var counter = SharedDictionary.Create <int, string>(this.Id.Runtime);

                this.CreateMachine(typeof(N), new E(counter));

                counter.TryAdd(1, "M");

                var v = counter[1];
                var c = counter.Count;

                this.Assert(c == 1);
            }
Esempio n. 13
0
            private void InitOnEntry()
            {
                var counter = SharedDictionary.Create <int, string>(this.Id.Runtime);

                this.CreateActor(typeof(N3), new E1(counter));

                counter.TryAdd(1, "M");

                _ = counter[1];
                var c = counter.Count;

                this.Assert(c == 1);
            }
Esempio n. 14
0
 protected override void OnLinkedTo(RuntimeHost runtimeHost, params object[] args)
 {
     if (args == null || args.Length == 0)
     {
         m_dic = SharedDictionary.Create <TKey, TValue>(runtimeHost.Runtime);
     }
     else if (args.Length == 1 && args[0] is IEqualityComparer <TKey> comparer)
     {
         m_dic = SharedDictionary.Create <TKey, TValue>(comparer, runtimeHost.Runtime);
     }
     else
     {
         throw new ArgumentOutOfRangeException(nameof(args), "The value needs to translate in null, empty or the array that has just one element as IEqualityComparer<TKey>.");
     }
 }
Esempio n. 15
0
 public SharedDictionaryTester(string testName, string path, object o, INamedVersionedUniqueId uid1, INamedVersionedUniqueId uid2, Action <ISharedDictionary, object, INamedVersionedUniqueId> f)
 {
     _errors   = new List <ReadElementObjectInfo>();
     _testName = testName;
     _path     = path;
     _seed     = Environment.TickCount;
     _o        = o;
     _uid1     = uid1;
     _uid2     = uid2;
     _dic      = SharedDictionary.Create(null);
     _seed2    = GenerateRandomProperties(_dic, _o, _uid1, 10, _seed);
     f(_dic, _o, _uid1);
     _seed3 = GenerateRandomProperties(_dic, _o, _uid1, 10, _seed2);
     GenerateRandomProperties(_dic, _o, _uid2, 20, _seed3);
 }
Esempio n. 16
0
        public void WriteReadUserConfig()
        {
            string path = Path.Combine(TestFolder, "UserConfig.xml");
            Guid   id   = new Guid("{6AFBAE01-5CD1-4EDE-BB56-4590C5A253DF}");

            // Write ----------------------------------------------------------
            {
                ISharedDictionary      dic    = SharedDictionary.Create(null);
                IConfigManagerExtended config = ConfigurationManager.Create(dic);
                Assert.That(config, Is.Not.Null);
                Assert.That(config.HostUserConfig, Is.Not.Null);
                Assert.That(config.ConfigManager.UserConfiguration, Is.Not.Null);

                config.HostUserConfig["key1"] = "value1";
                config.HostUserConfig["key2"] = "value2";
                config.HostUserConfig["key3"] = "value3";
                config.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id, ConfigPluginStatus.AutomaticStart);

                Assert.That(config.IsUserConfigDirty);
                Assert.That(config.IsSystemConfigDirty, Is.False);

                using (Stream wrt = new FileStream(path, FileMode.Create))
                    using (IStructuredWriter sw = SimpleStructuredWriter.CreateWriter(wrt, null))
                    {
                        config.SaveUserConfig(sw);
                    }
            }

            // Read ------------------------------------------------------------
            {
                ISimpleServiceContainer container = new SimpleServiceContainer();
                ISharedDictionary       dic       = SharedDictionary.Create(container);
                IConfigManagerExtended  config    = ConfigurationManager.Create(dic);

                using (Stream str = new FileStream(path, FileMode.Open))
                    using (IStructuredReader sr = SimpleStructuredReader.CreateReader(str, container))
                    {
                        config.LoadUserConfig(sr);
                    }
                Assert.That(config.HostUserConfig["key1"], Is.EqualTo("value1"));
                Assert.That(config.HostUserConfig["key2"], Is.EqualTo("value2"));
                Assert.That(config.HostUserConfig["key3"], Is.EqualTo("value3"));
                Assert.That(config.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id, ConfigPluginStatus.Disabled) == ConfigPluginStatus.AutomaticStart);
            }
        }
        public void TestDictionarySuccess()
        {
            var runtime = PSharpRuntime.Create();
            var counter = SharedDictionary.Create <int, string>(runtime);
            var tcs1    = new TaskCompletionSource <bool>();
            var failed  = false;

            runtime.OnFailure += delegate
            {
                failed = true;
                tcs1.SetResult(true);
            };

            var m1 = runtime.CreateMachine(typeof(M), new E(counter, tcs1));

            Task.WaitAll(tcs1.Task);
            Assert.False(failed);
        }
Esempio n. 18
0
        public void TestProductionSharedDictionary5()
        {
            var runtime = RuntimeFactory.Create();
            var counter = SharedDictionary.Create <int, string>(runtime);
            var tcs1    = new TaskCompletionSource <bool>();
            var failed  = false;

            runtime.OnFailure += (ex) =>
            {
                failed = true;
                tcs1.SetResult(true);
            };

            var m1 = runtime.CreateActor(typeof(M5), new E(counter, tcs1));

            Task.WaitAll(tcs1.Task);
            Assert.False(failed);
        }
Esempio n. 19
0
        public void WriteReadSystemConfig()
        {
            string path = Path.Combine(TestFolder, "SystemConfig.xml");

            // Write ----------------------------------------------------------
            {
                ISharedDictionary      dic    = SharedDictionary.Create(null);
                IConfigManagerExtended config = ConfigurationManager.Create(dic);

                Assert.That(config.ConfigManager.SystemConfiguration != null);

                config.HostSystemConfig["key1"] = "value1";
                config.HostSystemConfig["key2"] = "value2";
                config.HostSystemConfig["key3"] = "value3";
                config.HostSystemConfig["{12A9FCC0-ECDC-4049-8DBF-8961E49A9EDE}"] = true;

                Assert.That(config.IsSystemConfigDirty);
                Assert.That(config.IsUserConfigDirty, Is.False);

                using (Stream wrt = new FileStream(path, FileMode.Create))
                    using (IStructuredWriter sw = SimpleStructuredWriter.CreateWriter(wrt, null))
                    {
                        config.SaveSystemConfig(sw);
                    }
            }
            TestBase.DumpFileToConsole(path);
            // Read ------------------------------------------------------------
            {
                ISharedDictionary      dic    = SharedDictionary.Create(null);
                IConfigManagerExtended config = new ConfigManagerImpl(dic);

                using (Stream str = new FileStream(path, FileMode.Open))
                    using (IStructuredReader sr = SimpleStructuredReader.CreateReader(str, null))
                    {
                        config.LoadSystemConfig(sr);
                    }
                Assert.That(config.HostSystemConfig["key1"], Is.EqualTo("value1"));
                Assert.That(config.HostSystemConfig["key2"], Is.EqualTo("value2"));
                Assert.That(config.HostSystemConfig["key3"], Is.EqualTo("value3"));
                Assert.That(config.HostSystemConfig["{12A9FCC0-ECDC-4049-8DBF-8961E49A9EDE}"], Is.EqualTo(true));
            }
        }
Esempio n. 20
0
        public void ImportReloadedSkippedFragments()
        {
            INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0];
            INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1];

            string path = TestBase.GetTestFilePath("SharedDic", "ImportReloadedSkippedFragments");

            #region Creates actual fragments

            // Creates a dummy dictionnary and writes it.
            SharedDictionaryImpl dic = CreateDummySharedDic(this, uid1, uid2);
            SharedDicTestContext.Write("Test", path, dic, this);

            // Creates a second dictionnary to load previous data (with skippedFragments).
            IList <ReadElementObjectInfo> errors;
            SharedDictionaryImpl          dicFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors);
            Assert.IsTrue(new FileInfo(path).Length > 0, "File must exist and be not empty.");

            Assert.That(errors.Count, Is.EqualTo(0));
            Assert.That(dicFrag.GetSkippedFragments(this).Count == 2);
            Assert.That(dicFrag[this, uid1, "key1"], Is.Null);
            Assert.That(dicFrag[this, uid2, "key2"], Is.Null);

            #endregion

            ISharedDictionary dic2 = SharedDictionary.Create(SharedDicTestContext.ServiceProvider);
            dic2[this, uid1, "key1"] = "value1";
            dic2[this, uid1, "key2"] = "value2";

            Assert.That(dic2[this, uid2, "key1"], Is.Null);
            Assert.That(dic2[this, uid2, "key2"], Is.Null);

            dic2.Ensure(uid2);

            SharedDictionaryImpl implDic2 = (SharedDictionaryImpl)dic2;
            implDic2.ImportFragments(dicFrag.Fragments, MergeMode.None);
            Assert.That(implDic2.GetSkippedFragments(this) == null);

            Assert.That(dic2[this, uid2, "key1"], Is.EqualTo("value1"));
            Assert.That(dic2[this, uid2, "key2"], Is.EqualTo("value2"));
        }
Esempio n. 21
0
        public static ISharedDictionary Read(string testName, string path, object o, Action <ISharedDictionary> beforeRead, out IList <ReadElementObjectInfo> errors)
        {
            ISharedDictionary dicRead = SharedDictionary.Create(ServiceProvider);

            if (beforeRead != null)
            {
                beforeRead(dicRead);
            }
            using (Stream str = new FileStream(path, FileMode.Open))
            {
                using (IStructuredReader sr = SimpleStructuredReader.CreateReader(str, ServiceProvider))
                {
                    using (ISharedDictionaryReader r = dicRead.RegisterReader(sr, MergeMode.None))
                    {
                        r.ReadPluginsDataElement(testName, o);
                        errors = r.ErrorCollector;
                    }
                }
            }
            return(dicRead);
        }
Esempio n. 22
0
        private Context(bool proxified)
        {
            _serviceContainer = new ContextServiceContainer(this);
            _dic           = SharedDictionary.Create(_serviceContainer);
            _configManager = ConfigurationManager.Create(_dic);
            _reqLayer      = new RequirementLayer("Context");

            _pluginRunner = new PluginRunner(_serviceContainer, _configManager.ConfigManager);
            _serviceContainer.Add(RequirementLayerSerializer.Instance);
            _serviceContainer.Add(SimpleTypeFinder.Default);

            if (proxified)
            {
                _proxifiedContext = (IContext)_pluginRunner.ServiceHost.InjectExternalService(typeof(IContext), this);
            }
            else
            {
                _proxifiedContext = this;
                _serviceContainer.Add <IContext>(this);
            }
            _pluginRunner.Initialize(_proxifiedContext);
        }
Esempio n. 23
0
        public void TestDictionaryCount()
        {
            var runtime    = PSharpRuntime.Create();
            var dictionary = SharedDictionary.Create <int, string>(runtime);
            var counter    = SharedCounter.Create(runtime);
            var tcs1       = new TaskCompletionSource <bool>();
            var tcs2       = new TaskCompletionSource <bool>();
            var failed     = false;

            runtime.OnFailure += delegate
            {
                failed = true;
                tcs1.TrySetResult(true);
                tcs2.TrySetResult(true);
            };

            var m1 = runtime.CreateMachine(typeof(M), new E(dictionary, counter, tcs1));
            var m2 = runtime.CreateMachine(typeof(N), new E(dictionary, counter, tcs2));

            Task.WaitAll(tcs1.Task, tcs2.Task);
            Assert.False(failed);
            Assert.True(counter.GetValue() == T);
        }
Esempio n. 24
0
        public void TestProductionSharedObjects()
        {
            var runtime    = RuntimeFactory.Create();
            var dictionary = SharedDictionary.Create <int, string>(runtime);
            var counter    = SharedCounter.Create(runtime);
            var tcs1       = new TaskCompletionSource <bool>();
            var tcs2       = new TaskCompletionSource <bool>();
            var failed     = false;

            runtime.OnFailure += (ex) =>
            {
                failed = true;
                tcs1.TrySetResult(true);
                tcs2.TrySetResult(true);
            };

            var m1 = runtime.CreateActor(typeof(M), new E(dictionary, counter, tcs1));
            var m2 = runtime.CreateActor(typeof(N), new E(dictionary, counter, tcs2));

            Task.WaitAll(tcs1.Task, tcs2.Task);
            Assert.False(failed);
            Assert.True(counter.GetValue() is 100);
        }