Ejemplo n.º 1
0
  @Test
  public void testStatVFS() throws Exception, VolumeNotFoundException {
    final String VOLUME_NAME_1 = "foobar";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME_1);

    Volume volume = client.openVolume(VOLUME_NAME_1, null, options);

    StatVFS volumeVFS = volume.statFS(userCredentials);

    MRCServiceClient mrcClient = new MRCServiceClient(testEnv.getRpcClient(), null);

    StatVFS mrcClientVFS = null;
    RPCResponse<StatVFS> resp = null;
    try {
      statvfsRequest input =
          statvfsRequest.newBuilder().setVolumeName(VOLUME_NAME_1).setKnownEtag(0).build();
      resp = mrcClient.statvfs(testEnv.getMRCAddress(), auth, userCredentials, input);
      mrcClientVFS = resp.get();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (resp != null) {
        resp.freeBuffers();
      }
    }
    assertNotNull(volumeVFS);
    assertEquals(mrcClientVFS, volumeVFS);
  }
Ejemplo n.º 2
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) {
    // }
    // }
    //
  }