Ejemplo n.º 1
0
        public static void CleanTestObjects()
        {
            using (var svc = new ObjectService(GetConfig()))
            {
                if (svc.NameSpaceExists(NameSpace1))
                {
                    if (svc.ObjectNameExists(NameSpace1, ObjectName1))
                    {
                        svc.UnprovisionObjectStore(NameSpace1, ObjectName1);
                    }

                    if (svc.ObjectNameExists(NameSpace1, ObjectName2))
                    {
                        svc.UnprovisionObjectStore(NameSpace1, ObjectName2);
                    }

                    if (svc.ObjectNameExists(NameSpace1, ObjectName3))
                    {
                        svc.UnprovisionObjectStore(NameSpace1, ObjectName3);
                    }

                    svc.RemoveNameSpace(NameSpace1);
                }
            }
        }
Ejemplo n.º 2
0
        public LocalObjectServiceAdminClient(ObjectService service, string nameSpace)
        {
            if (null == service) { throw new ArgumentNullException("service"); }
            if (null == nameSpace) { throw new ArgumentNullException("nameSpace"); }

            _service = service;
            _nameSpace = nameSpace;
        }
Ejemplo n.º 3
0
        public void BulkStoreManyWithClient()
        {
            using (var svc = new ObjectService(ObjectTestHelper.GetConfig()))
            {
                var ns = ObjectTestHelper.NameSpace1;
                var obj = ObjectTestHelper.ObjectName1;

                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                // stores the object's metadata and builds the database tables
                svc.ProvisionObjectStore(
                    new ObjectMetadata(ns, obj,
                        new ObjectIndexMetadata[]
                        {
                            new ObjectIndexMetadata("IntIndex1", ObjectIndexType.Integer),
                            new ObjectIndexMetadata("StrIndex1", ObjectIndexType.String, 15)
                        }));

                var client = new LocalObjectServiceClient(svc, ns, obj);

                var objCount = 50000;

                var random = new Random();
                var buf = new byte[100];

                BulkStore bulk = client.BeginBulkStore();

                // generate a list of objects to store
                for (int i = 0; objCount > i; i++)
                {
                    random.NextBytes(buf);

                    bulk.Add(buf,
                        new ObjectIndex[]
                        {
                            ObjectIndex.Create("IntIndex1", i + 100),
                            ObjectIndex.Create("StrIndex1", "idx_" + i)
                        });
                }

                // Complete the operation and store and index the objects
                var ids = bulk.Complete();

                Assert.AreEqual(objCount, ids.Count());

                // query 100 objects from the index
                var vals = client.Find(@"{""IntIndex1"":10000, ""Op"": "">"", ""And"" : {""IntIndex1"":10101, ""Op"": ""<""}}");
                Assert.AreEqual(100, vals.Count());
            }
        }
Ejemplo n.º 4
0
        private void _InitializeObjectService()
        {
            var dataPath = Server.MapPath("/App_Data/ObjectService");
            var config = new Config(dataPath);
            ObjectService = new ObjectService(config);

            // ensure that Object Store namespace exists
            if (!ObjectService.NameSpaceExists(Globals.ObjectNameSpace))
            {
                ObjectService.CreateNameSpace(
                    new ObjectNameSpaceConfig(Globals.ObjectNameSpace, "Demo Owner", "Demo Location", DateTime.Now));
            }

            // provision ActivityFeed Object Store
            var metadata = ActivityFeed.GetMetadata();
            if (!ObjectService.ObjectNameExists(metadata.NameSpace, metadata.ObjectName))
            {
                ObjectService.ProvisionObjectStore(metadata);

                // create some test records to query
                var actService = new ActivityFeed(ObjectService);

                DateTime dt = DateTime.UtcNow - new TimeSpan(5, 0, 0);

                for (int i = 0; i < 1000; i++)
                {
                    var actType = ActivityType.News;

                    // put a few different types of activity types in
                    if (0 != i && (0 == i % 5))
                    {
                        actType = ActivityType.Article;
                    }

                    actService.Add(new Activity()
                    {
                        ActivityType = actType,
                        Title = "Demo article #" + i,
                        Text = "Demo article text #" + i,
                        Link = "http://www.website" + i + ".com",
                        Image = "image" + i + ".png",
                        CreatedUTC = DateTime.UtcNow,
                        ExpiresUTC = dt.AddSeconds(i)
                    });
                }
            }
        }
