Beispiel #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);
  }
Beispiel #2
0
  @AfterClass
  public static void shutdownTest() throws Exception {
    for (int i = 0; i < osds.length; i++) {
      if (osds[i] != null) {
        osds[i].shutdown();
      }
    }

    testEnv.shutdown();
    dir.shutdown();
    dir.waitForShutdown();

    client.shutdown();
  }
Beispiel #3
0
  @BeforeClass
  public static void initializeTest() throws Exception {
    FSUtils.delTree(new java.io.File(SetupUtils.TEST_DIR));

    Logging.start(SetupUtils.DEBUG_LEVEL, SetupUtils.DEBUG_CATEGORIES);

    dirConfig = SetupUtils.createDIRConfig();
    dir = new DIRRequestDispatcher(dirConfig, SetupUtils.createDIRdbsConfig());
    dir.startup();
    dir.waitForStartup();

    testEnv =
        new TestEnvironment(
            new TestEnvironment.Services[] {
              TestEnvironment.Services.DIR_CLIENT,
              TestEnvironment.Services.TIME_SYNC,
              TestEnvironment.Services.RPC_CLIENT,
              TestEnvironment.Services.MRC
            });
    testEnv.start();

    userCredentials = UserCredentials.newBuilder().setUsername("test").addGroups("test").build();

    dirAddress = testEnv.getDIRAddress().getHostName() + ":" + testEnv.getDIRAddress().getPort();
    mrcAddress = testEnv.getMRCAddress().getHostName() + ":" + testEnv.getMRCAddress().getPort();

    defaultCoordinates =
        VivaldiCoordinates.newBuilder()
            .setXCoordinate(0)
            .setYCoordinate(0)
            .setLocalError(0)
            .build();
    defaultStripingPolicy =
        StripingPolicy.newBuilder()
            .setType(StripingPolicyType.STRIPING_POLICY_RAID0)
            .setStripeSize(128)
            .setWidth(1)
            .build();

    osds = new OSD[4];
    configs = SetupUtils.createMultipleOSDConfigs(4);

    // start three OSDs
    osds[0] = new OSD(configs[0]);
    osds[1] = new OSD(configs[1]);
    osds[2] = new OSD(configs[2]);
    osds[3] = new OSD(configs[3]);

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

    options = new Options();
    client = ClientFactory.createClient(dirAddress, userCredentials, null, options);
    client.start();
  }
Beispiel #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) {
    // }
    // }
    //
  }