@@ -132,7 +132,7 @@ if (!s3TemporaryAccessKey && !s3TemporarySecretKey && !s3TemporaryBucket && !s3T
132132final String minioVersion = ' RELEASE.2018-06-22T23-48-46Z'
133133final String minioBinDir = " ${ buildDir} /minio/bin"
134134final String minioDataDir = " ${ buildDir} /minio/data"
135- final String minioAddress = " 127.0.0.1:60920 "
135+ final String minioAddress = " 127.0.0.1"
136136
137137final String minioDistribution
138138final String minioCheckSum
@@ -187,15 +187,30 @@ if (useFixture && minioDistribution) {
187187 dependsOn installMinio
188188
189189 ext. minioPid = 0L
190+ ext. minioPort = 0
190191
191192 doLast {
193+ // get free port
194+ for (int port = 60920 ; port < 60940 ; port++ ) {
195+ try {
196+ javax.net.ServerSocketFactory . getDefault(). createServerSocket(port, 1 , InetAddress . getByName(minioAddress)). close()
197+ minioPort = port
198+ break
199+ } catch (BindException e) {
200+ logger. info(" Port " + port + " for Minio process is already taken" , e)
201+ }
202+ }
203+ if (minioPort == 0 ) {
204+ throw new GradleException (" Could not find a free port for Minio" )
205+ }
206+
192207 new File (" ${ minioDataDir} /${ s3PermanentBucket} " ). mkdirs()
193208 // we skip these tests on Windows so we do no need to worry about compatibility here
194209 final ProcessBuilder minio = new ProcessBuilder (
195210 " ${ minioBinDir} /${ minioFileName} " ,
196211 " server" ,
197212 " --address" ,
198- minioAddress,
213+ minioAddress + " : " + minioPort ,
199214 minioDataDir)
200215 minio. environment(). put(' MINIO_ACCESS_KEY' , s3PermanentAccessKey)
201216 minio. environment(). put(' MINIO_SECRET_KEY' , s3PermanentSecretKey)
@@ -227,6 +242,7 @@ if (useFixture && minioDistribution) {
227242 final int index = line. lastIndexOf(" :" )
228243 assert index >= 0
229244 httpPort = Integer . parseInt(line. substring(index + 1 ))
245+ assert httpPort == minioPort : " Port mismatch, expected ${ minioPort} but was ${ httpPort} "
230246
231247 final File script = new File (project. buildDir, " minio/minio.killer.sh" )
232248 script. setText(
@@ -269,10 +285,15 @@ if (useFixture && minioDistribution) {
269285 project. afterEvaluate {
270286 ClusterConfiguration cluster = project. extensions. getByName(' integTestMinioCluster' ) as ClusterConfiguration
271287 cluster. dependsOn(project. bundlePlugin)
288+ cluster. dependsOn(startMinio) // otherwise we don't know the Minio port
272289 cluster. keystoreSetting ' s3.client.integration_test_permanent.access_key' , s3PermanentAccessKey
273290 cluster. keystoreSetting ' s3.client.integration_test_permanent.secret_key' , s3PermanentSecretKey
274291
275- cluster. setting ' s3.client.integration_test_permanent.endpoint' , " http://${ minioAddress} "
292+ Closure<String > minioAddressAndPort = {
293+ assert startMinio. minioPort > 0
294+ return ' http://' + minioAddress + ' :' + startMinio. minioPort
295+ }
296+ cluster. setting ' s3.client.integration_test_permanent.endpoint' , " ${ -> minioAddressAndPort.call()} "
276297
277298 Task restIntegTestTask = project. tasks. getByName(' integTestMinio' )
278299 restIntegTestTask. clusterConfig. plugin(project. path)
0 commit comments