Skip to content

Commit 6f59bf2

Browse files
committed
Fix potential issue in hdfs cluster when
- using in parallel - using with weired Locale settings
1 parent 749e814 commit 6f59bf2

File tree

1 file changed

+17
-4
lines changed
  • test/fixtures/hdfs-fixture/src/main/java/org/elasticsearch/test/fixtures/hdfs

1 file changed

+17
-4
lines changed

test/fixtures/hdfs-fixture/src/main/java/org/elasticsearch/test/fixtures/hdfs/HdfsFixture.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252
import java.security.PrivilegedExceptionAction;
5353
import java.util.ArrayList;
5454
import java.util.List;
55+
import java.util.Locale;
5556
import java.util.function.Supplier;
5657

5758
public class HdfsFixture extends ExternalResource {
5859

5960
private static final Logger LOGGER = LoggerFactory.getLogger(HdfsFixture.class);
61+
private static final Object STATIC_CONFIG_LOCK = new Object();
6062

6163
private TemporaryFolder temporaryFolder = new TemporaryFolder();
6264
private MiniDFSCluster dfs;
@@ -81,9 +83,20 @@ public HdfsFixture withKerberos(Supplier<String> principalConfig, Supplier<Path>
8183

8284
@Override
8385
protected void before() throws Throwable {
84-
temporaryFolder.create();
85-
assumeHdfsAvailable();
86-
startMinHdfs();
86+
// Save current locale and set to English for consistent HDFS startup behavior
87+
Locale originalLocale = Locale.getDefault();
88+
// Synchronize to prevent race conditions in concurrent test execution
89+
synchronized (STATIC_CONFIG_LOCK) {
90+
try {
91+
Locale.setDefault(Locale.ENGLISH);
92+
temporaryFolder.create();
93+
assumeHdfsAvailable();
94+
startMinHdfs();
95+
} finally {
96+
// Restore original locale
97+
Locale.setDefault(originalLocale);
98+
}
99+
}
87100
}
88101

89102
private void assumeHdfsAvailable() {
@@ -458,7 +471,7 @@ public void close() {
458471

459472
@SuppressWarnings({ "unchecked", "rawtypes" })
460473
public static void refreshKrb5Config() throws ClassNotFoundException, NoSuchMethodException, IllegalArgumentException,
461-
IllegalAccessException, InvocationTargetException, InvocationTargetException {
474+
IllegalAccessException, InvocationTargetException {
462475
Class classRef;
463476
if (System.getProperty("java.vendor").contains("IBM")) {
464477
classRef = Class.forName("com.ibm.security.krb5.internal.Config");

0 commit comments

Comments
 (0)