changeset 161:27b3b0df5f90

2 upload tests
author am@osimis.io
date Fri, 17 Aug 2018 17:24:11 +0200
parents 6995d5d12d88
children dbc42a03ee75
files PerfsDb/DbPopulator.py PerfsDb/Run.py PerfsDb/Test.py PerfsDb/TestConfig.py PerfsDb/Tests/UploadFile.py PerfsDb/Tests/__init__.py
diffstat 6 files changed, 118 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/PerfsDb/DbPopulator.py	Fri Aug 17 16:17:57 2018 +0200
+++ b/PerfsDb/DbPopulator.py	Fri Aug 17 17:24:11 2018 +0200
@@ -1,6 +1,7 @@
 import typing
+import time
 from orthancRestApi import OrthancClient
-
+from TestResult import TestResult
 from DbSize import DbSize
 
 class DbPopulator:
@@ -9,7 +10,8 @@
         self._orthanc = orthanc
         self._dbSize = dbSize
         self._sourceInstanceId = None
-
+        self._fileCounter = 0
+    
     def populate(self):
         self._sourceInstanceId = self._orthanc.uploadDicomFile("../Database/DummyCT.dcm")
 
@@ -17,25 +19,43 @@
             patientCount = 1
             smallStudiesPerPatient = 2
             largeStudiesPerPatient = 1
+            seriesPerSmallStudy = 1
+            seriesPerLargeStudy = 2
+            instancesPerSmallSeries = 1
             instancesPerLargeSeries = 5
         elif self._dbSize == DbSize.Small:
-            patientCount = 20
+            patientCount = 100
             smallStudiesPerPatient = 2
             largeStudiesPerPatient = 1
-            instancesPerLargeSeries = 300
+            seriesPerSmallStudy = 1
+            seriesPerLargeStudy = 2
+            instancesPerSmallSeries = 1
+            instancesPerLargeSeries = 30
         elif self._dbSize == DbSize.Medium:
             patientCount = 1000
             smallStudiesPerPatient = 2
-            largeStudiesPerPatient = 1
-            instancesPerLargeSeries = 500
+            largeStudiesPerPatient = 2
+            seriesPerSmallStudy = 1
+            seriesPerLargeStudy = 2
+            instancesPerSmallSeries = 1
+            instancesPerLargeSeries = 300
         elif self._dbSize == DbSize.Large:
-            patientCount = 20000
-            smallStudiesPerPatient = 4
-            largeStudiesPerPatient = 8
-            instancesPerLargeSeries = 500
+            patientCount = 10000
+            smallStudiesPerPatient = 2
+            largeStudiesPerPatient = 2
+            seriesPerSmallStudy = 1
+            seriesPerLargeStudy = 2
+            instancesPerSmallSeries = 1
+            instancesPerLargeSeries = 300
         else:
             raise NotImplementedError
 
+        print("Will generate data for (approximately):")
+        print("{n:>12} patients".format(n=patientCount))
+        print("{n:>12} studies".format(n=patientCount * (smallStudiesPerPatient + largeStudiesPerPatient)))
+        print("{n:>12} instances".format(n=patientCount * (smallStudiesPerPatient * seriesPerSmallStudy * instancesPerSmallSeries + largeStudiesPerPatient * seriesPerLargeStudy * instancesPerLargeSeries)))
+
+        startTime = time.time()
         # first add data that are the same in small and large DBs (and that can be used in tests for comparing the same things !!)
 
         # used in TestFindStudyByPatientId5Results
@@ -55,14 +75,16 @@
             print("Generating data for patient " + str(patientIndex))
             for i in range(0, smallStudiesPerPatient):
                 print("Generating small study " + str(i))
-                self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=2, instancesPerSeries=instancesPerLargeSeries)
+                self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=seriesPerSmallStudy, instancesPerSeries=instancesPerSmallSeries)
                 studyIndex+=1
             for i in range(0, largeStudiesPerPatient):
                 print("Generating large study " + str(i))
-                self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=4, instancesPerSeries=instancesPerLargeSeries)
+                self.createStudy(studyIndex=studyIndex, patientIndex=patientIndex, seriesCount=seriesPerLargeStudy, instancesPerSeries=instancesPerLargeSeries)
                 studyIndex+=1
 