Ejemplo n.º 5
0
        public void BulkStoreWithClient()
        {
            using (var svc = new ObjectService(ObjectTestHelper.GetConfig()))
            {
                var ns = ObjectTestHelper.NameSpace1;
                var obj = ObjectTestHelper.ObjectName1;

                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                svc.ProvisionObjectStore(new ObjectMetadata(ns, obj));

                var client = new LocalObjectServiceClient(svc, ns, obj);

                var val1 = new Guid("{D22640F0-7D87-4F1C-8817-119FC036FAC1}");
                var val2 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
                var val3 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");

                var val2SecondaryKey = Encoding.UTF8.GetBytes("val2key");

                BulkStore bulk = client.BeginBulkStore();

                bulk.Add(12, val1.ToByteArray());
                bulk.Add(val2SecondaryKey, val2.ToByteArray(), null);
                bulk.Add(500, val3.ToByteArray());

                var ids = bulk.Complete().ToArray();
                Assert.AreEqual(3, ids.Length);
                Assert.AreEqual(12, ids[0].ID);
                Assert.IsFalse(ids[0].HasSecondaryKey());
                Assert.AreEqual(1, ids[1].ID);
                Assert.IsTrue(ids[1].HasSecondaryKey());
                Assert.AreEqual(val2SecondaryKey, ids[1].SecondaryKey);
                Assert.AreEqual(500, ids[2].ID);
                Assert.IsFalse(ids[2].HasSecondaryKey());

                Assert.AreEqual(val1, new Guid(client.Get(12)));
                Assert.AreEqual(val2, new Guid(client.Get(1)));
                Assert.AreEqual(val3, new Guid(client.Get(500)));

                Assert.AreEqual(val2, new Guid(client.GetBySecondaryKey(val2SecondaryKey)));

                Assert.AreEqual(3, client.Count());
            }
        }
Ejemplo n.º 6
0
        public void SetAndGetTest()
        {
            using (var svc = new ObjectService(ObjectTestHelper.GetConfig()))
            {
                var ns = ObjectTestHelper.NameSpace1;
                var obj = ObjectTestHelper.ObjectName1;

                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                svc.ProvisionObjectStore(
                    new ObjectMetadata(ns, obj));

                var client = new LocalObjectServiceClient(svc, ns, obj);

                var val1 = new Guid("{C8159CCF-9401-404E-A11E-0B5DF8BA6DB1}");
                var val2 = new Guid("{F1B3E0E4-0C96-4671-8BBF-A086ED1C96BC}");

                var objId1 = client.Store(val1.ToByteArray());
                var objId2 = client.Store(val2.ToByteArray());

                var getVal = client.Get(objId1.ID);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val1, new Guid(getVal));

                getVal = client.Get(objId2.ID);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val2, new Guid(getVal));
            }
        }
