From 97bee01bba5e3c6e589b56594733234045a31b21 Mon Sep 17 00:00:00 2001 From: Dionysios Stolis Date: Wed, 14 Oct 2026 11:10:55 +0200 Subject: [PATCH] [test] Avoid network retries in AzureFileSystemPluginTest --- .../fs/azure/AzureFileSystemPluginTest.java | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/fluss-filesystems/fluss-fs-azure/src/test/java/org/apache/fluss/fs/azure/AzureFileSystemPluginTest.java b/fluss-filesystems/fluss-fs-azure/src/test/java/org/apache/fluss/fs/azure/AzureFileSystemPluginTest.java index aa2b45f201d..bcfee7800e3 100644 --- a/fluss-filesystems/fluss-fs-azure/src/test/java/org/apache/fluss/fs/azure/AzureFileSystemPluginTest.java +++ b/fluss-filesystems/fluss-fs-azure/src/test/java/org/apache/fluss/fs/azure/AzureFileSystemPluginTest.java @@ -25,9 +25,9 @@ import org.junit.jupiter.api.Test; -import java.io.PrintWriter; -import java.io.StringWriter; import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.Base64; import java.util.HashMap; import java.util.Map; @@ -38,6 +38,16 @@ /** Tests for {@link AzureFileSystemPlugin}. */ public class AzureFileSystemPluginTest { + // Reserved TLD (RFC 2606) so the host is guaranteed to never resolve or be registered. + private static final String TEST_FS_URI = "abfs://container@account.dfs.core.windows.invalid/"; + + private static Configuration offlineConfig() { + Configuration flussConfig = new Configuration(); + flussConfig.setString("fs.azure.account.hns.enabled", "false"); + flussConfig.setString("fs.azure.io.retry.max.retries", "0"); + return flussConfig; + } + @Test void testGetHadoopConfiguration() { AzureFileSystemPlugin plugin = new AbfsFileSystemPlugin(); @@ -64,29 +74,20 @@ void testGetHadoopConfigurationNull() { @Test void testCreateWithAccountKey() throws Exception { AzureFileSystemPlugin plugin = new AbfsFileSystemPlugin(); - Configuration flussConfig = new Configuration(); - flussConfig.setString(ACCOUNT_KEY.key(), "some-key"); - - // This will try to initialize AzureBlobFileSystem which might fail in some environments - // but we want to check if it reaches the right logic. - // Actually, AzureBlobFileSystem.initialize might fail because it tries to parse the URI. - - URI uri = new URI("abfs://container@account.dfs.core.windows.net/"); - // We don't necessarily need to call create() if we can test the private methods or if they - // are called. - // Since they are private, we call create(). - - try { - plugin.create(uri, flussConfig); - } catch (Exception e) { - // expected or ignored, we just want coverage - } + Configuration flussConfig = offlineConfig(); + // ABFS requires the account key to be base64 encoded. + flussConfig.setString( + ACCOUNT_KEY.key(), + Base64.getEncoder().encodeToString("some-key".getBytes(StandardCharsets.UTF_8))); + + assertThat(plugin.create(new URI(TEST_FS_URI), flussConfig)) + .isInstanceOf(AzureFileSystem.class); } @Test void testCreateWithoutAccountKey() throws Exception { AzureFileSystemPlugin plugin = new AbfsFileSystemPlugin(); - Configuration flussConfig = new Configuration(); + Configuration flussConfig = offlineConfig(); // Prepare credentials so updateHadoopConfig doesn't throw IllegalStateException Credentials credentials = new Credentials("id", "secret", "token"); @@ -97,15 +98,8 @@ void testCreateWithoutAccountKey() throws Exception { "abfs", CredentialsJsonSerde.toJson(credentials), 100L, additionInfos); new AbfsDelegationTokenReceiver().onNewTokensObtained(token); - URI uri = new URI("abfs://container@account.dfs.core.windows.net/"); - try { - plugin.create(uri, flussConfig); - } catch (Exception e) { - // If the plugin creation fails, it must NOT fail with an "init configuration" error. - StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); - assertThat(sw.toString()).doesNotContain("Failure to initialize configuration"); - } + assertThat(plugin.create(new URI(TEST_FS_URI), flussConfig)) + .isInstanceOf(AzureFileSystem.class); } @Test