@Test public void testVolumeQuota() throws Exception { final String VOLUME_NAME = "testVolumeQuota"; client.createVolume( mrcAddress, auth, userCredentials, VOLUME_NAME, 0, userCredentials.getUsername(), userCredentials.getGroups(0), AccessControlPolicyType.ACCESS_CONTROL_POLICY_NULL, StripingPolicyType.STRIPING_POLICY_RAID0, defaultStripingPolicy.getStripeSize(), defaultStripingPolicy.getWidth(), new ArrayList<KeyValuePair>()); Volume volume = client.openVolume(VOLUME_NAME, null, options); volume.setXAttr(userCredentials, "/", "xtreemfs.quota", "8", XATTR_FLAGS.XATTR_FLAGS_CREATE); assertEquals("8", volume.getXAttr(userCredentials, "/", "xtreemfs.quota")); int flags = SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(); byte[] content = "foo foo foo".getBytes(); // 11 bytes will exceed quota FileHandle file = volume.openFile(userCredentials, "/test1.txt", flags, 0777); boolean osdWriteException = false; try { file.write(userCredentials, content, content.length, 0); } catch (Exception ex) { osdWriteException = true; } if (!osdWriteException) { fail("OSD performed write operation although it exceeds the quota."); } content = "foo bar ".getBytes(); // 8 bytes to fit quota perfectly file.write(userCredentials, content, content.length, 0); file.close(); try { file = volume.openFile(userCredentials, "/test2.txt", flags, 0777); assertTrue(false); } catch (PosixErrorException exc) { // check if right exception was thrown if (!exc.getMessage().contains("POSIX_ERROR_ENOSPC")) { assertTrue(false); } } }
private boolean isDirectory(Volume volume, String path) throws IOException { try { Stat stat = volume.getAttr(userCredentials, path); return (stat.getMode() & SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_S_IFDIR.getNumber()) > 0; } catch (PosixErrorException pee) { if (pee.getPosixError().equals(POSIXErrno.POSIX_ERROR_ENOENT)) { return false; } else { throw pee; } } }