Ejemplo n.º 7
0
        public void SetAndFindTest()
        {
            using (var svc = new ObjectService(ObjectTestHelper.GetConfig()))
            {
                var ns = ObjectTestHelper.NameSpace1;
                var obj = ObjectTestHelper.ObjectName1;

                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                var indexName1 = "StrIndex1";
                var indexName2 = "StrIndex2";

                svc.ProvisionObjectStore(
                    new ObjectMetadata(ns, obj,
                        new ObjectIndexMetadata[]
                        {
                            new ObjectIndexMetadata(indexName1, ObjectIndexType.String, 8),
                            new ObjectIndexMetadata(indexName2, ObjectIndexType.String, 1)
                        }));

                var client = new LocalObjectServiceClient(svc, ns, obj);

                var val1 = new Guid("{C8159CCF-9401-404E-A11E-0B5DF8BA6DB1}");
                var val2 = new Guid("{F1B3E0E4-0C96-4671-8BBF-A086ED1C96BC}");
                var indexes1 = new string[] { "AA BB CC", "00 11 22"};
                var indexes2 = new string[] { "F", "M" };

                var objId1 = client.Store(val1.ToByteArray(),
                    new ObjectIndex[]
                    {
                        ObjectIndex.Create(indexName1, indexes1[0]),
                        ObjectIndex.Create(indexName2, indexes2[0])
                    });

                var objId2 = client.Store(val2.ToByteArray(),
                    new ObjectIndex[]
                    {
                        ObjectIndex.Create(indexName1, indexes1[1]),
                        ObjectIndex.Create(indexName2, indexes2[1])
                    });

                var getVal = client.Get(objId1.ID);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val1, new Guid(getVal));

                getVal = client.Get(objId2.ID);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val2, new Guid(getVal));

                getVal = client.Find(@"{ ""StrIndex1"" : ""AA BB CC"" }").FirstOrDefault();
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val1, new Guid(getVal));
            }
        }
Ejemplo n.º 8
0
        public void RemoveTest()
        {
            using (var svc = new ObjectService(ObjectTestHelper.GetConfig()))
            {
                var ns = ObjectTestHelper.NameSpace1;
                var obj = ObjectTestHelper.ObjectName1;

                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                svc.ProvisionObjectStore(
                    new ObjectMetadata(ns, obj));

                var client = new LocalObjectServiceClient(svc, ns, obj);

                var val1 = new Guid("{C8159CCF-9401-404E-A11E-0B5DF8BA6DB1}");
                var val2 = new Guid("{F1B3E0E4-0C96-4671-8BBF-A086ED1C96BC}");
                var val3 = new Guid("{46C4CD37-EECA-416C-AD7A-52F4EA1CC999}");
                var key1 = Encoding.UTF8.GetBytes("val1");
                var key2 = Encoding.UTF8.GetBytes("val2");
                var key3 = Encoding.UTF8.GetBytes("val3");

                var objId1 = client.Store(val1.ToByteArray());
                var objId2 = client.Store(key2, val2.ToByteArray());
                var objId3 = client.Store(key3, val3.ToByteArray());

                // test that all objects are returned
                var getVal = client.Get(objId1.ID);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val1, new Guid(getVal));
                getVal = client.GetBySecondaryKey(key2);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val2, new Guid(getVal));
                getVal = client.GetBySecondaryKey(key3);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val3, new Guid(getVal));

                // remove an object and test that it is no longer returned
                client.Remove(objId1.ID);
                getVal = client.Get(objId1.ID);
                Assert.IsNull(getVal);
                getVal = client.GetBySecondaryKey(key1);
                Assert.IsNull(getVal);
                getVal = client.Get(objId2.ID);
                Assert.IsNotNull(getVal);
                getVal = client.GetBySecondaryKey(key3);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val3, new Guid(getVal));

                // remove a second object
                client.Remove(objId2.ID);
                getVal = client.Get(objId2.ID);
                Assert.IsNull(getVal);
                getVal = client.GetBySecondaryKey(key2);
                Assert.IsNull(getVal);
                getVal = client.GetBySecondaryKey(key3);
                Assert.IsNotNull(getVal);
                Assert.AreEqual(val3, new Guid(getVal));

                // remove a third object by its secondary key
                bool removed = client.RemoveBySecondaryKey(key3);
                Assert.IsTrue(removed);
                getVal = client.Get(objId2.ID);
                Assert.IsNull(getVal);
                getVal = client.GetBySecondaryKey(key2);
                Assert.IsNull(getVal);
                getVal = client.GetBySecondaryKey(key3);
                Assert.IsNull(getVal);
            }
        }
