2121import java .io .IOException ;
2222import java .util .EnumSet ;
2323
24- import org .junit . Assume ;
24+ import org .assertj . core . api . Assertions ;
2525import org .junit .Test ;
2626
2727import org .apache .hadoop .fs .Path ;
@@ -46,45 +46,24 @@ public ITestAzureBlobFileSystemAttributes() throws Exception {
4646 public void testSetGetXAttr () throws Exception {
4747 AzureBlobFileSystem fs = getFileSystem ();
4848 AbfsConfiguration conf = fs .getAbfsStore ().getAbfsConfiguration ();
49- Assume .assumeTrue (getIsNamespaceEnabled (fs ));
50-
51- byte [] attributeValue1 = fs .getAbfsStore ().encodeAttribute ("hi" );
52- byte [] attributeValue2 = fs .getAbfsStore ().encodeAttribute ("你好" );
53- String attributeName1 = "user.asciiAttribute" ;
54- String attributeName2 = "user.unicodeAttribute" ;
55- Path testFile = path ("setGetXAttr" );
56-
57- // after creating a file, the xAttr should not be present
58- touch (testFile );
59- assertNull (fs .getXAttr (testFile , attributeName1 ));
60-
61- // after setting the xAttr on the file, the value should be retrievable
62- fs .registerListener (
63- new TracingHeaderValidator (conf .getClientCorrelationId (),
64- fs .getFileSystemId (), FSOperationType .SET_ATTR , true , 0 ));
65- fs .setXAttr (testFile , attributeName1 , attributeValue1 );
66- fs .setListenerOperation (FSOperationType .GET_ATTR );
67- assertArrayEquals (attributeValue1 , fs .getXAttr (testFile , attributeName1 ));
68- fs .registerListener (null );
69-
70- // after setting a second xAttr on the file, the first xAttr values should not be overwritten
71- fs .setXAttr (testFile , attributeName2 , attributeValue2 );
72- assertArrayEquals (attributeValue1 , fs .getXAttr (testFile , attributeName1 ));
73- assertArrayEquals (attributeValue2 , fs .getXAttr (testFile , attributeName2 ));
49+ final Path testPath = path ("setGetXAttr" );
50+ fs .create (testPath );
51+ testGetSetXAttrHelper (fs , testPath );
7452 }
7553
7654 @ Test
7755 public void testSetGetXAttrCreateReplace () throws Exception {
7856 AzureBlobFileSystem fs = getFileSystem ();
79- Assume .assumeTrue (getIsNamespaceEnabled (fs ));
8057 byte [] attributeValue = fs .getAbfsStore ().encodeAttribute ("one" );
8158 String attributeName = "user.someAttribute" ;
8259 Path testFile = path ("createReplaceXAttr" );
8360
8461 // after creating a file, it must be possible to create a new xAttr
8562 touch (testFile );
8663 fs .setXAttr (testFile , attributeName , attributeValue , CREATE_FLAG );
87- assertArrayEquals (attributeValue , fs .getXAttr (testFile , attributeName ));
64+ Assertions .assertThat (fs .getXAttr (testFile , attributeName ))
65+ .describedAs ("Retrieved Attribute Value is Not as Expected" )
66+ .containsExactly (attributeValue );
8867
8968 // however after the xAttr is created, creating it again must fail
9069 intercept (IOException .class , () -> fs .setXAttr (testFile , attributeName , attributeValue , CREATE_FLAG ));
@@ -93,7 +72,6 @@ public void testSetGetXAttrCreateReplace() throws Exception {
9372 @ Test
9473 public void testSetGetXAttrReplace () throws Exception {
9574 AzureBlobFileSystem fs = getFileSystem ();
96- Assume .assumeTrue (getIsNamespaceEnabled (fs ));
9775 byte [] attributeValue1 = fs .getAbfsStore ().encodeAttribute ("one" );
9876 byte [] attributeValue2 = fs .getAbfsStore ().encodeAttribute ("two" );
9977 String attributeName = "user.someAttribute" ;
@@ -108,6 +86,72 @@ public void testSetGetXAttrReplace() throws Exception {
10886 // however after the xAttr is created, replacing it must succeed
10987 fs .setXAttr (testFile , attributeName , attributeValue1 , CREATE_FLAG );
11088 fs .setXAttr (testFile , attributeName , attributeValue2 , REPLACE_FLAG );
111- assertArrayEquals (attributeValue2 , fs .getXAttr (testFile , attributeName ));
89+ Assertions .assertThat (fs .getXAttr (testFile , attributeName ))
90+ .describedAs ("Retrieved Attribute Value is Not as Expected" )
91+ .containsExactly (attributeValue2 );
92+ }
93+
94+ @ Test
95+ public void testGetSetXAttrOnRoot () throws Exception {
96+ AzureBlobFileSystem fs = getFileSystem ();
97+ final Path testPath = new Path ("/" );
98+ testGetSetXAttrHelper (fs , testPath );
99+ }
100+
101+ private void testGetSetXAttrHelper (final AzureBlobFileSystem fs ,
102+ final Path testPath ) throws Exception {
103+
104+ String attributeName1 = "user.attribute1" ;
105+ String attributeName2 = "user.attribute2" ;
106+ String decodedAttributeValue1 = "hi" ;
107+ String decodedAttributeValue2 = "hello" ;
108+ byte [] attributeValue1 = fs .getAbfsStore ().encodeAttribute (decodedAttributeValue1 );
109+ byte [] attributeValue2 = fs .getAbfsStore ().encodeAttribute (decodedAttributeValue2 );
110+
111+ // Attribute not present initially
112+ Assertions .assertThat (fs .getXAttr (testPath , attributeName1 ))
113+ .describedAs ("Cannot get attribute before setting it" )
114+ .isNull ();
115+ Assertions .assertThat (fs .getXAttr (testPath , attributeName2 ))
116+ .describedAs ("Cannot get attribute before setting it" )
117+ .isNull ();
118+
119+ // Set the Attributes
120+ fs .registerListener (
121+ new TracingHeaderValidator (fs .getAbfsStore ().getAbfsConfiguration ()
122+ .getClientCorrelationId (),
123+ fs .getFileSystemId (), FSOperationType .SET_ATTR , true , 0 ));
124+ fs .setXAttr (testPath , attributeName1 , attributeValue1 );
125+
126+ // Check if the attribute is retrievable
127+ fs .setListenerOperation (FSOperationType .GET_ATTR );
128+ byte [] rv = fs .getXAttr (testPath , attributeName1 );
129+ Assertions .assertThat (rv )
130+ .describedAs ("Retrieved Attribute Does not Matches in Encoded Form" )
131+ .containsExactly (attributeValue1 );
132+ Assertions .assertThat (fs .getAbfsStore ().decodeAttribute (rv ))
133+ .describedAs ("Retrieved Attribute Does not Matches in Decoded Form" )
134+ .isEqualTo (decodedAttributeValue1 );
135+ fs .registerListener (null );
136+
137+ // Set the second Attribute
138+ fs .setXAttr (testPath , attributeName2 , attributeValue2 );
139+
140+ // Check all the attributes present and previous Attribute not overridden
141+ rv = fs .getXAttr (testPath , attributeName1 );
142+ Assertions .assertThat (rv )
143+ .describedAs ("Retrieved Attribute Does not Matches in Encoded Form" )
144+ .containsExactly (attributeValue1 );
145+ Assertions .assertThat (fs .getAbfsStore ().decodeAttribute (rv ))
146+ .describedAs ("Retrieved Attribute Does not Matches in Decoded Form" )
147+ .isEqualTo (decodedAttributeValue1 );
148+
149+ rv = fs .getXAttr (testPath , attributeName2 );
150+ Assertions .assertThat (rv )
151+ .describedAs ("Retrieved Attribute Does not Matches in Encoded Form" )
152+ .containsExactly (attributeValue2 );
153+ Assertions .assertThat (fs .getAbfsStore ().decodeAttribute (rv ))
154+ .describedAs ("Retrieved Attribute Does not Matches in Decoded Form" )
155+ .isEqualTo (decodedAttributeValue2 );
112156 }
113157}
0 commit comments