Exemple #1
0
        public void TestIdentifierSwap(DatabaseType type)
        {
            var mappingDataTable = new DataTable("IdMap");

            mappingDataTable.Columns.Add("priv");
            mappingDataTable.Columns.Add("pub");
            mappingDataTable.Rows.Add("010101", "020202");

            var db = GetCleanedServer(type);

            var options = new IdentifierMapperOptions();

            options.MappingConnectionString = db.Server.Builder.ConnectionString;
            options.MappingTableName        = db.CreateTable("IdMap", mappingDataTable).GetFullyQualifiedName();
            options.SwapColumnName          = "priv";
            options.ReplacementColumnName   = "pub";
            options.MappingDatabaseType     = type;
            options.TimeoutInSeconds        = 500;

            var swapper = new PreloadTableSwapper();

            swapper.Setup(options);

            var consumer = new IdentifierMapperQueueConsumer(Mock.Of <IProducerModel>(), swapper);

            var msg = GetTestDicomFileMessage();

            string reason;

            consumer.SwapIdentifier(msg, out reason);

            AssertDicomFileMessageHasPatientID(msg, "020202");
        }
Exemple #2
0
        public void TestIdentifierSwap_MillionsOfRows(DatabaseType type)
        {
            Console.WriteLine("DatabaseType:" + type);

            var mappingDataTable = new DataTable("IdMap");

            mappingDataTable.Columns.Add("priv");
            mappingDataTable.Columns.Add("pub");
            mappingDataTable.Rows.Add("abclkjlkjdefghijiklaskdf", Guid.NewGuid().ToString());
            var db = GetCleanedServer(type);

            DiscoveredTable tbl;

            var options = new IdentifierMapperOptions();

            options.MappingConnectionString = db.Server.Builder.ConnectionString;
            options.MappingTableName        = (tbl = db.CreateTable("IdMap", mappingDataTable)).GetFullyQualifiedName();
            options.SwapColumnName          = "priv";
            options.ReplacementColumnName   = "pub";
            options.MappingDatabaseType     = type;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            mappingDataTable.Rows.Clear();
            using (var blk = tbl.BeginBulkInsert())
                for (int i = 0; i < 9999999; i++) //9 million
                {
                    mappingDataTable.Rows.Add(i.ToString(), Guid.NewGuid().ToString());

                    if (i % 100000 == 0)
                    {
                        blk.Upload(mappingDataTable);
                        mappingDataTable.Rows.Clear();
                        Console.WriteLine("Upload Table " + i + " rows " + sw.ElapsedMilliseconds);
                    }
                }

            sw.Stop();
            sw.Reset();


            sw.Start();
            var swapper = new PreloadTableSwapper();

            swapper.Setup(options);

            sw.Stop();
            Console.WriteLine("PreloadTableSwapper.Setup:" + sw.ElapsedMilliseconds);
            sw.Reset();

            sw.Start();
            string reason;
            var    answer = swapper.GetSubstitutionFor("12325", out reason);

            sw.Stop();
            Console.WriteLine("Lookup Key:" + sw.ElapsedMilliseconds);
            sw.Reset();

            Assert.IsNotNull(answer);
            Assert.IsTrue(answer.Length > 20);
        }
Exemple #3
0
        public void TestIdentifierSwap_RegexVsDeserialize(DatabaseType type, int batchSize, int numberOfRandomTagsPerDicom)
        {
            var options = new GlobalOptionsFactory().Load();

            var mappingDataTable = new DataTable("IdMap");

            mappingDataTable.Columns.Add("priv");
            mappingDataTable.Columns.Add("pub");
            mappingDataTable.Rows.Add("010101", "020202");
            mappingDataTable.Rows.Add("0101010101", "0202020202");


            var db = GetCleanedServer(type);

            options.IdentifierMapperOptions.MappingConnectionString = db.Server.Builder.ConnectionString;
            options.IdentifierMapperOptions.MappingTableName        = db.CreateTable("IdMap", mappingDataTable).GetFullyQualifiedName();
            options.IdentifierMapperOptions.SwapColumnName          = "priv";
            options.IdentifierMapperOptions.ReplacementColumnName   = "pub";
            options.IdentifierMapperOptions.MappingDatabaseType     = type;
            options.IdentifierMapperOptions.TimeoutInSeconds        = 500;


            var swapper = new PreloadTableSwapper();

            swapper.Setup(options.IdentifierMapperOptions);

            var goodChis = new List <DicomFileMessage>();
            var badChis  = new List <DicomFileMessage>();

            Console.WriteLine("Generating Test data...");

            List <Task> tasks     = new List <Task>();
            object      oTaskLock = new object();

            for (int i = 0; i < batchSize; i++)
            {
                var t = new Task(() =>
                {
                    var a = GetTestDicomFileMessage(Test.ProperlyFormatedChi, numberOfRandomTagsPerDicom);
                    var b = GetTestDicomFileMessage(Test.ProperlyFormatedChi, numberOfRandomTagsPerDicom);
                    lock (oTaskLock)
                    {
                        goodChis.Add(a);
                        badChis.Add(b);
                    }
                });

                t.Start();
                tasks.Add(t);


                if (i % Environment.ProcessorCount == 0)
                {
                    Task.WaitAll(tasks.ToArray());
                    tasks.Clear();
                }

                if (i % 100 == 0)
                {
                    Console.WriteLine(i + " pairs done");
                }
            }

            Task.WaitAll(tasks.ToArray());

            options.IdentifierMapperOptions.AllowRegexMatching = true;

            using (var tester = new MicroserviceTester(options.RabbitOptions, options.IdentifierMapperOptions))
            {
                tester.CreateExchange(options.IdentifierMapperOptions.AnonImagesProducerOptions.ExchangeName, null);

                Console.WriteLine("Pushing good messages to Rabbit...");
                tester.SendMessages(options.IdentifierMapperOptions, goodChis, true);

                var host = new IdentifierMapperHost(options, swapper);
                tester.StopOnDispose.Add(host);

                Console.WriteLine("Starting host");

                Stopwatch sw = Stopwatch.StartNew();
                host.Start();

                new TestTimelineAwaiter().Await(() => host.Consumer.AckCount == batchSize);

                Console.WriteLine("Good message processing (" + batchSize + ") took:" + sw.ElapsedMilliseconds + "ms");
                host.Stop("Test finished");
            }

            options.IdentifierMapperOptions.AllowRegexMatching = false;

            using (var tester = new MicroserviceTester(options.RabbitOptions, options.IdentifierMapperOptions))
            {
                tester.CreateExchange(options.IdentifierMapperOptions.AnonImagesProducerOptions.ExchangeName, null);

                Console.WriteLine("Pushing bad messages to Rabbit...");
                tester.SendMessages(options.IdentifierMapperOptions, badChis, true);

                var host = new IdentifierMapperHost(options, swapper);
                tester.StopOnDispose.Add(host);

                Console.WriteLine("Starting host");

                Stopwatch sw = Stopwatch.StartNew();
                host.Start();

                new TestTimelineAwaiter().Await(() => host.Consumer.AckCount == batchSize);

                Console.WriteLine("Bad message processing (" + batchSize + ") took:" + sw.ElapsedMilliseconds + "ms");

                host.Stop("Test finished");
            }
        }