|
@@ -21,7 +21,7 @@ package org.apache.hadoop.fs.azurebfs;
|
|
|
import java.io.IOException;
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
-import org.junit.Assume;
|
|
|
+import org.assertj.core.api.Assertions;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import org.apache.hadoop.fs.Path;
|
|
@@ -46,37 +46,14 @@ public class ITestAzureBlobFileSystemAttributes extends AbstractAbfsIntegrationT
|
|
|
public void testSetGetXAttr() throws Exception {
|
|
|
AzureBlobFileSystem fs = getFileSystem();
|
|
|
AbfsConfiguration conf = fs.getAbfsStore().getAbfsConfiguration();
|
|
|
- Assume.assumeTrue(getIsNamespaceEnabled(fs));
|
|
|
-
|
|
|
- byte[] attributeValue1 = fs.getAbfsStore().encodeAttribute("hi");
|
|
|
- byte[] attributeValue2 = fs.getAbfsStore().encodeAttribute("你好");
|
|
|
- String attributeName1 = "user.asciiAttribute";
|
|
|
- String attributeName2 = "user.unicodeAttribute";
|
|
|
- Path testFile = path("setGetXAttr");
|
|
|
-
|
|
|
- // after creating a file, the xAttr should not be present
|
|
|
- touch(testFile);
|
|
|
- assertNull(fs.getXAttr(testFile, attributeName1));
|
|
|
-
|
|
|
- // after setting the xAttr on the file, the value should be retrievable
|
|
|
- fs.registerListener(
|
|
|
- new TracingHeaderValidator(conf.getClientCorrelationId(),
|
|
|
- fs.getFileSystemId(), FSOperationType.SET_ATTR, true, 0));
|
|
|
- fs.setXAttr(testFile, attributeName1, attributeValue1);
|
|
|
- fs.setListenerOperation(FSOperationType.GET_ATTR);
|
|
|
- assertArrayEquals(attributeValue1, fs.getXAttr(testFile, attributeName1));
|
|
|
- fs.registerListener(null);
|
|
|
-
|
|
|
- // after setting a second xAttr on the file, the first xAttr values should not be overwritten
|
|
|
- fs.setXAttr(testFile, attributeName2, attributeValue2);
|
|
|
- assertArrayEquals(attributeValue1, fs.getXAttr(testFile, attributeName1));
|
|
|
- assertArrayEquals(attributeValue2, fs.getXAttr(testFile, attributeName2));
|
|
|
+ final Path testPath = path("setGetXAttr");
|
|
|
+ fs.create(testPath);
|
|
|
+ testGetSetXAttrHelper(fs, testPath);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testSetGetXAttrCreateReplace() throws Exception {
|
|
|
AzureBlobFileSystem fs = getFileSystem();
|
|
|
- Assume.assumeTrue(getIsNamespaceEnabled(fs));
|
|
|
byte[] attributeValue = fs.getAbfsStore().encodeAttribute("one");
|
|
|
String attributeName = "user.someAttribute";
|
|
|
Path testFile = path("createReplaceXAttr");
|
|
@@ -84,7 +61,9 @@ public class ITestAzureBlobFileSystemAttributes extends AbstractAbfsIntegrationT
|
|
|
// after creating a file, it must be possible to create a new xAttr
|
|
|
touch(testFile);
|
|
|
fs.setXAttr(testFile, attributeName, attributeValue, CREATE_FLAG);
|
|
|
- assertArrayEquals(attributeValue, fs.getXAttr(testFile, attributeName));
|
|
|
+ Assertions.assertThat(fs.getXAttr(testFile, attributeName))
|
|
|
+ .describedAs("Retrieved Attribute Value is Not as Expected")
|
|
|
+ .containsExactly(attributeValue);
|
|
|
|
|
|
// however after the xAttr is created, creating it again must fail
|
|
|
intercept(IOException.class, () -> fs.setXAttr(testFile, attributeName, attributeValue, CREATE_FLAG));
|
|
@@ -93,7 +72,6 @@ public class ITestAzureBlobFileSystemAttributes extends AbstractAbfsIntegrationT
|
|
|
@Test
|
|
|
public void testSetGetXAttrReplace() throws Exception {
|
|
|
AzureBlobFileSystem fs = getFileSystem();
|
|
|
- Assume.assumeTrue(getIsNamespaceEnabled(fs));
|
|
|
byte[] attributeValue1 = fs.getAbfsStore().encodeAttribute("one");
|
|
|
byte[] attributeValue2 = fs.getAbfsStore().encodeAttribute("two");
|
|
|
String attributeName = "user.someAttribute";
|
|
@@ -108,6 +86,72 @@ public class ITestAzureBlobFileSystemAttributes extends AbstractAbfsIntegrationT
|
|
|
// however after the xAttr is created, replacing it must succeed
|
|
|
fs.setXAttr(testFile, attributeName, attributeValue1, CREATE_FLAG);
|
|
|
fs.setXAttr(testFile, attributeName, attributeValue2, REPLACE_FLAG);
|
|
|
- assertArrayEquals(attributeValue2, fs.getXAttr(testFile, attributeName));
|
|
|
+ Assertions.assertThat(fs.getXAttr(testFile, attributeName))
|
|
|
+ .describedAs("Retrieved Attribute Value is Not as Expected")
|
|
|
+ .containsExactly(attributeValue2);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetSetXAttrOnRoot() throws Exception {
|
|
|
+ AzureBlobFileSystem fs = getFileSystem();
|
|
|
+ final Path testPath = new Path("/");
|
|
|
+ testGetSetXAttrHelper(fs, testPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void testGetSetXAttrHelper(final AzureBlobFileSystem fs,
|
|
|
+ final Path testPath) throws Exception {
|
|
|
+
|
|
|
+ String attributeName1 = "user.attribute1";
|
|
|
+ String attributeName2 = "user.attribute2";
|
|
|
+ String decodedAttributeValue1 = "hi";
|
|
|
+ String decodedAttributeValue2 = "hello";
|
|
|
+ byte[] attributeValue1 = fs.getAbfsStore().encodeAttribute(decodedAttributeValue1);
|
|
|
+ byte[] attributeValue2 = fs.getAbfsStore().encodeAttribute(decodedAttributeValue2);
|
|
|
+
|
|
|
+ // Attribute not present initially
|
|
|
+ Assertions.assertThat(fs.getXAttr(testPath, attributeName1))
|
|
|
+ .describedAs("Cannot get attribute before setting it")
|
|
|
+ .isNull();
|
|
|
+ Assertions.assertThat(fs.getXAttr(testPath, attributeName2))
|
|
|
+ .describedAs("Cannot get attribute before setting it")
|
|
|
+ .isNull();
|
|
|
+
|
|
|
+ // Set the Attributes
|
|
|
+ fs.registerListener(
|
|
|
+ new TracingHeaderValidator(fs.getAbfsStore().getAbfsConfiguration()
|
|
|
+ .getClientCorrelationId(),
|
|
|
+ fs.getFileSystemId(), FSOperationType.SET_ATTR, true, 0));
|
|
|
+ fs.setXAttr(testPath, attributeName1, attributeValue1);
|
|
|
+
|
|
|
+ // Check if the attribute is retrievable
|
|
|
+ fs.setListenerOperation(FSOperationType.GET_ATTR);
|
|
|
+ byte[] rv = fs.getXAttr(testPath, attributeName1);
|
|
|
+ Assertions.assertThat(rv)
|
|
|
+ .describedAs("Retrieved Attribute Does not Matches in Encoded Form")
|
|
|
+ .containsExactly(attributeValue1);
|
|
|
+ Assertions.assertThat(fs.getAbfsStore().decodeAttribute(rv))
|
|
|
+ .describedAs("Retrieved Attribute Does not Matches in Decoded Form")
|
|
|
+ .isEqualTo(decodedAttributeValue1);
|
|
|
+ fs.registerListener(null);
|
|
|
+
|
|
|
+ // Set the second Attribute
|
|
|
+ fs.setXAttr(testPath, attributeName2, attributeValue2);
|
|
|
+
|
|
|
+ // Check all the attributes present and previous Attribute not overridden
|
|
|
+ rv = fs.getXAttr(testPath, attributeName1);
|
|
|
+ Assertions.assertThat(rv)
|
|
|
+ .describedAs("Retrieved Attribute Does not Matches in Encoded Form")
|
|
|
+ .containsExactly(attributeValue1);
|
|
|
+ Assertions.assertThat(fs.getAbfsStore().decodeAttribute(rv))
|
|
|
+ .describedAs("Retrieved Attribute Does not Matches in Decoded Form")
|
|
|
+ .isEqualTo(decodedAttributeValue1);
|
|
|
+
|
|
|
+ rv = fs.getXAttr(testPath, attributeName2);
|
|
|
+ Assertions.assertThat(rv)
|
|
|
+ .describedAs("Retrieved Attribute Does not Matches in Encoded Form")
|
|
|
+ .containsExactly(attributeValue2);
|
|
|
+ Assertions.assertThat(fs.getAbfsStore().decodeAttribute(rv))
|
|
|
+ .describedAs("Retrieved Attribute Does not Matches in Decoded Form")
|
|
|
+ .isEqualTo(decodedAttributeValue2);
|
|
|
}
|
|
|
}
|