Esempio n. 1
0
        public async Task ResolveEntities()
        {
            var cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, "TestResolveEntities");

            cdmCorpus.RootPath = TestHelper.GetInputFolderPath(testsSubpath, "TestResolveEntities");

            var entities = await this.GetAllEntities(cdmCorpus);

            var entityResolutionTimes = new List <Tuple <string, long> >();

            foreach (var data in entities)
            {
                var entity     = data.Item1;
                var doc        = data.Item2;
                var directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                    "normalized", "referenceOnly"
                });
                var resOpt = new ResolveOptions {
                    WrtDoc = doc, Directives = directives
                };
                var watch = Stopwatch.StartNew();
                await entity.CreateResolvedEntityAsync($"{entity.GetName()}_", resOpt); watch.Stop();
                entityResolutionTimes.Add(Tuple.Create(entity.AtCorpusPath, watch.ElapsedMilliseconds));
            }

            entityResolutionTimes.Sort((lhs, rhs) =>
            {
                var diff = rhs.Item2 - lhs.Item2;
                return(diff == 0 ? 0 : diff < 0 ? -1 : 1);
            });

            foreach (var data in entityResolutionTimes)
            {
                Trace.WriteLine($"{data.Item1}:{data.Item2}");
            }

            Assert.Performance(1000, entityResolutionTimes[0].Item2);
            var total = entityResolutionTimes.Sum(data => data.Item2);

            Assert.Performance(5000, total);
        }
Esempio n. 2
0
        public async Task TestProjectionPerformanceOnLoad()
        {
            string testName = nameof(TestProjectionPerformanceOnLoad);
            var    corpus   = TestHelper.GetLocalCorpus(testsSubpath, testName);
            var    entity   = await corpus.FetchObjectAsync <CdmEntityDefinition>("largeProjectionEntity.cdm.json/largeProjectionEntity");

            var operation = ((entity.Attributes[0] as CdmEntityAttributeDefinition).Entity.ExplicitReference as CdmProjection).Operations[0] as CdmOperationAddArtifactAttribute;
            var attGroup  = (operation.NewAttribute as CdmAttributeGroupReference).ExplicitReference as CdmAttributeGroupDefinition;

            // add a large number of attributes to the projection
            for (var i = 1; i < 10000; i++)
            {
                attGroup.Members.Add(new CdmTypeAttributeDefinition(corpus.Ctx, "a" + i));
            }
            var watch = Stopwatch.StartNew();
            // reindex the entity to run through the visit function
            await entity.InDocument.IndexIfNeeded(new ResolveOptions(entity.InDocument), true);

            watch.Stop();
            Assert.Performance(500, watch.ElapsedMilliseconds);
        }
Esempio n. 3
0
        public void TestEntityTimeDateReadInLocalFormat()
        {
            var originalModelJson = TestHelper.GetInputFileContent(testsSubpath, "TestEntityTimeDateReadInLocalFormat", "SerializerTesting-entity2.json");
            var deserialized      = Deserialize <Entity>(originalModelJson);

            var expectedSerializedLastChildFileModifiedTime = "\"2018-12-19T02:05:03.2374986+00:00\"";
            var expectedSerializedLastFileModifiedTime      = "\"2018-12-19T05:05:03.2374986+00:00\"";
            var expectedSerializedLastFileStatusCheckTime   = "\"2018-12-19T21:35:03.2374986+00:00\"";

            var lastChildFileModifiedTime = deserialized?.LastChildFileModifiedTime;
            var lastFileModifiedTime      = deserialized?.LastFileModifiedTime;
            var lastFileStatusCheckTime   = deserialized?.LastFileStatusCheckTime;

            Assert.AreEqual(expectedSerializedLastChildFileModifiedTime, Serialize(lastChildFileModifiedTime));
            Assert.AreEqual(expectedSerializedLastFileModifiedTime, Serialize(lastFileModifiedTime));
            Assert.AreEqual(expectedSerializedLastFileStatusCheckTime, Serialize(lastFileStatusCheckTime));


            string serialized = Serialize(deserialized);

            Assert.IsTrue(serialized.Contains(expectedSerializedLastChildFileModifiedTime));
            Assert.IsTrue(serialized.Contains(expectedSerializedLastFileModifiedTime));
            Assert.IsTrue(serialized.Contains(expectedSerializedLastFileStatusCheckTime));
        }
Esempio n. 4
0
        public async Task ResolveEntitiesWrt()
        {
            var cdmCorpus = new CdmCorpusDefinition();

            var testInputPath = TestHelper.GetInputFolderPath(testsSubpath, "TestResolveEntitiesWrt");

            ((CdmCorpusDefinition)cdmCorpus).RootPath = testInputPath;
            cdmCorpus.Storage.Mount("local", new LocalAdapter(testInputPath));
            cdmCorpus.Storage.DefaultNamespace = "local";
            var entities = await this.GetAllEntities(cdmCorpus);

            var incomingReferences = new Dictionary <CdmEntityDefinition, List <CdmEntityDefinition> >();

            foreach (var data in entities)
            {
                var entity = data.Item1;
                incomingReferences[entity] = new List <CdmEntityDefinition>();
            }

            // Start by populating all the incoming references to the entities
            foreach (var data in entities)
            {
                var entity     = data.Item1;
                var doc        = data.Item2;
                var directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                    "normalized", "referenceOnly"
                });
                var resOpt = new ResolveOptions {
                    WrtDoc = doc, Directives = directives
                };
                var resolvedEntity = await entity.CreateResolvedEntityAsync($"{entity.GetName()}_", resOpt);

                var references = await this.GetEntityReferences(resolvedEntity, resOpt, cdmCorpus);

                if (references.Count > 0)
                {
                    foreach (var reference in references)
                    {
                        incomingReferences[reference].Add(entity);
                    }
                }
            }

            // Next resolve the entity with all of it's incoming references and save the times
            var entityResolutionTimes = new List <Tuple <string, long> >();

            foreach (var data in entities)
            {
                var entity     = data.Item1;
                var doc        = data.Item2;
                var directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                    "normalized", "referenceOnly"
                });
                var resOpt = new ResolveOptions {
                    WrtDoc = doc, Directives = directives
                };
                var watch      = Stopwatch.StartNew();
                var references = incomingReferences[entity];
                foreach (var entRef in references)
                {
                    await entRef.CreateResolvedEntityAsync($"{entRef.GetName()}_", resOpt);
                }

                watch.Stop();
                entityResolutionTimes.Add(Tuple.Create(entity.AtCorpusPath, watch.ElapsedMilliseconds));
            }

            entityResolutionTimes.Sort((lhs, rhs) =>
            {
                var diff = rhs.Item2 - lhs.Item2;
                return(diff == 0 ? 0 : diff < 0 ? -1 : 1);
            });

            foreach (var data in entityResolutionTimes)
            {
                Trace.WriteLine($"{data.Item1}:{data.Item2}");
            }

            Assert.Performance(4000, entityResolutionTimes[0].Item2);
            var total = entityResolutionTimes.Sum(data => data.Item2);

            Assert.Performance(5000, total);
        }