Ejemplo n.º 9
0
        public void MultiThreadedObjectStoreGet()
        {
            var taskCount = 50;
            var taskList = new List<Task>();
            using (var svc = new ObjectService(ObjectTestHelper.GetConfig()))
            {
                var ns = ObjectTestHelper.NameSpace1;
                var obj = ObjectTestHelper.ObjectName1;

                for (int i = 0; taskCount > i; i++)
                {
                    taskList.Add(Task.Factory.StartNew((object state) =>
                    {
                        lock (svc)
                        {
                            if (!svc.NameSpaceExists(ns))
                            {
                                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                                    "ZeroG Test", "Unit Test", DateTime.Now));
                            }

                            if (!svc.ObjectNameExists(ns, obj))
                            {
                                svc.ProvisionObjectStore(
                                    new ObjectMetadata(ns, obj,
                                        new ObjectIndexMetadata[]
                                {
                                    new ObjectIndexMetadata("IntIndex1", ObjectIndexType.Integer),
                                    new ObjectIndexMetadata("StrIndex1", ObjectIndexType.String, 15),
                                    new ObjectIndexMetadata("StrNullIndex1", ObjectIndexType.String, 5, true)
                                }));
                            }
                        }

                        var val1 = new Guid("{D22640F0-7D87-4F1C-8817-119FC036FAC1}");
                        var val2 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
                        var val3 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
                        var intIndex1 = 5;
                        var intIndex2 = 12500;
                        var intIndex3 = -100;
                        var strIndex1 = "asdf";
                        var strIndex2 = "index test val";
                        var strIndex3 = "zzyyxx";

                        var strNullIndexVal = "0011";

                        var objID1 = svc.Store(ns, new PersistentObject()
                        {
                            Name = obj,
                            Value = val1.ToByteArray(),
                            Indexes = new ObjectIndex[]
                            {
                                ObjectIndex.Create("IntIndex1", intIndex1),
                                ObjectIndex.Create("StrIndex1", strIndex1),
                                ObjectIndex.Create("StrNullIndex1", null)
                            }
                        });

                        var objID2 = svc.Store(ns, new PersistentObject()
                        {
                            Name = obj,
                            Value = val2.ToByteArray(),
                            Indexes = new ObjectIndex[]
                            {
                                ObjectIndex.Create("IntIndex1", intIndex2),
                                ObjectIndex.Create("StrIndex1", strIndex2),
                                ObjectIndex.Create("StrNullIndex1", strNullIndexVal)
                            }
                        });

                        var objID3 = svc.Store(ns, new PersistentObject()
                        {
                            Name = obj,
                            Value = val3.ToByteArray(),
                            Indexes = new ObjectIndex[]
                            {
                                ObjectIndex.Create("IntIndex1", intIndex3),
                                ObjectIndex.Create("StrIndex1", strIndex3),
                                ObjectIndex.Create("StrNullIndex1", null)
                            }
                        });

                        var options = new ObjectFindOptions()
                        {
                            Operator = ObjectFindOperator.Equals,
                            Logic = ObjectFindLogic.And
                        };
                        var findVals = svc.Find(ns, obj, options, new ObjectIndex[]
                            {
                                ObjectIndex.Create("ID", objID3.ID),
                                ObjectIndex.Create("StrIndex1", strIndex3)
                            }).ToArray();

                        Assert.AreEqual(1, findVals.Length);
                        Assert.AreEqual(val3, new Guid(findVals[0]));
                    }, i, TaskCreationOptions.LongRunning));
                }
                foreach (Task t in taskList)
                {
                    t.Wait();
                }

                var id = svc.GetNextObjectID(ns, obj);
                Assert.AreEqual(3 * taskCount + 1, id);

                Assert.AreEqual(3 * taskCount, svc.Iterate(ns, obj).Count());

                // count all index values
                Assert.AreEqual(3 * taskCount, svc.Count(ns, obj));
            }
        }
