This is an automated email from the ASF dual-hosted git repository.
nastra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new 85e22de10c Aliyun: Default random port for OSS mock server (#18249)
85e22de10c is described below
commit 85e22de10c0ac65565384e1ab5c0a2afff0b3885
Author: Hongyue/Steve Zhang <[email protected]>
AuthorDate: Thu Oct 1 00:32:07 2026 -0700
Aliyun: Default random port for OSS mock server (#18249)
AliyunOSSMock defaulted to the fixed port 9393, so running the aliyun
tests with more than one test fork made concurrent JVMs fight over the
same port. With -DtestParallelism=8, five of the eight test classes in
the module failed in beforeAll with "Can't start OSS Mock".
Default server.port to 0 and read the actual port back off the started
server, the same approach used in #6895 and #6959. An explicitly
configured server.port is still honoured.
Two related fork-safety problems in the same path:
- The BindException cause was discarded when wrapping the failure, which
is why the collision surfaced as a bare "Can't start OSS Mock" with no
indication that a port was at fault.
- The mock's store directory was named with System.currentTimeMillis(),
so two forks starting in the same millisecond shared a store and
deleted each other's objects during bucket teardown. Use a UUID.
Generated-by: Claude Code
---
.../org/apache/iceberg/aliyun/oss/mock/AliyunOSSMock.java | 6 +++++-
.../iceberg/aliyun/oss/mock/AliyunOSSMockExtension.java | 13 +++++--------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git
a/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/AliyunOSSMock.java
b/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/AliyunOSSMock.java
index 7894c1857d..cd5fdf46fe 100644
--- a/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/AliyunOSSMock.java
+++ b/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/AliyunOSSMock.java
@@ -43,7 +43,7 @@ public class AliyunOSSMock {
static final String ROOT_DIR_DEFAULT = "/tmp";
static final String PROP_HTTP_PORT = "server.port";
- static final int PORT_HTTP_PORT_DEFAULT = 9393;
+ static final int PORT_HTTP_PORT_DEFAULT = 0;
private final AliyunOSSMockLocalStore localStore;
private final HttpServer httpServer;
@@ -63,6 +63,10 @@ public class AliyunOSSMock {
httpServer = HttpServer.create(new InetSocketAddress("localhost",
serverPort), 0);
}
+ int port() {
+ return httpServer.getAddress().getPort();
+ }
+
private void start() {
httpServer.createContext("/", new AliyunHttpHandler());
httpServer.start();
diff --git
a/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/AliyunOSSMockExtension.java
b/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/AliyunOSSMockExtension.java
index d4cb106150..67303482c3 100644
---
a/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/AliyunOSSMockExtension.java
+++
b/aliyun/src/test/java/org/apache/iceberg/aliyun/oss/mock/AliyunOSSMockExtension.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.util.Map;
+import java.util.UUID;
import org.apache.iceberg.aliyun.oss.AliyunOSSExtension;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.base.Strings;
@@ -54,7 +55,7 @@ public class AliyunOSSMockExtension implements
AliyunOSSExtension {
try {
ossMock = AliyunOSSMock.start(properties);
} catch (Exception e) {
- throw new RuntimeException("Can't start OSS Mock");
+ throw new RuntimeException("Can't start OSS Mock", e);
}
}
@@ -65,11 +66,8 @@ public class AliyunOSSMockExtension implements
AliyunOSSExtension {
@Override
public OSS createOSSClient() {
- String endpoint =
- String.format(
- "http://localhost:%s",
- properties.getOrDefault(
- AliyunOSSMock.PROP_HTTP_PORT,
AliyunOSSMock.PORT_HTTP_PORT_DEFAULT));
+ Preconditions.checkState(null != ossMock, "OSS Mock must be started before
creating a client");
+ String endpoint = String.format("http://localhost:%d", ossMock.port());
return new OSSClientBuilder().build(endpoint, "foo", "bar");
}
@@ -112,8 +110,7 @@ public class AliyunOSSMockExtension implements
AliyunOSSExtension {
if (Strings.isNullOrEmpty(rootDir)) {
File dir =
new File(
- System.getProperty("java.io.tmpdir"),
- "oss-mock-file-store-" + System.currentTimeMillis());
+ System.getProperty("java.io.tmpdir"), "oss-mock-file-store-" +
UUID.randomUUID());
rootDir = dir.getAbsolutePath();
props.put(AliyunOSSMock.PROP_ROOT_DIR, rootDir);
}