-        print("Generation completed")    
+        endTime = time.time()
+        print("Generation completed.  Elapsed time: {duration:.2f} sec".format(duration=endTime-startTime))    
+        print("Uploaded {n} files -> {p:.2f} files/sec".format(n=self._fileCounter, p=self._fileCounter/(endTime-startTime)))
 
     def createStudy(self, studyIndex: int, patientIndex: int, seriesCount: int, instancesPerSeries: int):
         for seriesIndex in range(0, seriesCount):
@@ -71,6 +93,7 @@
                 self._orthanc.uploadDicom(dicomFile)
 
     def createDicomFile(self, patientIndex: int, studyIndex: int, seriesIndex: int, instanceIndex: int) -> object:
+        self._fileCounter += 1
         return self._orthanc.instances.modify(
             instanceId=self._sourceInstanceId,
             replaceTags={
--- a/PerfsDb/Run.py	Fri Aug 17 16:17:57 2018 +0200
+++ b/PerfsDb/Run.py	Fri Aug 17 17:24:11 2018 +0200
@@ -33,6 +33,14 @@
     TestConfig(label= "mssql-medium", dbSize=DbSize.Medium, dbServer=DbServer(dbType=DbType.MSSQL, port=4004)),
     TestConfig(label= "sqlite-medium", dbSize=DbSize.Medium, dbType=DbType.Sqlite),
     TestConfig(label= "sqliteplugin-medium", dbSize=DbSize.Medium, dbType=DbType.SqlitePlugin),
+
+    TestConfig(label= "mysql-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.MySQL, port=5000)),
+    TestConfig(label= "pg9-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.PG9, port=5001)),
+    TestConfig(label= "pg10-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.PG10, port=5002)),
+    TestConfig(label= "pg11-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.PG11, port=5003)),
+    TestConfig(label= "mssql-large", dbSize=DbSize.Large, dbServer=DbServer(dbType=DbType.MSSQL, port=5004)),
+    TestConfig(label= "sqlite-large", dbSize=DbSize.Large, dbType=DbType.Sqlite),
+    TestConfig(label= "sqliteplugin-large", dbSize=DbSize.Large, dbType=DbType.SqlitePlugin),
 ]
 
 allTests = [
@@ -42,7 +50,8 @@
     TestFindStudyByStudyDescription0Results(),
     TestFindStudyByPatientId0Results(),
     TestFindStudyByPatientId5Results(),
-    TestUploadFile(),
+    TestUploadNextPatientFile(),
+    TestUploadFirstPatientFile(),
 ]
 
 selectedTestConfigs = []
@@ -62,6 +71,8 @@
 parser.add_argument("--plugins-path", help = "path to the folder containing Orthanc executable", default=".")
 parser.add_argument("--repeat", help = "number of times to repeat each test to average timings", type=int, default=50)
 parser.add_argument("--test-filter", help = "filter tests by names (wildcards are allowed)", default="*")
+parser.add_argument("--verbose", help = "start Orthanc in verbose mode", action = "store_true")
+parser.add_argument("--trace", help = "start Orthanc in trace mode", action = "store_true")
 
 args = parser.parse_args()
 
@@ -110,7 +121,7 @@
         testConfig.launchDbServer()
         
         print("** Launching Orthanc")
-        orthancWasAlreadyRunning = not testConfig.launchOrthanc(args.orthanc_path)
+        orthancWasAlreadyRunning = not testConfig.launchOrthanc(args.orthanc_path, verboseEnabled=args.verbose, traceEnabled=args.trace)
         if orthancWasAlreadyRunning and len(selectedTestConfigs) > 1:
             print("Error: Can't execute multiple configuration on already running Orthanc.  Exit Orthanc and let this script start Orthanc instances")
             exit(-1)
--- a/PerfsDb/Test.py	Fri Aug 17 16:17:57 2018 +0200
+++ b/PerfsDb/Test.py	Fri Aug 17 17:24:11 2018 +0200
@@ -58,9 +58,11 @@
 
         for i in range(0, self.repeatCount):
             self.beforeEach()
+            
             startTime = time.time()
             self.test()
             endTime = time.time()
+            
             self.afterEach()
 
             result.add((endTime - startTime) * 1000)
--- a/PerfsDb/TestConfig.py	Fri Aug 17 16:17:57 2018 +0200
+++ b/PerfsDb/TestConfig.py	Fri Aug 17 17:24:11 2018 +0200
@@ -42,7 +42,7 @@
         if self._dbServer is not None:
             self._dbServer.launch()
 
-    def launchOrthanc(self, orthancPath) -> bool:
+    def launchOrthanc(self, orthancPath, verboseEnabled: bool=False, traceEnabled: bool=False) -> bool:
         orthanc = OrthancClient("http://127.0.0.1:8042")
         
         print("Checking if Orthanc is already running")
@@ -51,10 +51,16 @@
             return False
         
         print("Launching Orthanc")
-        self._orthancProcess = subprocess.Popen([
+        runOrthancCommand = [
             os.path.join(orthancPath, "Orthanc"), 
             os.path.join(os.path.abspath(os.path.dirname(__file__)), "ConfigFiles", self.label + ".json"), 
-        ])
+        ]
+        if traceEnabled:
+            runOrthancCommand.append("--trace")
+        elif verboseEnabled:
+            runOrthancCommand.append("--verbose")
+
+        self._orthancProcess = subprocess.Popen(runOrthancCommand)
        
         print("Waiting for Orthanc to start")
         orthanc.waitStarted(timeout=30)
--- a/PerfsDb/Tests/UploadFile.py	Fri Aug 17 16:17:57 2018 +0200
+++ b/PerfsDb/Tests/UploadFile.py	Fri Aug 17 17:24:11 2018 +0200
@@ -1,8 +1,8 @@
 from Test import Test
 
-class TestUploadFile(Test):
+class TestUploadFirstPatientFile(Test):
 
-    def __init__(self, name:str = "UploadFile", filePath:str = "../Database/DummyCT.dcm"):
+    def __init__(self, name:str = "UploadFirstPatientFile", filePath:str = "../Database/DummyCT.dcm"):
         super().__init__(name)
         self._instanceId = None
         self._filePath = filePath
@@ -19,4 +19,58 @@
         self._orthanc.instances.delete(self._instanceId)
 
     def test(self):
-        self._orthanc.uploadDicom(self._dicomFileContent)
\ No newline at end of file
+        self._orthanc.uploadDicom(self._dicomFileContent)
+
+
+class TestUploadNextPatientFile(Test):
+
+    def __init__(self, name:str = "UploadNextPatientFile", filePath:str = "../Database/DummyCT.dcm"):
+        super().__init__(name)
+        self._instanceId = None
+        self._filePath = filePath
+        self._dicomFileContent = None
+        self._instanceIndex = 0
+
+    def beforeAll(self):
+        self._clear()
+
+        # upload a source file that we will modify
+        self._sourceInstanceId = self._orthanc.uploadDicomFile(self._filePath)
+        
+        # upload the first instance of this patient
+        self._dicomFileContent = self._modifyFile()
+        self._orthanc.uploadDicom(self._dicomFileContent)
+
+
+
+    def beforeEach(self):
+        self._dicomFileContent = self._modifyFile()
+
+    def test(self):
+        self._orthanc.uploadDicom(self._dicomFileContent)
+
+    def afterAll(self):
+        self._clear()
+
+    def _clear(self):
+        patient = self._orthanc.patients.find("UploadNextPatientFile")
+        if patient is not None:
+            self._orthanc.patients.delete(patient.id)
+
+    def _modifyFile(self):
+        self._instanceIndex += 1
+        return self._orthanc.instances.modify(
+            instanceId=self._sourceInstanceId,
+            replaceTags={
+                "PatientName": "UploadNextPatientFile",
+                "PatientID": "UploadNextPatientFile",
+                "StudyDescription": "UploadNextPatientFile",
+                "SeriesDescription": "UploadNextPatientFile",
+                "SOPInstanceUID": "999999.888888.777777.666666.555555.44444",
+                "StudyInstanceUID": "999999.888888.777777.666666",
+                "SeriesInstanceUID": "999999.888888.777777.666666.555555",
+                "SeriesNumber": "1",
+                "InstanceNumber": str(self._instanceIndex)
+            },
+            deleteOriginal=False
+        )
\ No newline at end of file
--- a/PerfsDb/Tests/__init__.py	Fri Aug 17 16:17:57 2018 +0200
+++ b/PerfsDb/Tests/__init__.py	Fri Aug 17 17:24:11 2018 +0200
@@ -1,3 +1,3 @@
-from .UploadFile import TestUploadFile
+from .UploadFile import *
 from .FindStudy import *
 from .Statistics import *
\ No newline at end of file