@@ -90,6 +90,24 @@ public class TestRouterAdminCLI {
9090 private static final PrintStream OLD_OUT = System .out ;
9191 private static final PrintStream OLD_ERR = System .err ;
9292
93+ // testInitViewFsToMountTable use
94+ private static final String BASEDIR = "/initViewFs" ;
95+ private static final String SRC1 = BASEDIR + "/data1" ;
96+ private static final String USER1 = "user1" ;
97+ private static final String GROUP1 = "group1" ;
98+ private static final String CLUSTER_NAME1 = "ClusterX" ;
99+ private static Path destPath1 ;
100+
101+ private static final String SRC2 = BASEDIR + "/data2" ;
102+ private static final String CLUSTER_NAME2 = "ClusterY" ;
103+
104+ private static final String SRC3 = BASEDIR + "/inExistent" ;
105+ private static Path destPath3 ;
106+
107+ private static String nnAddress ;
108+
109+
110+
93111 @ BeforeClass
94112 public static void globalSetUp () throws Exception {
95113 cluster = new StateStoreDFSCluster (false , 1 ,
@@ -707,115 +725,127 @@ public void testAddMountTableIfParentExist() throws Exception {
707725 }
708726 }
709727
710- @ Test
711- public void testInitViewFsToMountTable () throws Exception {
712- // re-set system out for testing
713- System .setOut (new PrintStream (out ));
714- stateStore .loadCache (MountTableStoreImpl .class , true );
715- String nnAddress = cluster .getRandomNamenode ().
728+ public void setInitViewFsToMountEnv () throws IOException {
729+ nnAddress = cluster .getRandomNamenode ().
716730 getNamenode ().getHostAndPort ();
717- String baseDir = "/initViewFs" ;
718- String src1 = baseDir + "/data1" ;
719- Path destPath1 = new Path ("hdfs://" + nnAddress + src1 );
720- String user1 = "user1" ;
721- String group1 = "group1" ;
722- String clusterName1 = "ClusterX" ;
723-
724- String src2 = baseDir + "/data2" ;
725- String clusterName2 = "ClusterY" ;
726-
727- String src3 = baseDir + "/inExistent" ;
728- Path destPath3 = new Path ("hdfs://" + nnAddress + src3 );
729- String clusterName3 = "ClusterZ" ;
730-
731- // 0.mkdir destPath
731+ destPath1 = new Path ("hdfs://" + nnAddress + SRC1 );
732+ destPath3 = new Path ("hdfs://" + nnAddress + SRC3 );
732733 hdfs .mkdirs (destPath1 );
733- // 1.set owner
734- hdfs .setOwner (destPath1 , user1 , group1 );
735- // 2.set viewFs mapping
736- // Use different clusterName and mount points
734+ hdfs .setOwner (destPath1 , USER1 , GROUP1 );
737735 admin .getConf ().set (CONFIG_VIEWFS_PREFIX + "." +
738- clusterName1 + ".link." + src1 , destPath1 .toString ());
736+ CLUSTER_NAME1 + ".link." + SRC1 , destPath1 .toString ());
739737 admin .getConf ().set (CONFIG_VIEWFS_PREFIX + "." +
740- clusterName2 + ".link." + src2 , destPath1 .toString ());
738+ CLUSTER_NAME1 + ".link." + SRC2 , destPath1 .toString ());
739+ }
741740
742- // 3.run initialization,Specify a ClusterName
743- String [] argv = new String []{"-initViewFsToMountTable" , clusterName1 };
741+ @ Test
742+ public void testInitViewFsToMountTableWithSpecificCluster () throws Exception {
743+ // re-set system out for testing
744+ System .setOut (new PrintStream (out ));
745+ stateStore .loadCache (MountTableStoreImpl .class , true );
746+ // 1.Initialize the environment
747+ setInitViewFsToMountEnv ();
748+ // 2.Run initialization,Specify a ClusterName
749+ String [] argv = new String []{"-initViewFsToMountTable" , CLUSTER_NAME1 };
744750 assertEquals (0 , ToolRunner .run (admin , argv ));
745- // 4.gets the mount point entries
751+ // 3.Gets the mount point entries
746752 stateStore .loadCache (MountTableStoreImpl .class , true );
747753 GetMountTableEntriesRequest getRequest = GetMountTableEntriesRequest
748- .newInstance (src1 );
754+ .newInstance (SRC1 );
749755 GetMountTableEntriesResponse getResponse = client .getMountTableManager ()
750756 .getMountTableEntries (getRequest );
751757 List <MountTable > mountTables = getResponse .getEntries ();
752- // 5 .Checking
758+ // 4 .Checking
753759 assertEquals (1 , mountTables .size ());
754760 MountTable mountTable = mountTables .get (0 );
755761 List <RemoteLocation > destinations = mountTable .getDestinations ();
756762 assertEquals (1 , destinations .size ());
757- assertEquals (user1 , mountTable .getOwnerName ());
758- assertEquals (group1 , mountTable .getGroupName ());
763+ assertEquals (USER1 , mountTable .getOwnerName ());
764+ assertEquals (GROUP1 , mountTable .getGroupName ());
759765 assertEquals (destPath1 .toUri ().getPath (), mountTable .
760766 getDestinations ().get (0 ).getDest ());
761767 assertEquals (nnAddress , mountTable .
762768 getDestinations ().get (0 ).getNameserviceId ());
763- assertEquals (src1 , mountTable .getSourcePath ());
764-
765- // Specify allCluster to initialize all mappings
766- argv = new String []{"-rm" , src1 };
769+ assertEquals (SRC1 , mountTable .getSourcePath ());
770+ // 5.Clear up
771+ argv = new String []{"-rm" , SRC1 };
767772 assertEquals (0 , ToolRunner .run (admin , argv ));
773+ }
774+
775+ @ Test
776+ public void testInitViewFsToMountTableWithAllCluster () throws Exception {
777+ // re-set system out for testing
778+ System .setOut (new PrintStream (out ));
768779 stateStore .loadCache (MountTableStoreImpl .class , true );
769- argv = new String []{"-initViewFsToMountTable" , "allClusters" };
780+ // 1.Initialize the environment
781+ setInitViewFsToMountEnv ();
782+ // 2.Specify allCluster to initialize all mappings
783+ stateStore .loadCache (MountTableStoreImpl .class , true );
784+ String [] argv = new String []{"-initViewFsToMountTable" , "allClusters" };
770785 assertEquals (0 , ToolRunner .run (admin , argv ));
771-
786+ // 3.Gets the mount point entries
772787 stateStore .loadCache (MountTableStoreImpl .class , true );
773- getRequest = GetMountTableEntriesRequest
774- .newInstance (baseDir );
775- getResponse = client .getMountTableManager ()
788+ GetMountTableEntriesRequest getRequest = GetMountTableEntriesRequest
789+ .newInstance (BASEDIR );
790+ GetMountTableEntriesResponse getResponse = client .getMountTableManager ()
776791 .getMountTableEntries (getRequest );
777- mountTables = getResponse .getEntries ();
792+ List < MountTable > mountTables = getResponse .getEntries ();
778793 assertEquals (2 , mountTables .size ());
794+ // 3.Checking
779795 for (MountTable mountTable1 : mountTables ) {
780- mountTable1 = mountTables .get (0 );
781- destinations = mountTable1 .getDestinations ();
796+ List <RemoteLocation > destinations = mountTable1 .getDestinations ();
782797 assertEquals (1 , destinations .size ());
783- assertEquals (user1 , mountTable1 .getOwnerName ());
784- assertEquals (group1 , mountTable1 .getGroupName ());
798+ assertEquals (USER1 , mountTable1 .getOwnerName ());
799+ assertEquals (GROUP1 , mountTable1 .getGroupName ());
785800 assertEquals (destPath1 .toUri ().getPath (), mountTable1 .
786801 getDestinations ().get (0 ).getDest ());
787802 assertEquals (nnAddress , mountTable1 .
788803 getDestinations ().get (0 ).getNameserviceId ());
789- assertEquals (src1 , mountTable1 .getSourcePath ());
790804 }
805+ assertEquals (SRC1 , mountTables .get (0 ).getSourcePath ());
806+ assertEquals (SRC2 , mountTables .get (1 ).getSourcePath ());
807+ // 5.Clear up
808+ argv = new String []{"-rm" , SRC1 };
809+ assertEquals (0 , ToolRunner .run (admin , argv ));
810+ argv = new String []{"-rm" , SRC2 };
811+ assertEquals (0 , ToolRunner .run (admin , argv ));
812+ }
813+
814+ @ Test
815+ public void testInitViewFsToMountTableMountNoExist () throws Exception {
816+ // re-set system out for testing
817+ System .setOut (new PrintStream (out ));
818+ stateStore .loadCache (MountTableStoreImpl .class , true );
819+ // 1.Initialize the environment
820+ setInitViewFsToMountEnv ();
791821 // When the mount directory does not exist
822+ String clusterName3 = "ClusterZ" ;
792823 admin .getConf ().set (CONFIG_VIEWFS_PREFIX + "." +
793- clusterName3 + ".link." + src3 , destPath3 .toString ());
794- // set user
795- UserGroupInformation userA = UserGroupInformation .createUserForTesting (
796- TEST_USER , new String []{TEST_USER });
797- UserGroupInformation .setLoginUser (userA );
798- argv = new String []{"-initViewFsToMountTable" , clusterName3 };
824+ clusterName3 + ".link." + SRC3 , destPath3 .toString ());
825+ // 2.Run initialization,Specify a ClusterName
826+ String [] argv = new String []{"-initViewFsToMountTable" , clusterName3 };
799827 assertEquals (0 , ToolRunner .run (admin , argv ));
800-
828+ // 3.Gets the mount point entries
801829 stateStore .loadCache (MountTableStoreImpl .class , true );
802- getRequest = GetMountTableEntriesRequest
803- .newInstance (src3 );
804- getResponse = client .getMountTableManager ()
830+ GetMountTableEntriesRequest getRequest = GetMountTableEntriesRequest
831+ .newInstance (SRC3 );
832+ GetMountTableEntriesResponse getResponse = client .getMountTableManager ()
805833 .getMountTableEntries (getRequest );
806- mountTables = getResponse .getEntries ();
807- // Checking
834+ List < MountTable > mountTables = getResponse .getEntries ();
835+ // 4. Checking
808836 assertEquals (1 , mountTables .size ());
809- mountTable = mountTables .get (0 );
810- destinations = mountTable .getDestinations ();
837+ MountTable mountTable = mountTables .get (0 );
838+ List < RemoteLocation > destinations = mountTable .getDestinations ();
811839 assertEquals (1 , destinations .size ());
812- assertEquals (TEST_USER , mountTable .getOwnerName ());
813- assertEquals (TEST_USER , mountTable .getGroupName ());
840+ assertEquals (System .getProperty ("user.name" ), mountTable .getOwnerName ());
814841 assertEquals (destPath3 .toUri ().getPath (), mountTable .
815842 getDestinations ().get (0 ).getDest ());
816843 assertEquals (nnAddress , mountTable .
817844 getDestinations ().get (0 ).getNameserviceId ());
818- assertEquals (src3 , mountTable .getSourcePath ());
845+ assertEquals (SRC3 , mountTable .getSourcePath ());
846+ // 5.Clear up
847+ argv = new String []{"-rm" , SRC3 };
848+ assertEquals (0 , ToolRunner .run (admin , argv ));
819849 }
820850
821851 @ Test
0 commit comments