2424import org .apache .hadoop .fs .Path ;
2525import org .apache .hadoop .hbase .HBaseClassTestRule ;
2626import org .apache .hadoop .hbase .HBaseTestingUtil ;
27+ import org .apache .hadoop .hbase .HConstants ;
28+ import org .apache .hadoop .hbase .ServerName ;
2729import org .apache .hadoop .hbase .backup .util .BackupUtils ;
30+ import org .apache .hadoop .hbase .master .region .MasterRegionFactory ;
2831import org .apache .hadoop .hbase .testclassification .SmallTests ;
32+ import org .apache .hadoop .hbase .util .Addressing ;
33+ import org .apache .hadoop .hbase .util .CommonFSUtils ;
34+ import org .apache .hadoop .hbase .util .EnvironmentEdgeManager ;
2935import org .apache .hadoop .security .UserGroupInformation ;
3036import org .junit .Assert ;
3137import org .junit .ClassRule ;
@@ -45,7 +51,7 @@ public class TestBackupUtils {
4551 protected static Configuration conf = TEST_UTIL .getConfiguration ();
4652
4753 @ Test
48- public void TestGetBulkOutputDir () {
54+ public void testGetBulkOutputDir () {
4955 // Create a user who is not the current user
5056 String fooUserName = "foo1234" ;
5157 String fooGroupName = "group1" ;
@@ -78,4 +84,24 @@ public Path run() {
7884 // Make sure the directory is in foo1234's home directory
7985 Assert .assertTrue (bulkOutputDir .toString ().startsWith (fooHomeDirectory .toString ()));
8086 }
87+
88+ @ Test
89+ public void testFilesystemWalHostNameParsing () throws IOException {
90+ String host = "localhost" ;
91+ int port = 60030 ;
92+ ServerName serverName = ServerName .valueOf (host , port , 1234 );
93+ Path walRootDir = CommonFSUtils .getWALRootDir (conf );
94+ Path oldLogDir = new Path (walRootDir , HConstants .HREGION_OLDLOGDIR_NAME );
95+
96+ Path testWalPath = new Path (oldLogDir ,
97+ serverName .toString () + BackupUtils .LOGNAME_SEPARATOR + EnvironmentEdgeManager .currentTime ());
98+ Path testMasterWalPath =
99+ new Path (oldLogDir , testWalPath .getName () + MasterRegionFactory .ARCHIVED_WAL_SUFFIX );
100+
101+ String parsedHost = BackupUtils .parseHostFromOldLog (testMasterWalPath );
102+ Assert .assertNull (parsedHost );
103+
104+ parsedHost = BackupUtils .parseHostFromOldLog (testWalPath );
105+ Assert .assertEquals (parsedHost , host + Addressing .HOSTNAME_PORT_SEPARATOR + port );
106+ }
81107}
0 commit comments