Ejemplo n.º 10
0
        public void FindWithCachingTest()
        {
            using (var svc = new ObjectService(ObjectTestHelper.GetConfigWithCaching()))
            {
                var ns = ObjectTestHelper.NameSpace1;
                var obj = ObjectTestHelper.ObjectName1;

                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                svc.ProvisionObjectStore(
                    new ObjectMetadata(ns, obj,
                        new ObjectIndexMetadata[]
                        {
                            new ObjectIndexMetadata("IntIndex1", ObjectIndexType.Integer),
                            new ObjectIndexMetadata("StrIndex1", ObjectIndexType.String, 15)
                        }));

                var val1 = new Guid("{D22640F0-7D87-4F1C-8817-119FC036FAC1}");
                var val2 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
                var val3 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
                var intIndex1 = 5;
                var intIndex2 = 12500;
                var intIndex3 = -100;
                var strIndex1 = "asdf";
                var strIndex2 = "index test val";
                var strIndex3 = "zzyyxx";

                var objID1 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val1.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex1),
                        ObjectIndex.Create("StrIndex1", strIndex1)
                    }
                });

                var objID2 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val2.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex2),
                        ObjectIndex.Create("StrIndex1", strIndex2)
                    }
                });

                var objID3 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val3.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex3),
                        ObjectIndex.Create("StrIndex1", strIndex3)
                    }
                });

                // test a single index lookup using And
                var options = new ObjectFindOptions()
                {
                    Operator = ObjectFindOperator.Equals,
                    Logic = ObjectFindLogic.And
                };
                var findVals = svc.Find(ns, obj, options, new ObjectIndex[]
                {
                    ObjectIndex.Create("IntIndex1", 12500)
                }).ToArray();

                Assert.AreEqual(1, findVals.Length);
                Assert.AreEqual(val2, new Guid(findVals[0]));

                // test two index lookups using And
                options = new ObjectFindOptions()
                {
                    Operator = ObjectFindOperator.Equals,
                    Logic = ObjectFindLogic.And
                };

                findVals = svc.Find(ns, obj, options, new ObjectIndex[]
                {
                    ObjectIndex.Create("StrIndex1", "index test val"),
                    ObjectIndex.Create("IntIndex1", 12500)
                }).ToArray();

                Assert.AreEqual(1, findVals.Length);
                Assert.AreEqual(val2, new Guid(findVals[0]));

                // test a single lookup using Or
                options = new ObjectFindOptions()
                {
                    Operator = ObjectFindOperator.Equals,
                    Logic = ObjectFindLogic.Or
                };
                findVals = svc.Find(ns, obj, options, new ObjectIndex[]
                {
                    ObjectIndex.Create("IntIndex1", 12500)
                }).ToArray();

                Assert.AreEqual(1, findVals.Length);
                Assert.AreEqual(val2, new Guid(findVals[0]));

                // test two index lookups using Or
                options = new ObjectFindOptions()
                {
                    Operator = ObjectFindOperator.Equals,
                    Logic = ObjectFindLogic.Or
                };
                findVals = svc.Find(ns, obj, options, new ObjectIndex[]
                {
                    ObjectIndex.Create("IntIndex1", 12500),
                    ObjectIndex.Create("StrIndex1", "asdf")
                }).ToArray();

                Assert.AreEqual(2, findVals.Length);
                var findVal1 = new Guid(findVals[0]);
                var findVal2 = new Guid(findVals[1]);
                Assert.IsFalse(findVal1 == findVal2);
                Assert.IsTrue(findVal1 == val1 || findVal1 == val2);
                Assert.IsTrue(findVal2 == val1 || findVal2 == val2);
            }
        }
