예제 #1
0
        public void TestMethod2()
        {
            string testKey             = "KEY10";
            string testValue           = "VALUE10";
            DistributedCacheStore _dcs = new DistributedCacheStore();

            NMTest.DataSource.DataSource _ds = new NMTest.DataSource.DataSource(_dcs); // Attach

            _dcs.StoreValue(testKey, testValue);

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            Assert.AreEqual(_ds.GetValue(testKey), testValue);
            stopWatch.Stop();
            Assert.IsTrue(stopWatch.ElapsedMilliseconds >= 100);

            System.Threading.Thread.Sleep(1000);

            stopWatch.Reset();
            stopWatch.Start();
            Assert.AreEqual(_ds.GetValue(testKey), testValue);
            stopWatch.Stop();
            Assert.IsTrue(stopWatch.ElapsedMilliseconds < 100);
        }
        private DistributedCacheStore GetDistributedCacheStore()
        {
            var log = GetLog();

            ICacheConfiguration cacheConfiguration = GetConfiguration();

            DistributedCacheStore localCache = new DistributedCacheStore(cacheConfiguration, log);

            return(localCache);
        }
        // Basic store functionality tested in MultiTenantStoresShould.cs

        protected override IMultiTenantStore <TenantInfo> CreateTestStore()
        {
            var services = new ServiceCollection();

            services.AddOptions().AddDistributedMemoryCache();
            var sp = services.BuildServiceProvider();

            var store = new DistributedCacheStore <TenantInfo>(sp.GetRequiredService <IDistributedCache>(), Constants.TenantToken, TimeSpan.FromSeconds(3));

            return(PopulateTestStore(store));
        }
예제 #4
0
        public void TestMethod1()
        {
            DistributedCacheStore _dcs = new DistributedCacheStore();

            NMTest.DataSource.DataSource _ds = new NMTest.DataSource.DataSource(_dcs); // Attach

            for (int k = 0; k < 10; k++)
            {
                _dcs.StoreValue("key" + k, "value" + k);
            }

            for (int k = 0; k < 10; k++)
            {
                Assert.AreEqual(_ds.GetValue("key" + k), "value" + k);
            }
        }
예제 #5
0
        public static void Main(string[] parameters)
        {
            // your code goes here
            DatabaseStore         _dbs = new DatabaseStore();
            DistributedCacheStore _dcs = new DistributedCacheStore();

            DataSource.DataSource _ds = new DataSource.DataSource(_dcs); // Attach

            for (int k = 0; k < 10; k++)
            {
                _dbs.StoreValue("key" + k, "value" + k); //Populate DatabaseStore with data
                _dcs.StoreValue("key" + k, "value" + k); //Distribute Data to DistributedCacheStore for current default "working node"
            }

            for (var i = 0; i < 10; i++)
            {
                new Thread(() =>
                {
                    // your code goes here
                    Random rnd          = new Random();
                    Stopwatch stopWatch = new Stopwatch();
                    string key          = string.Empty;
                    object d;

                    for (int t = 0; t < 50; t++)
                    {
                        key = "key" + rnd.Next(0, 9);
                        stopWatch.Reset();
                        stopWatch.Start();
                        d = _ds.GetValue(key);
                        stopWatch.Stop();

                        Console.WriteLine("[{0}] Request '{1}', response '{2}', time: {3} ms", Thread.CurrentThread.ManagedThreadId, key, d as string, stopWatch.ElapsedMilliseconds.ToString("0.00"));
                    }
                }).Start();
            }

            Console.ReadKey();
        }
예제 #6
0
        static void Main(string[] args)
        {
            #region Display Header Info

            System.Console.ForegroundColor = ConsoleColor.DarkGreen;
            System.Console.WriteLine("---------------------------------------------------------------");
            System.Console.WriteLine("Welcome to NearMap Test ---------------------------------------");
            System.Console.WriteLine("------------------------ https://github.com/izevaka/nearmap-test");
            System.Console.WriteLine("Amir--Pour-----------------------------------------------------");
            System.Console.WriteLine("Mobile: 0414 888 931-------------------------------------------");
            System.Console.WriteLine("---------------------------------------------------------------");
            System.Console.ResetColor();

            #endregion

            #region Setting up log

            ILog log = LogManager.GetLogger(typeof(Program));

            FileInfo configFile = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.xml"));

            XmlConfigurator.ConfigureAndWatch(configFile);

            #endregion

            #region Composition root- Any kind of Dependency injector can be used to set it up

            DatabaseStore databaseStore = new DatabaseStore(log);

            ApplicationInitialiser applicationInitialiser = new ApplicationInitialiser(databaseStore, log);

            applicationInitialiser.Initialise();

            //getting all configs required for application
            CacheConfiguration cacheConfiguration = new CacheConfiguration();

            ICacheStoreAccelerator cacheStoreAccelerator = new CacheStoreAccelerator(cacheConfiguration, log);

            //this class helps local cache work faster, it adds more functionality
            LocalCacheStoreAccelerator localCacheAccelerator = new LocalCacheStoreAccelerator(cacheStoreAccelerator, cacheConfiguration, log);

            //this is the distributed cache
            DistributedCacheStore distributedCacheStore = new DistributedCacheStore(cacheConfiguration, log);

            //this class combines the localcache and distributed cache together  to provide a faster caching mechanism after a while
            //for more demanded objects, this class is the cache layer of the application
            SmartCacheStore fastCacheInterceptor = new SmartCacheStore(distributedCacheStore, localCacheAccelerator, log);

            //this class is responsible to retrieve the data either from cache layer or from database
            Repository repository = new Repository(fastCacheInterceptor, databaseStore, log);

            //this is the service that is going to expose to all consumers
            MyService myService = new MyService(repository);

            #endregion

            System.Console.WriteLine("Start up finished");
            System.Console.WriteLine("---------------------------------------------------------------");

            for (int i = 0; i < 10; i++)
            {
                new Thread(() =>
                {
                    //Sets the resolution of the timer. This has to be done per thread to ensure that 5ms sleep is actually 5 ms.
                    //http://stackoverflow.com/a/522681
                    timeBeginPeriod(5);

                    for (int j = 0; j < 50; j++)
                    {
                        string key = string.Format("key_{0}", random.Next(0, 9));

                        Stopwatch myStopwatch = new Stopwatch();

                        myStopwatch.Reset();
                        myStopwatch.Start();

                        var value = myService.GetItem(key);

                        myStopwatch.Stop();

                        var duration = myStopwatch.ElapsedMilliseconds;

                        System.Console.WriteLine("[{0}] Request '{1}', response '{2}', time: {3}",
                                                 Thread.CurrentThread.ManagedThreadId,
                                                 key,
                                                 value,
                                                 duration.ToString("F2"));

                        System.Console.ResetColor();
                    }

                    timeEndPeriod(5);
                }).Start();
            }

            System.Console.WriteLine("----E--N--D---");

            System.Console.Read();
        }