@@ -8,6 +8,10 @@ import org.apache.http.HttpStatus
8
8
import spock.lang.Stepwise
9
9
import pages.RlpProjectPage
10
10
11
+ import java.util.concurrent.Callable
12
+ import java.util.concurrent.ExecutorService
13
+ import java.util.concurrent.Executors
14
+
11
15
@Stepwise
12
16
// We need GrailsUnitTest because the WebService class has a dependency on grailsApplication.config
13
17
// It slows startup down quite a bit though
@@ -27,6 +31,36 @@ class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {
27
31
webService = new WebService (grailsApplication : getGrailsApplication())
28
32
}
29
33
34
+ private Map buildMintCollectionIdPayload () {
35
+ [
36
+ " survey_metadata" : [
37
+ " survey_details" : [
38
+ " survey_model" : " soil-pit-characterisation-full" ,
39
+ " time" : " 2023-08-28T00:34:13.100Z" ,
40
+ " uuid" : " 123-123-123-123-123" ,
41
+ " project_id" : " monitorProject" ,
42
+ " protocol_id" : " guid-1" ,
43
+ " protocol_version" : " 1"
44
+ ],
45
+ " provenance" :[
46
+ " version_app" : " 0.0.1-xxxxx" ,
47
+ " version_core" : " 0.1.0-1fb53f81" ,
48
+ " version_core_documentation" : " 0.0.1-xxxxx" ,
49
+ " version_org" : " 4.4-SNAPSHOT" ,
50
+ " system_app" : " monitor" ,
51
+ " system_core" : " Monitor-dummy-data-production" ,
52
+ " system_org" : " MERIT"
53
+ ]
54
+ ]
55
+ ]
56
+ }
57
+
58
+ private Map mintCollectionId (Map payload , String token ) {
59
+ String url = testConfig. ecodata. baseUrl + ' paratoo/mintCollectionId'
60
+ Map headers = [" Authorization" : " Bearer ${ token} " ]
61
+ Map resp = webService. post(url, payload, null , ContentType . APPLICATION_JSON , false , false , headers)
62
+ resp
63
+ }
30
64
31
65
def " Add new data set in to project" () {
32
66
@@ -54,28 +88,7 @@ class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {
54
88
]
55
89
56
90
]
57
- Map mintCollectionIdPayload = [
58
- " survey_metadata" : [
59
- " survey_details" : [
60
- " survey_model" : " soil-pit-characterisation-full" ,
61
- " time" : " 2023-08-28T00:34:13.100Z" ,
62
- " uuid" : " 123-123-123-123-123" ,
63
- " project_id" : " monitorProject" ,
64
- " protocol_id" : " guid-1" ,
65
- " protocol_version" : " 1"
66
- ],
67
- " provenance" :[
68
- " version_app" : " 0.0.1-xxxxx" ,
69
- " version_core" : " 0.1.0-1fb53f81" ,
70
- " version_core_documentation" : " 0.0.1-xxxxx" ,
71
- " version_org" : " 4.4-SNAPSHOT" ,
72
- " system_app" : " monitor" ,
73
- " system_core" : " Monitor-dummy-data-production" ,
74
- " system_org" : " MERIT"
75
- ]
76
- ]
77
- ]
78
-
91
+ Map mintCollectionIdPayload = buildMintCollectionIdPayload()
79
92
80
93
Map collectionPayload = [
81
94
" coreProvenance" : [
@@ -93,9 +106,7 @@ class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {
93
106
resp. statusCode == HttpStatus . SC_OK
94
107
95
108
when :
96
- url = testConfig. ecodata. baseUrl + ' paratoo/mintCollectionId'
97
- headers = [" Authorization" : " Bearer ${ token} " ]
98
- resp = webService. post(url, mintCollectionIdPayload, null , ContentType . APPLICATION_JSON , false , false , headers)
109
+ resp = mintCollectionId(mintCollectionIdPayload, token)
99
110
100
111
String orgMintedIdentifier = resp. resp. orgMintedIdentifier
101
112
byte [] jsonBytes = orgMintedIdentifier. decodeBase64()
@@ -139,4 +150,41 @@ class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {
139
150
then : " The data set is displayed"
140
151
datasetDetails. dataSetSummaryCount() == 1
141
152
}
153
+
154
+ def " Paratoo data sets can be submitted concurrently without data errors" () {
155
+ setup :
156
+ ExecutorService executor = Executors . newFixedThreadPool(20 )
157
+ String token = tokenForUser(' 1' )
158
+ String projectId = ' monitorProject'
159
+
160
+ when :
161
+ List callables = []
162
+ for (int i = 0 ; i < 100 ; i++ ) {
163
+ Callable callable = new Callable () {
164
+ @Override
165
+ Object call () throws Exception {
166
+ Map payload = buildMintCollectionIdPayload()
167
+ payload. survey_metadata. protocol_id = " guid-${ i} "
168
+ Map result = mintCollectionId(payload, token)
169
+
170
+ return result
171
+ }
172
+ }
173
+ callables. add(callable)
174
+ }
175
+ executor. invokeAll(callables)
176
+
177
+ String url = testConfig. ecodata. baseUrl + ' project/' + projectId
178
+ Map resp = webService. get(url)
179
+
180
+
181
+ then :
182
+ resp. resp?. custom?. dataSets?. size() == 101
183
+ for (int i = 0 ; i < 100 ; i++ ) {
184
+ resp. resp. custom. dataSets. find { it. surveyId. survey_metadata. protocol_id == ' guid-' + i } != null
185
+ }
186
+
187
+ }
188
+
189
+
142
190
}
0 commit comments