Search in sources :

Example 21 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method testSelectBestPoolsLotsOfContentV3Client.

@Test
public void testSelectBestPoolsLotsOfContentV3Client() {
    Pool pool = createV3OnlyPool();
    List<Pool> pools = new LinkedList<>();
    pools.add(pool);
    // Shouldn't throw an exception as we do for certv1 clients.
    consumer.setFact("system.certificate_version", "3.5");
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 22 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method testSelectBestPoolDefaultRule.

@Test
public void testSelectBestPoolDefaultRule() {
    consumer.setFact("cpu.cpu_socket(s)", "32");
    Product product = TestUtil.createProduct("a-product", "A product for testing");
    Pool pool1 = createPool(owner, product, 5, TestUtil.createDate(2000, 02, 26), TestUtil.createDate(2050, 02, 26));
    Pool pool2 = createPool(owner, product, 5, TestUtil.createDate(2000, 02, 26), TestUtil.createDate(2060, 02, 26));
    List<Pool> availablePools = Arrays.asList(new Pool[] { pool1, pool2 });
    List<PoolQuantity> result = autobindRules.selectBestPools(consumer, new String[] { product.getId() }, availablePools, compliance, null, new HashSet<>(), false);
    assertNotNull(result);
    for (PoolQuantity pq : result) {
        assertEquals(new Integer(1), pq.getQuantity());
    }
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 23 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method guestLimitAutobindServerAttachedNonStackable.

/*
     * If the hypervisor is already installed, and at least partially
     * subscribed, autobind will be able to cover the server subscription
     */
@Test
public void guestLimitAutobindServerAttachedNonStackable() {
    consumer.setFact("cpu.cpu_socket(s)", "2");
    for (int i = 0; i < 5; i++) {
        consumer.addGuestId(new GuestId("" + i, consumer, activeGuestAttrs));
    }
    Product server = mockProduct(productId, "some server", "2");
    server.setAttribute(Product.Attributes.GUEST_LIMIT, "4");
    Product hypervisor = mockProduct("hypervisor", "some hypervisor", "2");
    hypervisor.setAttribute(Product.Attributes.GUEST_LIMIT, "-1");
    Pool serverPool = TestUtil.createPool(owner, server, 10);
    Pool hyperPool = TestUtil.createPool(owner, hypervisor, 10);
    serverPool.setId("POOL-ID1");
    hyperPool.setId("Pool-ID2");
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.setPool(hyperPool);
    // compliant
    entitlement.setQuantity(1);
    // The hypervisor must be installed and entitled on the system for autobind
    // to pick up the unlimited guest_limit
    compliance.addCompliantProduct(hypervisor.getId(), entitlement);
    List<Pool> pools = new LinkedList<>();
    pools.add(serverPool);
    pools.add(hyperPool);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { server.getId() }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    assertEquals(new Integer(1), bestPools.get(0).getQuantity());
    assertEquals("POOL-ID1", bestPools.get(0).getPool().getId());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) GuestId(org.candlepin.model.GuestId) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 24 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method instanceAutobindForPhysical8SocketCompletePartialStack.

@Test
public void instanceAutobindForPhysical8SocketCompletePartialStack() {
    List<Pool> pools = createInstanceBasedPool();
    setupConsumer("8", false);
    // Create a pre-existing entitlement which only covers half of the sockets:
    Entitlement mockEnt = mockEntitlement(pools.get(0), 4);
    consumer.addEntitlement(mockEnt);
    compliance.addPartiallyCompliantProduct(productId, mockEnt);
    compliance.addPartialStack("1", mockEnt);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    assertEquals(1, bestPools.size());
    PoolQuantity q = bestPools.get(0);
    assertEquals(new Integer(4), q.getQuantity());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 25 with PoolQuantity

use of org.candlepin.model.PoolQuantity in project candlepin by candlepin.

the class AutobindRulesTest method autobindForPhysicalSocketPicksBestFitBalanceQuantity.

@Test
public void autobindForPhysicalSocketPicksBestFitBalanceQuantity() {
    List<Pool> pools = createSocketPool(1, 100, "1");
    pools.addAll(createSocketPool(5, 100, "2"));
    setupConsumer("9", false);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    // Should always pick the 2 5 socket subscriptions over 9 1 socket subscriptions
    // although we're slightly overconsuming, it's better than wasting subs that may be
    // used elsewhere
    assertEquals(1, bestPools.size());
    PoolQuantity q = bestPools.get(0);
    assertEquals(new Integer(2), q.getQuantity());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Aggregations

PoolQuantity (org.candlepin.model.PoolQuantity)75 Pool (org.candlepin.model.Pool)65 Test (org.junit.Test)52 Entitlement (org.candlepin.model.Entitlement)34 LinkedList (java.util.LinkedList)30 Product (org.candlepin.model.Product)28 HashMap (java.util.HashMap)27 ArrayList (java.util.ArrayList)21 Consumer (org.candlepin.model.Consumer)12 List (java.util.List)11 ConsumerType (org.candlepin.model.ConsumerType)11 Matchers.anyString (org.mockito.Matchers.anyString)11 Date (java.util.Date)8 Set (java.util.Set)8 HashSet (java.util.HashSet)7 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)7 ValidationResult (org.candlepin.policy.ValidationResult)7 Subscription (org.candlepin.model.dto.Subscription)6 Matchers.anyLong (org.mockito.Matchers.anyLong)6 PoolFilterBuilder (org.candlepin.model.PoolFilterBuilder)5