Search in sources :

Example 16 with PoolQuantity

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

the class AutobindRulesTest method instanceAutobindForPhysical8Socket.

@Test
public void instanceAutobindForPhysical8Socket() {
    List<Pool> pools = createInstanceBasedPool();
    setupConsumer("8", false);
    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(8), q.getQuantity());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 17 with PoolQuantity

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

the class AutobindRulesTest method hostRestrictedAutobindForVirt8Vcpu.

@Test
public void hostRestrictedAutobindForVirt8Vcpu() {
    List<Pool> pools = createHostRestrictedVirtLimitPool();
    setupConsumer("8", true);
    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(1), q.getQuantity());
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 18 with PoolQuantity

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

the class AutobindRulesTest method testFindBestWillNotCompleteAPartialStackFromAnotherId.

@Test
public void testFindBestWillNotCompleteAPartialStackFromAnotherId() {
    consumer.setFact("cpu.cpu_socket(s)", "8");
    String productId1 = "A";
    String productId2 = "B";
    String productId3 = "C";
    Product product1 = mockStackingProduct(productId1, "Test Stack product", "1", "2");
    Product product2 = mockStackingProduct(productId2, "Test Stack product 2", "2", "2");
    Product product3 = mockProduct(productId3, "Test Provided product");
    Pool pool1 = mockPool(product1);
    pool1.setId("DEAD-BEEF");
    pool1.addProvidedProduct(product3);
    Pool pool2 = mockPool(product2);
    pool2.setId("DEAD-BEEF2");
    pool2.addProvidedProduct(product3);
    List<Pool> pools = new LinkedList<>();
    // pools.add(pool1);
    pools.add(pool2);
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.setPool(pool1);
    entitlement.setQuantity(2);
    compliance.addPartialStack("1", entitlement);
    List<PoolQuantity> result = autobindRules.selectBestPools(consumer, new String[] { productId2, productId3 }, pools, compliance, null, new HashSet<>(), false);
    assertNotNull(result);
    // We can make sure the partial stack wasn't completed
    for (PoolQuantity pq : result) {
        if (pq.getPool().getId().equals(pool1.getId())) {
            fail("Should not complete this stack");
        }
    }
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 19 with PoolQuantity

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

the class AutobindRulesTest method testPoolQuantityCompareNullPool.

@Test
public void testPoolQuantityCompareNullPool() {
    Product prod = mockProduct(productId, "some prod", "2");
    Pool pool1 = TestUtil.createPool(owner, prod, 10);
    pool1.setId("1234");
    Pool pool2 = TestUtil.createPool(owner, prod, 10);
    pool2.setId(null);
    PoolQuantity pq1 = new PoolQuantity(pool1, 5);
    PoolQuantity pq2 = new PoolQuantity(pool2, 5);
    assertTrue(pq1.compareTo(pq2) != 0);
    assertEquals(pq1.compareTo(pq2), -pq2.compareTo(pq1));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 20 with PoolQuantity

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

the class AutobindRulesTest method autobindForPhysicalSocketPicksBestFit.

@Test
public void autobindForPhysicalSocketPicksBestFit() {
    List<Pool> pools = createSocketPool(1, 100, "1");
    pools.addAll(createSocketPool(2, 100, "2"));
    setupConsumer("32", false);
    List<PoolQuantity> bestPools = autobindRules.selectBestPools(consumer, new String[] { productId }, pools, compliance, null, new HashSet<>(), false);
    // Should always pick the 2 socket subscriptions because less are required
    assertEquals(1, bestPools.size());
    PoolQuantity q = bestPools.get(0);
    assertEquals(new Integer(16), 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