Ejemplo n.º 11
0
        public void FindByConstraintWithCachingTest()
        {
            using (var svc = new ObjectService(ObjectTestHelper.GetConfigWithCaching()))
            {
                var ns = ObjectTestHelper.NameSpace1;
                var obj = ObjectTestHelper.ObjectName1;

                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                svc.ProvisionObjectStore(
                    new ObjectMetadata(ns, obj,
                        new ObjectIndexMetadata[]
                        {
                            new ObjectIndexMetadata("IntIndex1", ObjectIndexType.Integer),
                            new ObjectIndexMetadata("StrIndex1", ObjectIndexType.String, 15)
                        }));

                var val1 = new Guid("{D22640F0-7D87-4F1C-8817-119FC036FAC1}");
                var val2 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
                var val3 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
                var intIndex1 = 5;
                var intIndex2 = 12500;
                var intIndex3 = -100;
                var strIndex1 = "asdf";
                var strIndex2 = "index test val";
                var strIndex3 = "zzyyxx";

                var objID1 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val1.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex1),
                        ObjectIndex.Create("StrIndex1", strIndex1)
                    }
                });

                var objID2 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val2.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex2),
                        ObjectIndex.Create("StrIndex1", strIndex2)
                    }
                });

                var objID3 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val3.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex3),
                        ObjectIndex.Create("StrIndex1", strIndex3)
                    }
                });

                var findVals = svc.Find(ns, obj, @"{ ""IntIndex1"" : 12500, ""Op"" : ""="" }").ToArray();

                Assert.AreEqual(1, findVals.Length);
                Assert.AreEqual(val2, new Guid(findVals[0]));
            }
        }
Ejemplo n.º 12
0
        public void CacheWithObjectRemovedEvent()
        {
            Config config = ObjectTestHelper.GetConfigWithCaching();
            string ns = ObjectTestHelper.NameSpace1;
            string obj = ObjectTestHelper.ObjectName1;
            string objectFullName = ObjectNaming.CreateFullObjectName(ns, obj);
            ObjectMetadata objectMetadata = new ObjectMetadata(ns, obj,
                new ObjectIndexMetadata[]
                {
                    new ObjectIndexMetadata("IntIndex1", ObjectIndexType.Integer),
                    new ObjectIndexMetadata("StrIndex1", ObjectIndexType.String, 15)
                });

            // Temporarily use the ObjectService to provision the Object's Metadata.
            using (var svc = new ObjectService(config))
            {
                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                svc.ProvisionObjectStore(objectMetadata);
            }

            ObjectMetadataStore metadata = new ObjectMetadataStore(config);
            ObjectVersionStore versions = new ObjectVersionStore(config, metadata);
            ObjectIndexerCache cache = new ObjectIndexerCache(metadata, versions);

            string intVal1 = ObjectIndex.Create("IntIdx", 5).ToString();
            string strVal1 = ObjectIndex.Create("StrIdx", "Val1").ToString();
            string strVal2 = ObjectIndex.Create("StrIdx", "Val3").ToString();

            object[] cacheParams = new object[] { objectFullName, intVal1, strVal1 };
            object[] cacheParams2 = new object[] { objectFullName, intVal1, strVal2 };
            int[] objectIds = new int[] { 1000, 2000 };
            int[] objectIds2 = new int[] { 3000, 4000 };

            try
            {
                // add a couple items to cache - they should not be cleared
                // when the object's metadata is removed
                cache.Set(objectIds, cacheParams);
                cache.Set(objectIds2, cacheParams2);

                Assert.AreEqual(2, cache.EnumerateCache().Count());
                CacheTotals totals = cache.Totals;
                Assert.AreEqual(2, totals.TotalQueries);
                Assert.AreEqual(4, totals.TotalValues);
                Assert.IsNotNull(cache.Get(cacheParams));
                Assert.IsNotNull(cache.Get(cacheParams2));

                metadata.Remove(objectFullName);

                // NOTE: Dirty cache entries are not removed from cache as soon as
                // they become dirty. They are removed lazily when Get/Set
                // are called.
                // CacheTotals and Enumerate will return Dirty objects and are
                // only meant to be used by the Cache Cleaner and not directly
                // by the Object Indexer.
                Assert.AreEqual(0, cache.EnumerateCache().Count());
                totals = cache.Totals;
                Assert.AreEqual(0, totals.TotalQueries);
                Assert.AreEqual(0, totals.TotalValues);
                Assert.IsNull(cache.Get(cacheParams));
                Assert.IsNull(cache.Get(cacheParams2));

                // The metadata needs to be added back so TestCleanup completes
                metadata.StoreMetadata(objectMetadata);
            }
            finally
            {
                cache.Dispose();
                versions.Dispose();
                metadata.Dispose();
            }
        }
