public void UseFileArtifactSource()
        {
            var fa = new DirectorySource(_testPath);

            fa.Mask = "*.xml|*.xsd";
            var names = fa.ListArtifactNames();

            Assert.AreEqual(3, names.Count());
            Assert.IsTrue(names.Contains("extension-definitions.xml"));
            Assert.IsTrue(names.Contains("flag.xsd"));
            Assert.IsFalse(names.Contains("patient.sch"));

            using (var stream = fa.LoadArtifactByName("TestPatient.xml"))
            {
                var pat = new FhirXmlParser().Parse <Resource>(SerializationUtil.XmlReaderFromStream(stream));
                Assert.IsNotNull(pat);
            }
        }
Ejemplo n.º 2
0
        public void TestSourceSpeedTest()
        {
            var jsonSource = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData"), includeSubdirectories: false)
            {
                Mask     = "*.json",
                Includes = new[] { "profiles-types.json" }
            };

            Assert.IsNotNull(jsonSource.LoadArtifactByName("profiles-types.json"));

            var xmlSource = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), includeSubdirectories: false)
            {
                Mask     = "*.xml",
                Includes = new[] { "profiles-types.xml" }
            };

            Assert.IsNotNull(xmlSource.LoadArtifactByName("profiles-types.xml"));

            var duration = runTest(jsonSource);

            Assert.IsTrue(duration < 1000);

            duration = runTest(xmlSource);
            Assert.IsTrue(duration < 500);

            long runTest(DirectorySource s)
            {
                var sw = new Stopwatch();

                sw.Start();

                for (var repeat = 0; repeat < 10; repeat++)
                {
                    s.Refresh();  // force reload of whole file
                    s.ListResourceUris().Count();
                }

                sw.Stop();
                return(sw.ElapsedMilliseconds);
            }
        }
Ejemplo n.º 3
0
        public void TestSourceSpeedTest()
        {
            // var jsonSource = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData"), includeSubdirectories: false)
            var jsonSource = new DirectorySource(
                Path.Combine(DirectorySource.SpecificationDirectory, "TestData"),
                new DirectorySourceSettings()
            {
                Mask     = "*.json",
                Includes = new[] { "profiles-types.json" },
                IncludeSubDirectories = false
            });

            Assert.IsNotNull(jsonSource.LoadArtifactByName("profiles-types.json"));

            // var xmlSource = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), includeSubdirectories: false)
            var xmlSource = new DirectorySource(
                Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"),
                new DirectorySourceSettings()
            {
                Mask     = "*.xml",
                Includes = new[] { "profiles-types.xml" },
                IncludeSubDirectories = false
            });

            Assert.IsNotNull(xmlSource.LoadArtifactByName("profiles-types.xml"));

            // var xmlSourceLarge = new DirectorySource(Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"), includeSubdirectories: true)
            var xmlSourceLarge = new DirectorySource(
                Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"),
                new DirectorySourceSettings()
            {
                Mask = "*.xml",
                IncludeSubDirectories = true
            });

            Assert.IsNotNull(xmlSourceLarge.LoadArtifactByName("profiles-types.xml"));

            (var duration, var count) = runTest(jsonSource);
            Debug.WriteLine($"jsonSource: {count} resources, duration {duration} ms");
            Assert.IsTrue(duration < 1000);

            (duration, count) = runTest(xmlSource);
            Debug.WriteLine($"xmlSource: {count} resources, duration {duration} ms");
            Assert.IsTrue(duration < 500);

            (duration, count) = runTest(xmlSourceLarge);
            Debug.WriteLine($"xmlSourceLarge: {count} resources, duration {duration} ms");
            Assert.IsTrue(duration < 10000);

            (long duration, int count) runTest(DirectorySource s)
            {
                var sw = new Stopwatch();

                sw.Start();

                int cnt = 0;

                for (var repeat = 0; repeat < 10; repeat++)
                {
                    s.Refresh();  // force reload of whole file
                    cnt = s.ListResourceUris().Count();
                }

                sw.Stop();
                return(sw.ElapsedMilliseconds, cnt);
            }
        }
        public void TestSourceSpeedTest()
        {
            var jsonSource = new DirectorySource(
                Path.Combine(DirectorySource.SpecificationDirectory, "TestData"),
                new DirectorySourceSettings()
            {
                Mask     = "*.json",
                Includes = new[] { "profiles-types.json" },
                IncludeSubDirectories = false
            });

            using (var stream = jsonSource.LoadArtifactByName("profiles-types.json"))
            {
                Assert.IsNotNull(stream);
            }

            var xmlSource = new DirectorySource(
                Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"),
                new DirectorySourceSettings()
            {
                Mask     = "*.xml",
                Includes = new[] { "profiles-types.xml" },
                IncludeSubDirectories = false
            });

            using (var stream = xmlSource.LoadArtifactByName("profiles-types.xml"))
            {
                Assert.IsNotNull(stream);
            }

            var xmlSourceLarge = new DirectorySource(
                Path.Combine(DirectorySource.SpecificationDirectory, "TestData", "snapshot-test"),
                new DirectorySourceSettings()
            {
                Mask = "*.xml",
                IncludeSubDirectories = true
            });

            using (var stream = xmlSourceLarge.LoadArtifactByName("profiles-types.xml"))
            {
                Assert.IsNotNull(stream);
            }

            runTest("profiles-types.json", jsonSource, false, 1000);
            runTest("profiles-types.xml", xmlSource, false, 500);
            runTest("all xml examples", xmlSourceLarge, false, 10000);

            runTest("profiles-types.json", jsonSource, true, 1000);
            runTest("profiles-types.xml", xmlSource, true, 500);
            runTest("all xml examples", xmlSourceLarge, true, 10000);

            void runTest(string title, DirectorySource s, bool multiThreaded, long maxDuration)
            {
                var sw = new Stopwatch();

                sw.Start();

                int cnt = 0;

                s.MultiThreaded = multiThreaded;
                for (var repeat = 0; repeat < 10; repeat++)
                {
                    s.Refresh();  // force reload of whole file
                    cnt = s.ListResourceUris().Count();
                }

                sw.Stop();
                Console.WriteLine($"{title} : {(multiThreaded ? "multi" : "single")} threaded, {cnt} resources, duration {sw.ElapsedMilliseconds} ms");
                Assert.IsTrue(sw.ElapsedMilliseconds < maxDuration);
            }
        }