示例#1
0
  @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);
      }
    }
  }
示例#2
0
  @Test
  public void testCreateDirWithEmptyPathComponents() throws Exception {
    VOLUME_NAME = "testCreateDirWithEmptyPathComponents";
    // Both directories should be created under "/"
    final String DIR1 = "/test";
    final String DIR2 = "/test//";
    final String DIR3 = "/test//testdir";

    // create volume
    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);

    // create some files and directories
    try {
      volume.createDirectory(userCredentials, DIR1, 0755);
      volume.createDirectory(userCredentials, DIR3, 0755);
    } catch (IOException ioe) {
      fail("failed to create testdirs");
    }

    try {
      volume.createDirectory(userCredentials, DIR2, 0755);
      fail("existing directory could be created");
    } catch (IOException ioe) {
    }

    // test 'readDir' and 'stat'
    DirectoryEntries entrySet = null;

    entrySet = volume.readDir(userCredentials, DIR2, 0, 1000, false);
    assertEquals(3, entrySet.getEntriesCount());
    assertEquals("..", entrySet.getEntries(0).getName());
    assertEquals(".", entrySet.getEntries(1).getName());
    assertEquals("/testdir", "/" + entrySet.getEntries(2).getName());

    entrySet = volume.readDir(userCredentials, DIR3, 0, 1000, false);
    assertEquals(2, entrySet.getEntriesCount());

    volume.removeDirectory(userCredentials, DIR3);
    entrySet = volume.readDir(userCredentials, DIR1, 0, 1000, false);
    assertEquals(2, entrySet.getEntriesCount());
  }
示例#3
0
  @Test
  public void testReadDirMultipleChunks() throws Exception {
    options.setReaddirChunkSize(2);

    VOLUME_NAME = "testReadDirMultipleChunks";
    final String TESTFILE = "test";
    final int fileCount = 10;

    // create volume
    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);

    // create some files
    for (int i = 0; i < fileCount; i++) {
      FileHandle fh =
          volume.openFile(
              userCredentials,
              "/" + TESTFILE + i,
              SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fh.close();
    }

    // test 'readDir' across multiple readDir chunks.
    DirectoryEntries entrySet = null;

    entrySet = volume.readDir(userCredentials, "/", 0, 1000, false);
    assertEquals(2 + fileCount, entrySet.getEntriesCount());
    assertEquals("..", entrySet.getEntries(0).getName());
    assertEquals(".", entrySet.getEntries(1).getName());
    for (int i = 0; i < fileCount; i++) {
      assertEquals(TESTFILE + i, entrySet.getEntries(2 + i).getName());
    }
  }
示例#4
0
  @Test
  public void testHardLink() throws Exception {
    VOLUME_NAME = "testHardLink";
    final String ORIG_FILE = "test.txt";
    final String LINKED_FILE = "test-link.txt";
    final String LINKED_FILE2 = "test-link2.txt";

    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>());

    // create file
    openResponse open = null;
    RPCResponse<openResponse> resp = null;
    try {
      resp =
          mrcClient.open(
              testEnv.getMRCAddress(),
              auth,
              userCredentials,
              VOLUME_NAME,
              ORIG_FILE,
              FileAccessManager.O_CREAT,
              0,
              0777,
              defaultCoordinates);
      open = resp.get();
    } finally {
      if (resp != null) {
        resp.freeBuffers();
      }
    }
    assertNotNull(open);

    // create link
    Volume volume = client.openVolume(VOLUME_NAME, null, options);
    volume.link(userCredentials, ORIG_FILE, LINKED_FILE);

    open = null;
    resp = null;
    try {
      resp =
          mrcClient.open(
              testEnv.getMRCAddress(),
              auth,
              userCredentials,
              VOLUME_NAME,
              "test-hardlink.txt",
              FileAccessManager.O_CREAT,
              0,
              0,
              defaultCoordinates);
      open = resp.get();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp != null) {
        resp.freeBuffers();
      }
    }
    assertNotNull(open);

    // check whether both filenames refer to the same file
    Stat stat1 = null;
    Stat stat2 = null;
    RPCResponse<getattrResponse> resp1 = null;
    RPCResponse<getattrResponse> resp2 = null;
    try {
      resp1 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, ORIG_FILE, 0);
      stat1 = resp1.get().getStbuf();

      resp2 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE, 0);
      stat2 = resp2.get().getStbuf();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp1 != null) {
        resp1.freeBuffers();
      }
      if (resp2 != null) {
        resp.freeBuffers();
      }
    }
    assertNotNull(stat1);
    assertNotNull(stat2);

    assertEquals(stat1.getIno(), stat1.getIno());
    assertEquals(2, stat1.getNlink());

    // create another link to the second file
    volume.link(userCredentials, LINKED_FILE, LINKED_FILE2);

    // check whether both links refer to the same file
    stat1 = null;
    stat2 = null;
    resp1 = null;
    resp2 = null;
    try {
      resp1 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE, 0);
      stat1 = resp1.get().getStbuf();

      resp2 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE2, 0);
      stat2 = resp2.get().getStbuf();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp1 != null) {
        resp1.freeBuffers();
      }
      if (resp2 != null) {
        resp2.freeBuffers();
      }
    }
    assertEquals(stat1.getIno(), stat2.getIno());
    assertEquals(3, stat1.getNlink());

    // delete one of the links
    volume.unlink(userCredentials, LINKED_FILE);

    // check whether remaining links refer to the same file
    stat1 = null;
    stat2 = null;
    resp1 = null;
    resp2 = null;
    try {
      resp1 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, ORIG_FILE, 0);
      stat1 = resp1.get().getStbuf();

      resp2 =
          mrcClient.getattr(
              testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE2, 0);
      stat2 = resp2.get().getStbuf();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp1 != null) {
        resp1.freeBuffers();
      }
      if (resp2 != null) {
        resp2.freeBuffers();
      }
    }
    assertEquals(stat1.getIno(), stat2.getIno());
    assertEquals(2, stat1.getNlink());

    // delete the other two links
    volume.unlink(userCredentials, ORIG_FILE);
    volume.unlink(userCredentials, LINKED_FILE2);

    try {
      mrcClient
          .getattr(testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, LINKED_FILE2, 0)
          .get();
      fail("file should not exist anymore");
    } catch (Exception exc) {
    }

    try {
      mrcClient
          .getattr(testEnv.getMRCAddress(), auth, userCredentials, VOLUME_NAME, ORIG_FILE, 0)
          .get();
      fail("file should not exist anymore");
    } catch (Exception exc) {
    }

    //
    // // create two links to a directory
    // invokeSync(client.mkdir(mrcAddress, RPCAuthentication.authNone, uc,
    // volumeName, "testDir1", 0));
    // try {
    // invokeSync(client.link(mrcAddress, RPCAuthentication.authNone, uc,
    // volumeName, "testDir1",
    // "testDir1/testDir2"));
    // fail("links to directories should not be allowed");
    // } catch (Exception exc) {
    // }
    // }
    //
  }
