Ejemplo n.º 1
0
        public void TestCache()
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>();

            CmisObjectCache cache = new CmisObjectCache();
            cache.Initialize(null, parameters);

            string cacheKey1 = "ck1";
            string cacheKey2 = "ck2";

            // add first object
            MockObject mock1 = new MockObject("1");
            cache.Put(mock1, cacheKey1);

            ICmisObject o1 = cache.GetById(mock1.Id, cacheKey1);
            Assert.NotNull(o1);
            Assert.AreEqual(mock1.Id, o1.Id);
            Assert.Null(cache.GetById(mock1.Id, cacheKey2));
            Assert.Null(cache.GetById("- some id -", cacheKey1));

            // add second object - same id
            MockObject mock2 = new MockObject("1");
            cache.Put(mock2, cacheKey2);

            o1 = cache.GetById(mock1.Id, cacheKey1);
            Assert.NotNull(o1);
            Assert.AreEqual(mock1.Id, o1.Id);

            ICmisObject o2 = cache.GetById(mock2.Id, cacheKey2);
            Assert.NotNull(o2);
            Assert.AreEqual(mock2.Id, o2.Id);

            // add third object - other id

            MockObject mock3 = new MockObject("3");
            cache.Put(mock3, cacheKey1);

            o1 = cache.GetById(mock1.Id, cacheKey1);
            Assert.NotNull(o1);
            Assert.AreEqual(mock1.Id, o1.Id);

            o2 = cache.GetById(mock2.Id, cacheKey2);
            Assert.NotNull(o2);
            Assert.AreEqual(mock2.Id, o2.Id);

            ICmisObject o3 = cache.GetById(mock3.Id, cacheKey1);
            Assert.NotNull(o3);
            Assert.AreEqual(mock3.Id, o3.Id);
        }
Ejemplo n.º 2
0
        public void TestLRU()
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>();
            parameters[SessionParameter.CacheSizeObjects] = "10";

            CmisObjectCache cache = new CmisObjectCache();
            cache.Initialize(null, parameters);

            string cacheKey1 = "ck1";

            MockObject[] mocks = new MockObject[10];
            for (int i = 0; i < 10; i++)
            {
                mocks[i] = new MockObject("m" + i);
                cache.Put(mocks[i], cacheKey1);
            }

            for (int i = 0; i < 10; i++)
            {
                mocks[i] = new MockObject("m" + i);
                Assert.NotNull(cache.GetById("m" + i, cacheKey1));
            }

            MockObject newMock = new MockObject("new");
            cache.Put(newMock, cacheKey1);
            Assert.NotNull(cache.GetById(newMock.Id, cacheKey1));

            for (int i = 1; i < 10; i++)
            {
                mocks[i] = new MockObject("m" + i);
                Assert.NotNull(cache.GetById("m" + i, cacheKey1));
            }

            Assert.Null(cache.GetById("m0", cacheKey1));
        }
Ejemplo n.º 3
0
        public void TestPath()
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>();

            CmisObjectCache cache = new CmisObjectCache();
            cache.Initialize(null, parameters);

            string cacheKey1 = "ck1";
            string path = "/test/path";

            MockObject mock1 = new MockObject("1");
            cache.PutPath(path, mock1, cacheKey1);

            ICmisObject o1 = cache.GetById(mock1.Id, cacheKey1);
            Assert.NotNull(o1);
            Assert.AreEqual(mock1.Id, o1.Id);

            ICmisObject o2 = cache.GetByPath(path, cacheKey1);
            Assert.NotNull(o2);
            Assert.AreEqual(mock1.Id, o2.Id);

            Assert.Null(cache.GetByPath("/some/other/path/", cacheKey1));
        }
Ejemplo n.º 4
0
        public void TestExpiration()
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>();
            parameters[SessionParameter.CacheTTLObjects] = "500";

            CmisObjectCache cache = new CmisObjectCache();
            cache.Initialize(null, parameters);

            string cacheKey1 = "ck1";

            MockObject mock1 = new MockObject("1");
            cache.Put(mock1, cacheKey1);

            Assert.NotNull(cache.GetById(mock1.Id, cacheKey1));

            Thread.Sleep(TimeSpan.FromSeconds(1));

            Assert.Null(cache.GetById(mock1.Id, cacheKey1));
        }