Ejemplo n.º 13
0
        public void CacheWithDependencyVersionChangeEvent()
        {
            Config config = ObjectTestHelper.GetConfigWithCaching();
            string ns = ObjectTestHelper.NameSpace1;
            string obj = ObjectTestHelper.ObjectName1;
            string obj2 = ObjectTestHelper.ObjectName2;
            string objectFullName = ObjectNaming.CreateFullObjectName(ns, obj);
            string objectFullName2 = ObjectNaming.CreateFullObjectName(ns, obj2);

            ObjectMetadata objectMetadata = new ObjectMetadata(ns, obj,
                new ObjectIndexMetadata[]
                {
                    new ObjectIndexMetadata("IntIndex1", ObjectIndexType.Integer),
                    new ObjectIndexMetadata("StrIndex1", ObjectIndexType.String, 15)
                });

            ObjectMetadata objectMetadata2 = new ObjectMetadata(ns, obj2, null,
                new string[] { obj }); // Make Object1 a dependency of Object2.
            // Now whenever Object2's version changes, Object1's change event will fire as well.
            // NOTE: Do not supply Full Object Name as objects can only depend on other objects
            // within their namespace.

            // Temporarily use the ObjectService to provision the Object's Metadata.
            using (var svc = new ObjectService(config))
            {
                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                svc.ProvisionObjectStore(objectMetadata);
                svc.ProvisionObjectStore(objectMetadata2);
            }

            ObjectMetadataStore metadata = new ObjectMetadataStore(config);
            ObjectVersionStore versions = new ObjectVersionStore(config, metadata);
            ObjectIndexerCache cache = new ObjectIndexerCache(metadata, versions);

            string intVal1 = ObjectIndex.Create("IntIdx", 5).ToString();
            string strVal1 = ObjectIndex.Create("StrIdx", "Val1").ToString();
            string strVal2 = ObjectIndex.Create("StrIdx", "Val3").ToString();

            object[] cacheParams = new object[] { objectFullName, intVal1, strVal1 };
            object[] cacheParams2 = new object[] { objectFullName, intVal1, strVal2 };
            int[] objectIds = new int[] { 1000, 2000 };
            int[] objectIds2 = new int[] { 3000, 4000 };

            try
            {
                // add a couple items to cache - they should not be returned
                // once the objects dependency object version changes
                cache.Set(objectIds, cacheParams);
                cache.Set(objectIds2, cacheParams2);

                Assert.AreEqual(2, cache.EnumerateCache().Count());
                CacheTotals totals = cache.Totals;
                Assert.AreEqual(2, totals.TotalQueries);
                Assert.AreEqual(4, totals.TotalValues);
                Assert.IsNotNull(cache.Get(cacheParams));
                Assert.IsNotNull(cache.Get(cacheParams2));

                versions.Update(objectFullName2);

                Assert.AreEqual(2, cache.EnumerateCache().Count());
                totals = cache.Totals;
                Assert.AreEqual(2, totals.TotalQueries);
                Assert.AreEqual(4, totals.TotalValues);

                Assert.IsNull(cache.Get(cacheParams));
                Assert.IsNull(cache.Get(cacheParams2));

                cache.Set(objectIds, cacheParams);
                cache.Set(objectIds2, cacheParams2);

                Assert.AreEqual(2, cache.EnumerateCache().Count());
                totals = cache.Totals;
                Assert.AreEqual(2, totals.TotalQueries);
                Assert.AreEqual(4, totals.TotalValues);
                Assert.IsNotNull(cache.Get(cacheParams));
                Assert.IsNotNull(cache.Get(cacheParams2));
            }
            finally
            {
                cache.Dispose();
                versions.Dispose();
                metadata.Dispose();
            }
        }
