@@ -4921,5 +4921,247 @@ public void MergeFilesTest()
49214921 }
49224922 }
49234923 }
4924- }
4924+
4925+ /// <summary>
4926+ /// Test creation of new attribute on file and displays attributes using fstat command to check usage of new configurable trait.storagedepot.min.
4927+ /// </summary>
4928+ [ TestMethod ( ) ]
4929+ [ DynamicData ( nameof ( GetAttributeAndFstatTestData ) , DynamicDataSourceType . Method ) ]
4930+ public void AttributeAndFstatTest ( int config_trait_storagedepot_min , string attributeName , object attributeValue , GetFileMetadataCmdFlags getFileMetadataCmdFlags , string expectedValue , bool useDbTraitTable = false )
4931+ {
4932+ Utilities . CheckpointType cptype = Utilities . CheckpointType . A ;
4933+
4934+ string uri = configuration . ServerPort ;
4935+ string user = "admin" ;
4936+ string pass = string . Empty ;
4937+ string ws_client = "admin_space" ;
4938+
4939+
4940+ for ( int i = 0 ; i < 1 ; i ++ ) // run once for ascii, once for unicode
4941+ {
4942+ Process p4d = null ;
4943+ Repository rep = null ;
4944+ try
4945+ {
4946+ p4d = Utilities . DeployP4TestServer ( TestDir , cptype , TestContext . TestName ) ;
4947+ Assert . IsNotNull ( p4d , "Setup Failure" ) ;
4948+
4949+ var clientRoot = Utilities . TestClientRoot ( TestDir , cptype ) ;
4950+ var adminSpace = Path . Combine ( clientRoot , "admin_space" ) ;
4951+ Directory . CreateDirectory ( adminSpace ) ;
4952+
4953+ Server server = new Server ( new ServerAddress ( uri ) ) ;
4954+ rep = new Repository ( server ) ;
4955+ Utilities . SetClientRoot ( rep , TestDir , cptype , ws_client ) ;
4956+
4957+ using ( Connection con = rep . Connection )
4958+ {
4959+ con . UserName = user ;
4960+ con . Client = new Client ( ) ;
4961+ con . Client . Name = ws_client ;
4962+
4963+ Assert . AreEqual ( con . Status , ConnectionStatus . Disconnected ) ;
4964+ Assert . AreEqual ( con . Server . State , ServerState . Unknown ) ;
4965+ Assert . IsTrue ( con . Connect ( null ) ) ;
4966+ Assert . AreEqual ( con . Server . State , ServerState . Online ) ;
4967+ Assert . AreEqual ( con . Status , ConnectionStatus . Connected ) ;
4968+ Assert . AreEqual ( "admin" , con . Client . OwnerName ) ;
4969+
4970+ var codePath = Path . Combine ( clientRoot , "admin_space" , "MyCode" ) ;
4971+
4972+ Directory . CreateDirectory ( codePath ) ;
4973+
4974+ FileSpec fs = FileSpec . DepotSpec ( "//depot/MyCode/ReadMe.txt" ) ;
4975+
4976+ bool setRv ;
4977+
4978+ if ( config_trait_storagedepot_min >= 0 )
4979+ {
4980+ logger . Debug ( "Set new configurable trait.storagedepot.min" ) ;
4981+ setRv = P4ConfigureSetAttributeStorageConfigurable ( con , config_trait_storagedepot_min ) ;
4982+ Assert . IsTrue ( setRv ) ;
4983+ }
4984+
4985+ logger . Debug ( "Checkout file {0} to set attribute." , fs . DepotPath . Path ) ;
4986+
4987+ using ( P4Command editCmd = new P4Command ( rep , "edit" , true , fs . DepotPath . Path ) )
4988+ {
4989+
4990+ P4CommandResult attributeResult = editCmd . Run ( ) ;
4991+
4992+ }
4993+
4994+ logger . Debug ( "Adding new Attribute to the file {0}" , fs . DepotPath . Path ) ;
4995+
4996+ using ( P4Command attributeCmd = new P4Command ( rep , "attribute" , true , fs . DepotPath . Path ) )
4997+ {
4998+
4999+ Options opts = new Options ( ) ;
5000+ opts [ "-f" ] = null ;
5001+ opts [ "-n" ] = attributeName ;
5002+ opts [ "-v" ] = attributeValue . ToString ( ) ;
5003+
5004+ if ( useDbTraitTable )
5005+ {
5006+ opts [ "-T0" ] = null ;
5007+ }
5008+
5009+ if ( config_trait_storagedepot_min < 0 )
5010+ {
5011+ opts [ "-T1" ] = null ;
5012+ }
5013+
5014+ string value = "" ;
5015+
5016+ try
5017+ {
5018+ //run command and get results
5019+ P4CommandResult results = attributeCmd . Run ( opts ) ;
5020+ results . TaggedOutput [ 0 ] . TryGetValue ( "status" , out value ) ;
5021+ }
5022+ catch ( Exception ex )
5023+ {
5024+ // Check if we got expected exception while trying to add attribute using -T1 flag without setting new configurable.
5025+ Assert . AreEqual ( ex . Message , expectedValue ) ;
5026+ }
5027+
5028+ if ( config_trait_storagedepot_min >= 0 )
5029+ {
5030+ // confirm if attribute is added successfully to the file.
5031+ Assert . AreEqual ( value , "set" ) ;
5032+ Options ops = new Options ( ) ;
5033+ switch ( getFileMetadataCmdFlags )
5034+ {
5035+ case GetFileMetadataCmdFlags . Attributes :
5036+ ops [ "-Oa" ] = null ;
5037+ break ;
5038+
5039+ case GetFileMetadataCmdFlags . AttributesProp :
5040+ ops [ "-On" ] = null ;
5041+ break ;
5042+ }
5043+
5044+ IList < FileMetaData > actual = rep . GetFileMetaData ( ops , fs ) ;
5045+
5046+ Assert . AreEqual ( true , actual ? . Count > 0 ) ;
5047+ object attributeActualValue ;
5048+ Assert . IsTrue ( actual [ 0 ] . Attributes . ContainsKey ( attributeName ) ) ;
5049+ Assert . IsTrue ( actual [ 0 ] . Attributes . TryGetValue ( attributeName , out attributeActualValue ) ) ;
5050+
5051+ switch ( getFileMetadataCmdFlags )
5052+ {
5053+ // -Oa flag
5054+ case GetFileMetadataCmdFlags . Attributes :
5055+ Assert . AreEqual ( opts [ "-v" ] , attributeActualValue ) ;
5056+ break ;
5057+
5058+ // -On flag
5059+ case GetFileMetadataCmdFlags . AttributesProp :
5060+ Assert . AreEqual ( expectedValue , attributeActualValue ) ;
5061+ break ;
5062+ }
5063+ }
5064+ logger . Debug ( "Finished fstat" ) ;
5065+ }
5066+ }
5067+ }
5068+ finally
5069+ {
5070+ Utilities . RemoveTestServer ( p4d , TestDir ) ;
5071+ p4d ? . Dispose ( ) ;
5072+ rep ? . Dispose ( ) ;
5073+ }
5074+
5075+ cptype = Utilities . CheckpointType . U ;
5076+ }
5077+ }
5078+
5079+ /// <summary>
5080+ /// Configure the server to set trait.storagedepot.min
5081+ /// Log in as "admin" and run "p4 configure set trait.storagedepot.min = value"
5082+ /// </summary>
5083+ /// <param name="con">Connection to server</param>
5084+ /// <param name="value">If set to a value greater than 0, the value of a newly created attribute is stored in the trait depot if its size in bytes matches or exceeds the setting of this configurable.</param>
5085+ /// <returns>true if no error</returns>
5086+ private bool P4ConfigureSetAttributeStorageConfigurable ( Connection con , int value )
5087+ {
5088+ string oldUser = con . UserName ;
5089+ con . UserName = "admin" ;
5090+ con . Login ( "" ) ;
5091+
5092+ // Tell the server to support parallel
5093+ string [ ] args = { "set" , "trait.storagedepot.min=" + value } ;
5094+ using ( var cmd = new P4Command ( con , "configure" , false , args ) )
5095+ {
5096+ var cmdr = cmd . Run ( new Options ( ) ) ;
5097+ // now force a reconnect, or p4d might not use the new config
5098+ con . getP4Server ( ) . Reconnect ( ) ;
5099+
5100+ con . UserName = oldUser ;
5101+ return cmdr . Success ;
5102+ }
5103+ }
5104+
5105+ /// <summary>
5106+ /// Method is used by MSTest holds test data.
5107+ /// </summary>
5108+ /// <returns>Returns IEnumerable collection of test data</returns>
5109+ private static IEnumerable < object [ ] > GetAttributeAndFstatTestData ( )
5110+ {
5111+ // config_trait_storagedepot_min : trait.storagedepot.min=0
5112+ // attributeName: attribute name : FileID
5113+ // attributeValue: attribute value : 10
5114+ // getFileMetadataCmdFlags: fstat command flag : -Oa
5115+ // expectedValue: expected value from command result: 10
5116+ yield return new object [ ]
5117+ {
5118+ 0 ,
5119+ "FileID" ,
5120+ 10 ,
5121+ GetFileMetadataCmdFlags . Attributes ,
5122+ "10"
5123+ } ;
5124+ yield return new object [ ]
5125+ {
5126+ 1 ,
5127+ "InitialFileSize" ,
5128+ 100 ,
5129+ GetFileMetadataCmdFlags . AttributesProp ,
5130+ ".p4traits"
5131+ } ;
5132+ yield return new object [ ]
5133+ {
5134+ - 3 ,
5135+ "fileVersion" ,
5136+ 100 ,
5137+ GetFileMetadataCmdFlags . AttributesProp ,
5138+ "Trait depot storage has not been configured by 'trait.storagedepot.min'. This value must be greater than 0 to enable trait depot storage.\n "
5139+ } ;
5140+ yield return new object [ ]
5141+ {
5142+ 3 ,
5143+ "IsFileReadOnly" ,
5144+ 1 ,
5145+ GetFileMetadataCmdFlags . AttributesProp ,
5146+ "db.traits"
5147+ } ;
5148+ yield return new object [ ]
5149+ {
5150+ 3 ,
5151+ "FileSize" ,
5152+ "4000KB" ,
5153+ GetFileMetadataCmdFlags . AttributesProp ,
5154+ ".p4traits"
5155+ } ;
5156+ yield return new object [ ]
5157+ {
5158+ 2 ,
5159+ "FileUsers" ,
5160+ "admin,super user" ,
5161+ GetFileMetadataCmdFlags . AttributesProp ,
5162+ "db.traits" ,
5163+ true
5164+ } ;
5165+ }
5166+ }
49255167}
0 commit comments