Ok i will start working on this. I have a small question. If user set includeIsolated = true , is it means that API will only fetch the isolated attachments ? ( or fetch both isolated and not isolated attachments ? )
I am getting “Obs.error.trying.write.complex” error in sometimes when i run the test classes. But sometimes it works properly. This error coming from the methods which are used ,
No it is not occur in every time. When i run mvn clean install this error is not occur in most times.I think that this error start to occour when i save the attachments without encounters using ComplexObsSaver.
Could you try narrowing down the issue the specific test method(s) that might be affected? You could do that by temporarily using the @Ignore annotation on the other methods. And then run the test case class via Maven multiple times to validate that the problem indeed occurs.
I’m trying to pinpoint which exact test method does that, or at least find a scenario that can be replayed to reproduce the issue more or less consistently.
I tested using @Ignore annotation. But i can’t find exact method which is give above mentioned error.
But all the newly added test class give error in different times. I can’t find exactly which method from that methods. I think all the following methods have common thing for occur this error.
But maven clean install will give this error only i run that command several time. It works perfectly in first time. Is this can be a problem in cache of the memory ?
@ridmal could you add me as a collaborator (see here how) on your fork of Attachments. I will push a commit to unlock the situation.
I have found the exact reason why this is happening, but in the meantime I took the time to refactor quite a few things so better let me insert a full commit and take it from there.
I’m busy now, going into a meeting, but I will explain what happened in my next message.
P.S. I would be great if you could connect on IRC Freenode #openmrs.
As part of my commit I also changed the actual implementation a little bit. In particular it does not get upset right away if no concepts complex are configured, a simple warning is then given (see here).
However it will get upset if, for some reason (such as a misconfiguration), non-complex obs are returned, see
I am really grateful for your positive feedback and advises given in the 1st evaluation and thankful for all the support and guidance you have given me to complete my tasks.
I update the PR with required changes. There is a error occurred in sometimes ( very rarely occured ) . I think this is because order of the fetching attachments.What Can we about that ?
getAttachments_shouldReturnAllAttachments(org.openmrs.module.attachments.AttachmentsServiceTest): arrays first differed at element [0]; expected:<[0be9476d-17dc-4e01-
be71-51b81e3ec594]> but was:<[1186503c-74c2-43c3-b771-6035ccbe439a]>
Each routine of the service implementation ensures that the obs are returned in descending order of updated timestamps. However in this very specific place the properly sorted obs from two method calls might get mixed up when the two arrays are added. On the other hand the actual attachments are sorted correctly and the assert fails on the first mismatching element (element 0). That’s my guess of what might be happening. Can you @Ignore that test routine and launch the test case multiple times to confirm that that’s where the problem come from?
If you can confirm that, the solution would be to sort expectedAllAttachments by update date prior to asserting against actualAllAttachments.
I run test cases by putting @Ignore in every test cases individually. Like you said testIncludeIsolatedParameter()
unit test occurred previous mentioned error many times. But when i ignore that method and run the test cases , sometimes
getAttachments_shouldReturnAllAttachments() , getAttachments_shouldNotReturnIsolatedAttachments() , getAttachments_shouldReturnIsolatedAttachments() tests also give the same error ( ration of occurring is 1 for 10 times.) I used mvn test -Dtest=AttachmentsServiceTest -pl api-2.0/ for testings.
And for overcome this error can i used this method ,
use Collections.sort(expectedAttachments, Comparator.comparing(Attachment::getUuid)); which will sort the expectedAttachments list based on the Uuid of attachements.( i didn’t able to get getDateCreated() for sorting because it return null vlaues ). And aslo sort the actualAttachments list using same method and used the Assert.assertArrayEquals method for both sorted lists.
@ridmal I added this commit to your branch. This ensures that you can now obtain the attachment/obs date-time out of any Attachment instance. I also added some other minor changes.
Can you try to sort expected attachments by descending date-time in a test method where you know that the problem occurs?