@Test
  public void testBackReference() {
    Path rootDir = new Path("/root");
    Path archiveDir = new Path(rootDir, ".archive");
    String storeFileName = "121212";
    String linkDir = FileLink.BACK_REFERENCES_DIRECTORY_PREFIX + storeFileName;
    String encodedRegion = "FEFE";
    String cf = "cf1";

    TableName refTables[] =
      { TableName.valueOf(name.getMethodName()), TableName.valueOf("ns", name.getMethodName()) };

    for (TableName refTable : refTables) {
      Path refTableDir = CommonFSUtils.getTableDir(archiveDir, refTable);
      Path refRegionDir = HRegion.getRegionDir(refTableDir, encodedRegion);
      Path refDir = new Path(refRegionDir, cf);
      Path refLinkDir = new Path(refDir, linkDir);
      String refStoreFileName = refTable.getNameAsString().replace(TableName.NAMESPACE_DELIM, '=')
        + "=" + encodedRegion + "-" + storeFileName;

      TableName tableNames[] = { TableName.valueOf(name.getMethodName() + "1"),
        TableName.valueOf("ns", name.getMethodName() + "2"),
        TableName.valueOf(name.getMethodName() + ":" + name.getMethodName()) };

      for (TableName tableName : tableNames) {
        Path tableDir = CommonFSUtils.getTableDir(rootDir, tableName);
        Path regionDir = HRegion.getRegionDir(tableDir, encodedRegion);
        Path cfDir = new Path(regionDir, cf);

        // Verify back reference creation
        assertEquals(
          encodedRegion + "." + tableName.getNameAsString().replace(TableName.NAMESPACE_DELIM, '='),
          HFileLink.createBackReferenceName(CommonFSUtils.getTableName(tableDir).getNameAsString(),
            encodedRegion));

        // verify parsing back reference
        Pair<TableName, String> parsedRef = HFileLink.parseBackReferenceName(encodedRegion + "."
          + tableName.getNameAsString().replace(TableName.NAMESPACE_DELIM, '='));
        assertEquals(parsedRef.getFirst(), tableName);
        assertEquals(encodedRegion, parsedRef.getSecond());

        // verify resolving back reference
        Path storeFileDir = new Path(refLinkDir, encodedRegion + "."
          + tableName.getNameAsString().replace(TableName.NAMESPACE_DELIM, '='));
        Path linkPath = new Path(cfDir, refStoreFileName);
        assertEquals(linkPath, HFileLink.getHFileFromBackReference(rootDir, storeFileDir));
      }
    }
  }
Test that FileLink switches between alternate locations when the current location moves or gets
deleted.
hbase-server/src/test/java/org/apache/hadoop/hbase/io/TestHFileLink.java