Exemplo n.º 1
0
        public void ComplexKeyHashingStrategy_1()
        {
            using (var store = new CacheStore(null))
            {
                var strat = new ComplexKeyHashingStrategy(store);

                strat.Put("t1", "A", new businessObject {
                    ID = 000, Name = "Adoyan", IsGood = true
                });
                strat.Put("t1", "B", new businessObject {
                    ID = 234, Name = "Borisenko", IsGood = false
                });
                strat.Put("t1", "C", new businessObject {
                    ID = 342, Name = "Carov", IsGood = true
                });
                strat.Put("t2", "A", new businessObject {
                    ID = 2000, Name = "2Adoyan", IsGood = true
                });
                strat.Put("t2", "B", new businessObject {
                    ID = 2234, Name = "2Borisenko", IsGood = false
                });
                strat.Put("t2", "C", new businessObject {
                    ID = 2342, Name = "2Carov", IsGood = true
                });

                Assert.AreEqual("Adoyan", ((businessObject)strat.Get("t1", "A")).Name);
                Assert.AreEqual("Borisenko", ((businessObject)strat.Get("t1", "B")).Name);
                Assert.AreEqual("Carov", ((businessObject)strat.Get("t1", "C")).Name);

                Assert.AreEqual("2Adoyan", ((businessObject)strat.Get("t2", "A")).Name);
                Assert.AreEqual("2Borisenko", ((businessObject)strat.Get("t2", "B")).Name);
                Assert.AreEqual("2Carov", ((businessObject)strat.Get("t2", "C")).Name);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens metabase from the specified file system instance at the specified metabase root path
        /// </summary>
        /// <param name="bootApplication">IApplication chassis which this metabank boots from</param>
        /// <param name="skyApplication">ISkyApplication chassis which this metabank installs in</param>
        /// <param name="fileSystem">
        /// An instance of a file system that stores the metabase files
        /// Note: This file system is typically a component of Boot application, not the sky app which is being mounted.
        /// Metabank does NOT dispose the FS, as it is an external resource relative to metabank
        /// </param>
        /// <param name="fsSessionParams">File system connection parameter</param>
        /// <param name="rootPath">A path to the directory within the file system that contains metabase root data</param>
        internal Metabank(IApplication bootApplication,
                          ISkyApplication skyApplication,
                          IFileSystem fileSystem,
                          FileSystemSessionConnectParams fsSessionParams,
                          string rootPath) : base(bootApplication.NonNull(nameof(bootApplication)))
        {
            this.m_SkyApplication = skyApplication.NonNull(nameof(skyApplication));

            if (fileSystem is LocalFileSystem && fsSessionParams == null)
            {
                fsSessionParams = new FileSystemSessionConnectParams();
            }

            if (fileSystem == null || fsSessionParams == null)
            {
                throw new MetabaseException(StringConsts.ARGUMENT_ERROR + "Metabank.ctor(fileSystem|fsSessionParams==null)");
            }

            using (var session = ctorFS(fileSystem, fsSessionParams, rootPath))
            {
                m_CommonLevelConfig = getConfigFromFile(session, CONFIG_COMMON_FILE).Root;

                m_RootConfig = getConfigFromFile(session, CONFIG_SECTION_LEVEL_FILE).Root;
                includeCommonConfig(m_RootConfig);
                m_RootConfig.ResetModified();

                m_RootAppConfig  = getConfigFromFile(session, CONFIG_SECTION_LEVEL_ANY_APP_FILE).Root;
                m_PlatformConfig = getConfigFromFile(session, CONFIG_PLATFORMS_FILE).Root;
                m_NetworkConfig  = getConfigFromFile(session, CONFIG_NETWORKS_FILE).Root;
                m_ContractConfig = getConfigFromFile(session, CONFIG_CONTRACTS_FILE).Root;
            }
            m_Catalogs = new Registry <Catalog>();
            var cacheStore = new CacheStore(this, "AC.Metabank");

            //No app available - nowhere to configure: //cacheStore.Configure(null);

            /*
             * cacheStore.TableOptions.Register( new TableOptions(APP_CATALOG, 37, 3) );
             * cacheStore.TableOptions.Register( new TableOptions(BIN_CATALOG, 37, 7) );
             * cacheStore.TableOptions.Register( new TableOptions(REG_CATALOG, 37, 17) );
             * superseded by the cacheStore.DefaultTableOptions below:
             */
            cacheStore.DefaultTableOptions = new TableOptions("*", 37, 17);
            //reg catalog needs more space
            cacheStore.TableOptions.Register(new TableOptions(REG_CATALOG, 571, 37));

            cacheStore.InstrumentationEnabled = false;

            m_Cache = new ComplexKeyHashingStrategy(cacheStore);

            new AppCatalog(this);
            new BinCatalog(this);
            new SecCatalog(this);
            new RegCatalog(this);

            ConfigAttribute.Apply(this, m_RootConfig);
        }
Exemplo n.º 3
0
        public void Hashing_StringKey_6()
        {
            var h1 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("1234012345678 and also some text follows that makes this much longer than others in the same test group");

            Console.WriteLine(h1);

            var h2 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("1234012345678 and also some text follows that makes this much longer than others in the same test group");

            Assert.AreEqual(h1, h2);
        }
Exemplo n.º 4
0
        public void Hashing_StringKey_4()
        {
            var h1 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("1234012345678");

            Console.WriteLine(h1);

            var h2 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("1234012345678");

            Assert.AreEqual(h1, h2);
        }
Exemplo n.º 5
0
        public void Hashing_StringKey_1()
        {
            var h1 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("123");

            Console.WriteLine(h1);

            var h2 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("223");

            Console.WriteLine(h2);
        }
Exemplo n.º 6
0
        public void Hashing_StringKey_2()
        {
            var h1 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("abc");

            Console.WriteLine(h1);

            var h2 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("忁曨曣");

            Console.WriteLine(h2);
            Assert.AreNotEqual(h1, h2);

            var h3 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("忁曣曣");

            Console.WriteLine(h3);
            Assert.AreNotEqual(h3, h2);

            var h4 = ComplexKeyHashingStrategy.DefaultStringKeyToCacheKey("Abc");

            Console.WriteLine(h4);
            Assert.AreNotEqual(h1, h4);
        }
Exemplo n.º 7
0
        public void ComplexKeyHashingStrategy_3(int CNT, double k)
        {
            using (var store = new CacheStore(null))
            {
                var strat = new ComplexKeyHashingStrategy(store);

                for (var i = 0; i < CNT; i++)
                {
                    strat.Put("t1", "ThisIsAKeyLongerThanEight-" + i, new businessObject {
                        ID = i, Name = "Gagarin-" + i, IsGood = true
                    });
                }

                var collision = 0;
                for (var i = 0; i < CNT; i++)
                {
                    Assert.IsNull(strat.Get("t1", "ThisAKeyLongerThanEight-" + i));
                    Assert.IsNull(strat.Get("t1", "ThusIsAKeyLongerThanEight-" + i));
                    Assert.IsNull(strat.Get("t1", "ThisIsAKeyLongerEightThan-" + i));
                    var o = strat.Get("t1", "ThisIsAKeyLongerThanEight-" + i);

                    if (o != null)
                    {
                        Assert.AreEqual(i, ((businessObject)strat.Get("t1", "ThisIsAKeyLongerThanEight-" + i)).ID);
                        Assert.AreEqual(i, ((businessObject)strat.Get("t1", "ThisIsAKeyLongerThanEight-" + i)).ID);
                    }
                    else
                    {
                        collision++;
                    }
                }

                Console.WriteLine("Did {0}, collision {1}", CNT, collision);
                Assert.IsTrue(collision < (int)(CNT * k));
            }
        }
Exemplo n.º 8
0
        public void ComplexKeyHashingStrategy_2(int CNT, double k)
        {
            using (var store = new CacheStore(NOPApplication.Instance))
            {
                var strat = new ComplexKeyHashingStrategy(store);

                for (var i = 0; i < CNT; i++)
                {
                    strat.Put("t1", "Key-" + i, new businessObject {
                        ID = i, Name = "Gagarin-" + i, IsGood = true
                    });
                }


                var collision = 0;
                for (var i = 0; i < CNT; i++)
                {
                    Aver.IsNull(strat.Get("t1", "KeI-" + i));
                    Aver.IsNull(strat.Get("t1", "Ke y-" + i));
                    Aver.IsNull(strat.Get("t1", "Key " + i));

                    var o = strat.Get("t1", "Key-" + i);
                    if (o != null)
                    {
                        Aver.AreEqual(i, ((businessObject)o).ID);
                    }
                    else
                    {
                        collision++;
                    }
                }

                Console.WriteLine("Did {0}, collision {1}", CNT, collision);
                Aver.IsTrue(collision < (int)(CNT * k));
            }
        }