diff OrthancServer/UnitTestsSources/ServerJobsTests.cpp @ 5130:f2dcdbe05884

ResourceModification jobs can now use multiple threads
author Alain Mazy <am@osimis.io>
date Thu, 05 Jan 2023 17:24:43 +0100
parents 6eff25f70121
children 0ea402b4d901
line wrap: on
line diff
--- a/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Mon Dec 19 20:00:21 2022 +0100
+++ b/OrthancServer/UnitTestsSources/ServerJobsTests.cpp	Thu Jan 05 17:24:43 2023 +0100
@@ -325,6 +325,34 @@
 }
 
 
+static bool CheckIdempotentSetOfInstances(IJobUnserializer& unserializer,
+                                          ThreadedSetOfInstancesJob& job)
+{
+  Json::Value a = 42;
+  
+  if (!job.Serialize(a))
+  {
+    return false;
+  }
+  else
+  {
+    std::unique_ptr<ThreadedSetOfInstancesJob> unserialized
+      (dynamic_cast<ThreadedSetOfInstancesJob*>(unserializer.UnserializeJob(a)));
+  
+    Json::Value b = 43;
+    if (unserialized->Serialize(b))
+    {    
+      return (CheckSameJson(a, b) &&
+              job.GetCurrentStep() == unserialized->GetCurrentStep() &&
+              job.GetInstancesCount() == unserialized->GetInstancesCount() );
+    }
+    else
+    {
+      return false;
+    }
+  }
+}
+
 static bool CheckIdempotentSerialization(IJobUnserializer& unserializer,
                                          IJobOperation& operation)
 {
@@ -813,7 +841,7 @@
     modification->SetupAnonymization(DicomVersion_2008);
     modification->SetLevel(ResourceType_Series);
 
-    ResourceModificationJob job(GetContext());
+    ResourceModificationJob job(GetContext(), 1);
     ASSERT_THROW(job.IsSingleResourceModification(), OrthancException);
     job.SetSingleResourceModification(modification.release(), ResourceType_Patient, true);
     job.SetOrigin(DicomInstanceOrigin::FromLua());
@@ -821,7 +849,6 @@
     ASSERT_TRUE(job.IsSingleResourceModification());
     ASSERT_EQ(ResourceType_Patient, job.GetOutputLevel());
 
-    job.AddTrailingStep();  // Necessary since 1.7.0
     ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
     ASSERT_TRUE(job.Serialize(s));
   }
@@ -858,12 +885,11 @@
   }
 
   {
-    ResourceModificationJob job(GetContext());
+    ResourceModificationJob job(GetContext(), 2);
     ASSERT_THROW(job.SetTranscode("nope"), OrthancException);
     job.SetTranscode(DicomTransferSyntax_JPEGProcess1);
     job.SetSingleResourceModification(new DicomModification, ResourceType_Study, false);
 
-    job.AddTrailingStep();  // Necessary since 1.7.0
     ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
     ASSERT_TRUE(job.Serialize(s));
   }
@@ -883,11 +909,12 @@
   }
 
   {
-    ResourceModificationJob job(GetContext());
+    ResourceModificationJob job(GetContext(), 2);
     job.SetMultipleResourcesModification(new DicomModification, true);
-    job.AddInstance("toto");
-    job.AddInstance("tutu");
-    job.AddTrailingStep();  // Necessary since 1.7.0
+    std::list<std::string> instances;
+    instances.push_back("toto");
+    instances.push_back("tutu");
+    job.AddInstances(instances);
     ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job));
     ASSERT_TRUE(job.Serialize(s));
   }
@@ -899,10 +926,7 @@
     ResourceModificationJob& tmp = dynamic_cast<ResourceModificationJob&>(*job);
 
     std::set<std::string> instances;
-    for (size_t i = 0; i < tmp.GetInstancesCount(); i++)
-    {
-      instances.insert(tmp.GetInstance(i));
-    }
+    tmp.GetInstances(instances);
     
     ASSERT_EQ(2u, instances.size());
     ASSERT_TRUE(instances.find("toto") != instances.end());