Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
5128:ede035d48b8e | 5130:f2dcdbe05884 |
---|---|
323 } | 323 } |
324 } | 324 } |
325 } | 325 } |
326 | 326 |
327 | 327 |
328 static bool CheckIdempotentSetOfInstances(IJobUnserializer& unserializer, | |
329 ThreadedSetOfInstancesJob& job) | |
330 { | |
331 Json::Value a = 42; | |
332 | |
333 if (!job.Serialize(a)) | |
334 { | |
335 return false; | |
336 } | |
337 else | |
338 { | |
339 std::unique_ptr<ThreadedSetOfInstancesJob> unserialized | |
340 (dynamic_cast<ThreadedSetOfInstancesJob*>(unserializer.UnserializeJob(a))); | |
341 | |
342 Json::Value b = 43; | |
343 if (unserialized->Serialize(b)) | |
344 { | |
345 return (CheckSameJson(a, b) && | |
346 job.GetCurrentStep() == unserialized->GetCurrentStep() && | |
347 job.GetInstancesCount() == unserialized->GetInstancesCount() ); | |
348 } | |
349 else | |
350 { | |
351 return false; | |
352 } | |
353 } | |
354 } | |
355 | |
328 static bool CheckIdempotentSerialization(IJobUnserializer& unserializer, | 356 static bool CheckIdempotentSerialization(IJobUnserializer& unserializer, |
329 IJobOperation& operation) | 357 IJobOperation& operation) |
330 { | 358 { |
331 Json::Value a = 42; | 359 Json::Value a = 42; |
332 operation.Serialize(a); | 360 operation.Serialize(a); |
811 { | 839 { |
812 std::unique_ptr<DicomModification> modification(new DicomModification); | 840 std::unique_ptr<DicomModification> modification(new DicomModification); |
813 modification->SetupAnonymization(DicomVersion_2008); | 841 modification->SetupAnonymization(DicomVersion_2008); |
814 modification->SetLevel(ResourceType_Series); | 842 modification->SetLevel(ResourceType_Series); |
815 | 843 |
816 ResourceModificationJob job(GetContext()); | 844 ResourceModificationJob job(GetContext(), 1); |
817 ASSERT_THROW(job.IsSingleResourceModification(), OrthancException); | 845 ASSERT_THROW(job.IsSingleResourceModification(), OrthancException); |
818 job.SetSingleResourceModification(modification.release(), ResourceType_Patient, true); | 846 job.SetSingleResourceModification(modification.release(), ResourceType_Patient, true); |
819 job.SetOrigin(DicomInstanceOrigin::FromLua()); | 847 job.SetOrigin(DicomInstanceOrigin::FromLua()); |
820 ASSERT_TRUE(job.IsAnonymization()); | 848 ASSERT_TRUE(job.IsAnonymization()); |
821 ASSERT_TRUE(job.IsSingleResourceModification()); | 849 ASSERT_TRUE(job.IsSingleResourceModification()); |
822 ASSERT_EQ(ResourceType_Patient, job.GetOutputLevel()); | 850 ASSERT_EQ(ResourceType_Patient, job.GetOutputLevel()); |
823 | 851 |
824 job.AddTrailingStep(); // Necessary since 1.7.0 | |
825 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job)); | 852 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job)); |
826 ASSERT_TRUE(job.Serialize(s)); | 853 ASSERT_TRUE(job.Serialize(s)); |
827 } | 854 } |
828 | 855 |
829 { | 856 { |
856 ASSERT_EQ(ResourceType_Series, tmp.GetOutputLevel()); // old, incorrect behavior | 883 ASSERT_EQ(ResourceType_Series, tmp.GetOutputLevel()); // old, incorrect behavior |
857 ASSERT_EQ(ResourceType_Series, tmp.GetModification().GetLevel()); | 884 ASSERT_EQ(ResourceType_Series, tmp.GetModification().GetLevel()); |
858 } | 885 } |
859 | 886 |
860 { | 887 { |
861 ResourceModificationJob job(GetContext()); | 888 ResourceModificationJob job(GetContext(), 2); |
862 ASSERT_THROW(job.SetTranscode("nope"), OrthancException); | 889 ASSERT_THROW(job.SetTranscode("nope"), OrthancException); |
863 job.SetTranscode(DicomTransferSyntax_JPEGProcess1); | 890 job.SetTranscode(DicomTransferSyntax_JPEGProcess1); |
864 job.SetSingleResourceModification(new DicomModification, ResourceType_Study, false); | 891 job.SetSingleResourceModification(new DicomModification, ResourceType_Study, false); |
865 | 892 |
866 job.AddTrailingStep(); // Necessary since 1.7.0 | |
867 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job)); | 893 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job)); |
868 ASSERT_TRUE(job.Serialize(s)); | 894 ASSERT_TRUE(job.Serialize(s)); |
869 } | 895 } |
870 | 896 |
871 { | 897 { |
881 ASSERT_EQ(ResourceType_Study, tmp.GetOutputLevel()); | 907 ASSERT_EQ(ResourceType_Study, tmp.GetOutputLevel()); |
882 ASSERT_EQ(ResourceType_Instance, tmp.GetModification().GetLevel()); | 908 ASSERT_EQ(ResourceType_Instance, tmp.GetModification().GetLevel()); |
883 } | 909 } |
884 | 910 |
885 { | 911 { |
886 ResourceModificationJob job(GetContext()); | 912 ResourceModificationJob job(GetContext(), 2); |
887 job.SetMultipleResourcesModification(new DicomModification, true); | 913 job.SetMultipleResourcesModification(new DicomModification, true); |
888 job.AddInstance("toto"); | 914 std::list<std::string> instances; |
889 job.AddInstance("tutu"); | 915 instances.push_back("toto"); |
890 job.AddTrailingStep(); // Necessary since 1.7.0 | 916 instances.push_back("tutu"); |
917 job.AddInstances(instances); | |
891 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job)); | 918 ASSERT_TRUE(CheckIdempotentSetOfInstances(unserializer, job)); |
892 ASSERT_TRUE(job.Serialize(s)); | 919 ASSERT_TRUE(job.Serialize(s)); |
893 } | 920 } |
894 | 921 |
895 { | 922 { |
897 job.reset(unserializer.UnserializeJob(s)); | 924 job.reset(unserializer.UnserializeJob(s)); |
898 | 925 |
899 ResourceModificationJob& tmp = dynamic_cast<ResourceModificationJob&>(*job); | 926 ResourceModificationJob& tmp = dynamic_cast<ResourceModificationJob&>(*job); |
900 | 927 |
901 std::set<std::string> instances; | 928 std::set<std::string> instances; |
902 for (size_t i = 0; i < tmp.GetInstancesCount(); i++) | 929 tmp.GetInstances(instances); |
903 { | |
904 instances.insert(tmp.GetInstance(i)); | |
905 } | |
906 | 930 |
907 ASSERT_EQ(2u, instances.size()); | 931 ASSERT_EQ(2u, instances.size()); |
908 ASSERT_TRUE(instances.find("toto") != instances.end()); | 932 ASSERT_TRUE(instances.find("toto") != instances.end()); |
909 ASSERT_TRUE(instances.find("tutu") != instances.end()); | 933 ASSERT_TRUE(instances.find("tutu") != instances.end()); |
910 | 934 |