@Test
public void testTierSharedInstanceAllocation() {

    List<AgentInstanceGroup> instanceGroups = asList(
            getInstanceGroup(Tier.Critical, M4_XLARGE_ID, 0, 0),
            getInstanceGroup(Tier.Critical, M4_4XLARGE_ID, 0, 0),
            getInstanceGroup(Tier.Flex, R4_4XLARGE_ID, 0, 0),
            getInstanceGroup(Tier.Flex, R4_8XLARGE_ID, 0, 0),
            getInstanceGroup(Tier.Flex, P2_8XLARGE_ID, 0, 3)
    );
    when(agentManagementService.getInstanceGroups()).thenReturn(instanceGroups);
    ApplicationSLA criticalSLA = ApplicationSlaSample.CriticalSmall.builder().withInstanceCount(20).build(); // 1 * 20 CPUs
    ApplicationSLA flexSLA = ApplicationSlaSample.FlexSmall.builder().withInstanceCount(20).build(); // 1 * 20 CPUs
    ApplicationSLA defaultFlexSLA = ApplicationSlaSample.DefaultFlex.builder().withInstanceCount(1).build(); // 2 * 1 CPUs
    Map<Tier, List<ApplicationSLA>> tierSLAs = CollectionsExt.<Tier, List<ApplicationSLA>>newHashMap()
            .entry(Tier.Critical, singletonList(criticalSLA))
            .entry(Tier.Flex, asList(defaultFlexSLA, flexSLA))
            .toMap();
    CapacityRequirements requirements = new CapacityRequirements(tierSLAs);
    CapacityAllocations allocations = strategy.compute(requirements);
    AgentInstanceGroup p28xlInstanceGroup = findInstanceGroupByInstanceType(allocations.getInstanceGroups(), P2_8XLARGE_ID);
    assertThat(allocations.getExpectedMinSize(p28xlInstanceGroup)).isEqualTo(1);
}