@Test
public void testINodeXAttrsLimit() throws Exception {

  List<XAttr> existingXAttrs = Lists.newArrayListWithCapacity(2);
  XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).
      setName("a1").setValue(new byte[]{0x31, 0x32, 0x33}).build();
  XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).
      setName("a2").setValue(new byte[]{0x31, 0x31, 0x31}).build();
  existingXAttrs.add(xAttr1);
  existingXAttrs.add(xAttr2);
  
  // Adding system and raw namespace xAttrs aren't affected by inode
  // xAttrs limit.
  XAttr newSystemXAttr = (new XAttr.Builder()).
      setNameSpace(XAttr.NameSpace.SYSTEM).setName("a3").
      setValue(new byte[]{0x33, 0x33, 0x33}).build();
  XAttr newRawXAttr = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.RAW).
      setName("a3").setValue(new byte[]{0x33, 0x33, 0x33}).build();
  List<XAttr> newXAttrs = Lists.newArrayListWithCapacity(2);
  newXAttrs.add(newSystemXAttr);
  newXAttrs.add(newRawXAttr);
  List<XAttr> xAttrs = fsdir.setINodeXAttrs(existingXAttrs, newXAttrs,
      EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE));
  assertEquals(xAttrs.size(), 4);
  
  // Adding a trusted namespace xAttr, is affected by inode xAttrs limit.
  XAttr newXAttr1 = (new XAttr.Builder()).setNameSpace(
      XAttr.NameSpace.TRUSTED).setName("a4").
      setValue(new byte[]{0x34, 0x34, 0x34}).build();
  newXAttrs.set(0, newXAttr1);
  try {
    fsdir.setINodeXAttrs(existingXAttrs, newXAttrs,
        EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE));
    fail("Setting user visible xattr on inode should fail if " +
        "reaching limit.");
  } catch (IOException e) {
    GenericTestUtils.assertExceptionContains("Cannot add additional XAttr " +
        "to inode, would exceed limit", e);
  }
}