Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand All @@ -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");
Expand All @@ -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
Expand Down
Loading