@Test
  public void testValidLinkNames() {
    String validLinkNames[] = { "foo=fefefe-0123456", "ns=foo=abababa-fefefefe" };

    for (String name : validLinkNames) {
      Assert.assertTrue("Failed validating:" + name, name.matches(HFileLink.LINK_NAME_REGEX));
    }

    for (String name : validLinkNames) {
      Assert.assertTrue("Failed validating:" + name, HFileLink.isHFileLink(name));
    }

    String testName = name.getMethodName() + "=fefefe-0123456";
    Assert.assertEquals(TableName.valueOf(name.getMethodName()),
      HFileLink.getReferencedTableName(testName));
    Assert.assertEquals("fefefe", HFileLink.getReferencedRegionName(testName));
    Assert.assertEquals("0123456", HFileLink.getReferencedHFileName(testName));
    Assert.assertEquals(testName,
      HFileLink.createHFileLinkName(TableName.valueOf(name.getMethodName()), "fefefe", "0123456"));

    testName = "ns=" + name.getMethodName() + "=fefefe-0123456";
    Assert.assertEquals(TableName.valueOf("ns", name.getMethodName()),
      HFileLink.getReferencedTableName(testName));
    Assert.assertEquals("fefefe", HFileLink.getReferencedRegionName(testName));
    Assert.assertEquals("0123456", HFileLink.getReferencedHFileName(testName));
    Assert.assertEquals(testName, HFileLink
      .createHFileLinkName(TableName.valueOf("ns", name.getMethodName()), "fefefe", "0123456"));

    for (String name : validLinkNames) {
      Matcher m = HFileLink.LINK_NAME_PATTERN.matcher(name);
      assertTrue(m.matches());
      Assert.assertEquals(HFileLink.getReferencedTableName(name),
        TableName.valueOf(m.group(1), m.group(2)));
      Assert.assertEquals(HFileLink.getReferencedRegionName(name), m.group(3));
      Assert.assertEquals(HFileLink.getReferencedHFileName(name), m.group(4));
    }
  }
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