@@ -5,6 +5,8 @@ import org.elasticsearch.gradle.test.AntFixture
5
5
import org.elasticsearch.gradle.test.ClusterConfiguration
6
6
import org.elasticsearch.gradle.test.RestIntegTestTask
7
7
8
+ import java.lang.reflect.Field
9
+
8
10
/*
9
11
* Licensed to Elasticsearch under one or more contributor
10
12
* license agreements. See the NOTICE file distributed with
@@ -142,10 +144,11 @@ if (useFixture && minioDistribution) {
142
144
fileMode 0755
143
145
}
144
146
145
- long minioPid
146
-
147
147
task startMinio {
148
148
dependsOn installMinio
149
+
150
+ ext. minioPid = 0L
151
+
149
152
doLast {
150
153
new File (" ${ minioDataDir} /${ s3Bucket} " ). mkdirs()
151
154
// we skip these tests on Windows so we do no need to worry about compatibility here
@@ -155,12 +158,26 @@ if (useFixture && minioDistribution) {
155
158
" --address" ,
156
159
minioAddress,
157
160
minioDataDir)
158
- minio. addShutdownHook { minio. destroy() }
159
161
minio. environment(). put(' MINIO_ACCESS_KEY' , s3AccessKey)
160
162
minio. environment(). put(' MINIO_SECRET_KEY' , s3SecretKey)
161
163
minio. environment(). put(' MINIO_DOMAIN' , ' localhost' )
162
164
final Process process = minio. start()
163
- minioPid = process. pid()
165
+ if (JavaVersion . current() <= JavaVersion . VERSION_1_8 ) {
166
+ try {
167
+ Class<?> cProcessImpl = process. getClass()
168
+ Field fPid = cProcessImpl. getDeclaredField(" pid" )
169
+ if (! fPid. isAccessible()) {
170
+ fPid. setAccessible(true )
171
+ }
172
+ minioPid = fPid. getInt(process)
173
+ } catch (Exception e) {
174
+ logger. error(" failed to read pid from minio process" , e)
175
+ process. destroyForcibly()
176
+ throw e
177
+ }
178
+ } else {
179
+ minioPid = process. pid()
180
+ }
164
181
165
182
new BufferedReader (new InputStreamReader (process. getInputStream())). withReader { br ->
166
183
String line
@@ -193,13 +210,13 @@ if (useFixture && minioDistribution) {
193
210
}
194
211
195
212
task stopMinio(type : LoggedExec ) {
196
- onlyIf { minioPid > 0 }
213
+ onlyIf { startMinio . minioPid > 0 }
197
214
198
215
doFirst {
199
- logger. info(" Shutting down minio with pid ${ minioPid} " )
216
+ logger. info(" Shutting down minio with pid ${ startMinio. minioPid} " )
200
217
}
201
218
202
- final Object pid = " ${ -> minioPid } "
219
+ final Object pid = " ${ -> startMinio. minioPid } "
203
220
204
221
// we skip these tests on Windows so we do no need to worry about compatibility here
205
222
executable = ' kill'
0 commit comments