Ejemplo n.º 14
0
        public void CachePerfTest()
        {
            var stopWatchUncached = new Stopwatch();
            var stopWatchCached = new Stopwatch();

            var stopWatchCountUncached = new Stopwatch();
            var stopWatchCountCached = new Stopwatch();

            var ns = ObjectTestHelper.NameSpace1;
            var obj = ObjectTestHelper.ObjectName1;

            var val1 = new Guid("{D22640F0-7D87-4F1C-8817-119FC036FAC1}");
            var val2 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
            var val3 = new Guid("{72FC1391-EC51-4826-890B-D02071A9A2DE}");
            var intIndex1 = 5;
            var intIndex2 = 12500;
            var intIndex3 = -100;
            var strIndex1 = "asdf";
            var strIndex2 = "index test val";
            var strIndex3 = "zzyyxx";

            using (var svc = new ObjectService(ObjectTestHelper.GetConfig()))
            {
                svc.CreateNameSpace(new ObjectNameSpaceConfig(ns,
                    "ZeroG Test", "Unit Test", DateTime.Now));

                svc.ProvisionObjectStore(
                    new ObjectMetadata(ns, obj,
                        new ObjectIndexMetadata[]
                        {
                            new ObjectIndexMetadata("IntIndex1", ObjectIndexType.Integer),
                            new ObjectIndexMetadata("StrIndex1", ObjectIndexType.String, 15)
                        }));

                var objID1 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val1.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex1),
                        ObjectIndex.Create("StrIndex1", strIndex1)
                    }
                });

                var objID2 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val2.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex2),
                        ObjectIndex.Create("StrIndex1", strIndex2)
                    }
                });

                var objID3 = svc.Store(ns, new PersistentObject()
                {
                    Name = obj,
                    Value = val3.ToByteArray(),
                    Indexes = new ObjectIndex[]
                    {
                        ObjectIndex.Create("IntIndex1", intIndex3),
                        ObjectIndex.Create("StrIndex1", strIndex3)
                    }
                });

                stopWatchUncached.Start();
                for (int i = 0; i < 10; i++)
                {
                    var findVals = svc.Find(ns, obj, @"{ ""IntIndex1"" : 12500 }").ToArray();
                    Assert.AreEqual(1, findVals.Length);
                    Assert.AreEqual(val2, new Guid(findVals[0]));
                }
                stopWatchUncached.Stop();

                stopWatchCountUncached.Start();
                for (int i = 0; i < 10; i++)
                {
                    var count = svc.Count(ns, obj, @"{ ""IntIndex1"" : 12500 }");
                    Assert.AreEqual(1, count);
                }
                stopWatchCountUncached.Stop();
            }

            using (var svc = new ObjectService(ObjectTestHelper.GetConfigWithCaching()))
            {
                stopWatchCached.Start();
                for (int i = 0; i < 10; i++)
                {
                    var findVals = svc.Find(ns, obj, @"{ ""IntIndex1"" : 12500 }").ToArray();
                    Assert.AreEqual(1, findVals.Length);
                    Assert.AreEqual(val2, new Guid(findVals[0]));
                }
                stopWatchCached.Stop();

                stopWatchCountCached.Start();
                for (int i = 0; i < 10; i++)
                {
                    var count = svc.Count(ns, obj, @"{ ""IntIndex1"" : 12500 }");
                    Assert.AreEqual(1, count);
                }
                stopWatchCountCached.Stop();
            }

            Assert.IsTrue(stopWatchUncached.Elapsed > stopWatchCached.Elapsed);
            Assert.IsTrue(stopWatchCountUncached.Elapsed > stopWatchCountCached.Elapsed);

            Console.WriteLine("Uncached Find time: {0} -- Cached Find time: {1}",
                stopWatchUncached.Elapsed,
                stopWatchCached.Elapsed);

            Console.WriteLine("Uncached Count time: {0} -- Cached Count time: {1}",
                stopWatchCountUncached.Elapsed,
                stopWatchCountCached.Elapsed);
        }
Ejemplo n.º 15
0
 public ActivityFeed(ObjectService svc)
 {
     // LocalObjectServiceClient means that hte ObjectService is running on the local machine
     _svc = new LocalObjectServiceClient(svc, Globals.ObjectNameSpace, ObjectName);
 }