示例#5
0
  @Test
  public void testCreateDelete() throws Exception {
    VOLUME_NAME = "testCreateDelete";
    // Both directories should be created under "/"
    final String DIR1 = "/testdir1";
    final String DIR2 = "testdir2";

    final String TESTFILE = "testfile";
    // create volume
    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);

    // create some files and directories
    try {
      volume.createDirectory(userCredentials, DIR1, 0755);
      volume.createDirectory(userCredentials, DIR2, 0755);
    } catch (IOException ioe) {
      fail("failed to create testdirs");
    }

    for (int i = 0; i < 10; i++) {
      FileHandle fh =
          volume.openFile(
              userCredentials,
              DIR1 + "/" + TESTFILE + i,
              SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fh.close();
    }

    // // try to create a file w/o a name
    try {
      volume.openFile(userCredentials, "", SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("missing filename");
    } catch (Exception e) {
    }

    // try to create an already existing file
    try {
      volume.openFile(
          userCredentials,
          DIR1 + "/" + TESTFILE + "1",
          SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_EXCL.getNumber()
              | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("file already exists");
    } catch (Exception e) {
    }

    // file in file creation should fail
    try {
      volume.openFile(
          userCredentials,
          DIR1 + "/" + TESTFILE + "1/foo.txt",
          SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("file in file creation");
    } catch (Exception e) {
    }

    // should fail
    try {
      volume.createDirectory(userCredentials, "/", 0);
      fail("directory already exists");
    } catch (PosixErrorException exc) {
    }

    // test 'readDir' and 'stat'
    DirectoryEntries entrySet = null;

    entrySet = volume.readDir(userCredentials, "", 0, 1000, false);
    assertEquals(4, entrySet.getEntriesCount());
    assertEquals("..", entrySet.getEntries(0).getName());
    assertEquals(".", entrySet.getEntries(1).getName());
    assertEquals(DIR1, "/" + entrySet.getEntries(2).getName());
    assertEquals("/" + DIR2, "/" + entrySet.getEntries(3).getName());

    entrySet = volume.readDir(userCredentials, DIR1, 0, 1000, false);
    assertEquals(12, entrySet.getEntriesCount());

    // test 'delete'
    volume.unlink(userCredentials, DIR1 + "/" + TESTFILE + "4");
    entrySet = volume.readDir(userCredentials, DIR1, 0, 1000, false);
    assertEquals(11, entrySet.getEntriesCount());

    volume.removeDirectory(userCredentials, DIR2);
    entrySet = volume.readDir(userCredentials, "", 0, 1000, false);
    assertEquals(3, entrySet.getEntriesCount());
  }