예제 #1
0
        public async Task ResolveCorpus()
        {
            Assert.IsTrue(Directory.Exists(Path.GetFullPath(SchemaDocsRoot)), "SchemaDocsRoot not found!!!");

            var cdmCorpus = new CdmCorpusDefinition();

            cdmCorpus.SetEventCallback(new EventCallback {
                Invoke = CommonDataModelLoader.ConsoleStatusReport
            }, CdmStatusLevel.Warning);

            Console.WriteLine("reading source files");

            var watch = Stopwatch.StartNew();

            cdmCorpus.Storage.Mount("local", new LocalAdapter(SchemaDocsRoot));
            var manifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>(TestHelper.CdmStandardSchemaPath);

            var directives = new AttributeResolutionDirectiveSet(new HashSet <string> {
                "normalized", "referenceOnly"
            });
            await EntityResolutionTests.ListAllResolved(cdmCorpus, directives, manifest);

            watch.Stop();
            Assert.Performance(70000, watch.ElapsedMilliseconds);
        }
예제 #2
0
        public void TestSerializerPerformance()
        {
            var hugeEntity         = this.CreateHugeModel(10000);
            var serializeStopwatch = Stopwatch.StartNew();
            var serialized         = Serialize(hugeEntity);

            serializeStopwatch.Stop();
            var deserializeStopwatch = Stopwatch.StartNew();
            var deserialized         = Deserialize <Model>(serialized);

            deserializeStopwatch.Stop();
            var serializerTime   = serializeStopwatch.ElapsedMilliseconds;
            var deserializerTime = deserializeStopwatch.ElapsedMilliseconds;

            Assert.Performance(500, serializerTime, "Serializing");
            Assert.Performance(1500, deserializerTime, "Deserializing");
        }
예제 #3
0
        public async Task ResolveEntities()
        {
            var cdmCorpus = new CdmCorpusDefinition();

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

            cdmCorpus.RootPath = testInputPath;
            cdmCorpus.Storage.Mount("local", new LocalAdapter(testInputPath));
            cdmCorpus.Storage.DefaultNamespace = "local";
            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);
        }
예제 #4
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);
        }
예제 #5
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);
        }