@@ -1614,6 +1614,124 @@ func TestTryAllocate(t *testing.T) {
16141614 assertUserGroupResourceMaxLimits (t , getTestUserGroup (), resources .Multiply (res , 3 ), expectedQueuesMaxLimits )
16151615}
16161616
1617+ func TestApplicationsTriedCount (t * testing.T ) {
1618+ setupUGM ()
1619+ partition := createQueuesNodes (t )
1620+ assert .Assert (t , partition != nil , "partition create failed" )
1621+ if result := partition .tryAllocate (); result != nil {
1622+ t .Fatalf ("empty cluster allocate returned allocation: %s" , result )
1623+ }
1624+
1625+ app := newApplication (appID1 , "default" , "root.leaf" )
1626+ res , err := resources .NewResourceFromConf (map [string ]string {"vcore" : "18" })
1627+ assert .NilError (t , err , "failed to create resource" )
1628+ // add to the partition
1629+ err = partition .AddApplication (app )
1630+ assert .NilError (t , err , "failed to add app-1 to partition" )
1631+ err = app .AddAllocationAsk (newAllocationAsk (allocKey , appID1 , res ))
1632+ assert .NilError (t , err , "failed to add ask alloc-1 to app-1" )
1633+
1634+ app = newApplication (appID2 , "default" , "root.leaf" )
1635+ // add to the partition
1636+ err = partition .AddApplication (app )
1637+ assert .NilError (t , err , "failed to add app-2 to partition" )
1638+ res , err = resources .NewResourceFromConf (map [string ]string {"vcore" : "16" })
1639+ assert .NilError (t , err , "failed to create resource" )
1640+ err = app .AddAllocationAsk (newAllocationAsk (allocKey2 , appID2 , res ))
1641+ assert .NilError (t , err , "failed to add ask alloc-1 to app-2" )
1642+
1643+ app = newApplication (appID3 , "default" , "root.leaf" )
1644+ // add to the partition
1645+ err = partition .AddApplication (app )
1646+ assert .NilError (t , err , "failed to add app-3 to partition" )
1647+ res , err = resources .NewResourceFromConf (map [string ]string {"vcore" : "4" })
1648+ assert .NilError (t , err , "failed to create resource" )
1649+ err = app .AddAllocationAsk (newAllocationAsk (allocKey3 , appID3 , res ))
1650+ assert .NilError (t , err , "failed to add ask alloc-1 to app-3" )
1651+
1652+ expectedQueuesMaxLimits := make (map [string ]map [string ]interface {})
1653+ expectedQueuesMaxLimits ["root" ] = make (map [string ]interface {})
1654+ expectedQueuesMaxLimits ["root.leaf" ] = make (map [string ]interface {})
1655+ expectedQueuesMaxLimits ["root" ][maxresources ] = resources .NewResourceFromMap (map [string ]resources.Quantity {"memory" : 10 , "vcores" : 10 })
1656+ expectedQueuesMaxLimits ["root.leaf" ][maxresources ] = resources .NewResourceFromMap (map [string ]resources.Quantity {"memory" : 5 , "vcores" : 5 })
1657+ expectedQueuesMaxLimits ["root" ][maxapplications ] = uint64 (10 )
1658+ expectedQueuesMaxLimits ["root.leaf" ][maxapplications ] = uint64 (1 )
1659+ assertUserGroupResourceMaxLimits (t , getTestUserGroup (), nil , expectedQueuesMaxLimits )
1660+
1661+ // first allocation should be app-1 and alloc-2
1662+ result := partition .tryAllocate ()
1663+ if result == nil || result .Request == nil {
1664+ t .Fatal ("allocation did not return any allocation" )
1665+ }
1666+ assert .Equal (t , result .ResultType , objects .Allocated , "result type is not the expected allocated" )
1667+ assert .Equal (t , result .Request .GetApplicationID (), appID3 , "expected application app-2 to be allocated" )
1668+ assert .Equal (t , result .Request .GetAllocationKey (), allocKey3 , "expected ask alloc-2 to be allocated" )
1669+ assert .Equal (t , partition .root .GetApplicationsTried (), int64 (3 ), "expected 3 applications to be tried" )
1670+ }
1671+
1672+ func TestNodesTriedCount (t * testing.T ) {
1673+ setupUGM ()
1674+ partition , err := newConfiguredPartition ()
1675+ assert .NilError (t , err , "test partition create failed with error" )
1676+ var res1 * resources.Resource
1677+ res1 , err = resources .NewResourceFromConf (map [string ]string {"vcore" : "2" })
1678+ assert .NilError (t , err , "failed to create basic resource" )
1679+ err = partition .AddNode (newNodeMaxResource ("node-1" , res1 ))
1680+ assert .NilError (t , err , "test node1 add failed unexpected" )
1681+
1682+ var res2 * resources.Resource
1683+ res2 , err = resources .NewResourceFromConf (map [string ]string {"vcore" : "3" })
1684+ assert .NilError (t , err , "failed to create basic resource" )
1685+ err = partition .AddNode (newNodeMaxResource ("node-2" , res2 ))
1686+ assert .NilError (t , err , "test node2 add failed unexpected" )
1687+
1688+ var res3 * resources.Resource
1689+ res3 , err = resources .NewResourceFromConf (map [string ]string {"vcore" : "5" })
1690+ assert .NilError (t , err , "failed to create basic resource" )
1691+ err = partition .AddNode (newNodeMaxResource ("node-3" , res3 ))
1692+ assert .NilError (t , err , "test node3 add failed unexpected" )
1693+
1694+ var res4 * resources.Resource
1695+ res4 , err = resources .NewResourceFromConf (map [string ]string {"vcore" : "10" })
1696+ assert .NilError (t , err , "failed to create basic resource" )
1697+ err = partition .AddNode (newNodeMaxResource ("node-4" , res4 ))
1698+ assert .NilError (t , err , "test node4 add failed unexpected" )
1699+
1700+ assert .Assert (t , partition != nil , "partition create failed" )
1701+ if result := partition .tryAllocate (); result != nil {
1702+ t .Fatalf ("empty cluster allocate returned allocation: %s" , result )
1703+ }
1704+
1705+ app := newApplication (appID1 , "default" , "root.leaf" )
1706+ res , err := resources .NewResourceFromConf (map [string ]string {"vcore" : "4" })
1707+ assert .NilError (t , err , "failed to create resource" )
1708+ // add to the partition
1709+ err = partition .AddApplication (app )
1710+ assert .NilError (t , err , "failed to add app-1 to partition" )
1711+ err = app .AddAllocationAsk (newAllocationAsk (allocKey , appID1 , res ))
1712+ assert .NilError (t , err , "failed to add ask alloc-1 to app-1" )
1713+
1714+ expectedQueuesMaxLimits := make (map [string ]map [string ]interface {})
1715+ expectedQueuesMaxLimits ["root" ] = make (map [string ]interface {})
1716+ expectedQueuesMaxLimits ["root.leaf" ] = make (map [string ]interface {})
1717+ expectedQueuesMaxLimits ["root" ][maxresources ] = resources .NewResourceFromMap (map [string ]resources.Quantity {"memory" : 10 , "vcores" : 10 })
1718+ expectedQueuesMaxLimits ["root.leaf" ][maxresources ] = resources .NewResourceFromMap (map [string ]resources.Quantity {"memory" : 5 , "vcores" : 5 })
1719+ expectedQueuesMaxLimits ["root" ][maxapplications ] = uint64 (10 )
1720+ expectedQueuesMaxLimits ["root.leaf" ][maxapplications ] = uint64 (1 )
1721+ assertUserGroupResourceMaxLimits (t , getTestUserGroup (), nil , expectedQueuesMaxLimits )
1722+
1723+ // first allocation should be app-1 and alloc-2
1724+ result := partition .tryAllocate ()
1725+ if result == nil || result .Request == nil {
1726+ t .Fatal ("allocation did not return any allocation" )
1727+ }
1728+ assert .Equal (t , result .ResultType , objects .Allocated , "result type is not the expected allocated" )
1729+ assert .Equal (t , result .Request .GetApplicationID (), appID1 , "expected application app-2 to be allocated" )
1730+ assert .Equal (t , result .Request .GetAllocationKey (), allocKey , "expected ask alloc-2 to be allocated" )
1731+ assert .Equal (t , partition .root .GetApplicationsTried (), int64 (1 ), "expected 1 applications to be tried" )
1732+ assert .Equal (t , partition .root .GetNodesTried (), int64 (1 ), "expected 1 nodes to be tried" )
1733+ }
1734+
16171735// allocate ask request with required node
16181736func TestRequiredNodeReservation (t * testing.T ) {
16191737 setupUGM ()
0 commit comments