Exemple #1
0
  @Test
  public void testFutureSuggested() {
    consumer.setFact(SOCKET_FACT, "4");

    pool.setStartDate(TestUtil.createDate(9000, 1, 1));
    pool.setEndDate(TestUtil.createDate(9001, 1, 1));

    Pool currentPool = TestUtil.createPool(owner, product);
    currentPool.setStartDate(TestUtil.createDate(2000, 1, 1));
    currentPool.setEndDate(TestUtil.createDate(5000, 1, 1));
    currentPool.getProduct().setAttribute("multi-entitlement", "yes");
    currentPool.getProduct().setAttribute("stacking_id", "1");

    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    currentPool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement currentEntitlement = TestUtil.createEntitlement(owner, consumer, currentPool, null);
    currentEntitlement.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(currentEntitlement);
    consumer.setEntitlements(ents);

    SuggestedQuantity suggested =
        quantityRules.getSuggestedQuantity(currentPool, consumer, TestUtil.createDate(2010, 6, 1));
    assertEquals(new Long(0), suggested.getSuggested());

    // Make sure current coverage does not affect the future
    suggested = quantityRules.getSuggestedQuantity(pool, consumer, TestUtil.createDate(9000, 6, 1));
    assertEquals(new Long(2), suggested.getSuggested());
  }
Exemple #2
0
  @Test
  public void testPhysicalIgnoresFutureConsumed() {
    // Setup a future pool for the same product:
    Pool futurePool = TestUtil.createPool(owner, product);
    futurePool.setStartDate(TestUtil.createDate(2050, 1, 1));
    futurePool.setEndDate(TestUtil.createDate(2060, 1, 1));

    pool.getProduct().setAttribute("multi-entitlement", "yes");
    pool.getProduct().setAttribute("stacking_id", "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");
    futurePool.getProduct().setAttribute("multi-entitlement", "yes");
    futurePool.getProduct().setAttribute("stacking_id", "1");
    futurePool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    consumer.setFact(SOCKET_FACT, "4");

    // Green in future but we have nothing now:
    Entitlement e = createValidEntitlement(futurePool);
    e.setQuantity(4);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(4), suggested.getSuggested());
  }
Exemple #3
0
  @Test
  public void testStackOnlyStacksWithSameStackingId() {
    consumer.setFact(IS_VIRT, "false");
    consumer.setFact(SOCKET_FACT, "8");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    pool.setQuantity(10L);
    Product product1 = TestUtil.createProduct();
    Pool pool1 = TestUtil.createPool(owner, product1);
    Entitlement e =
        TestUtil.createEntitlement(owner, consumer, pool1, new EntitlementCertificate());

    Set<Entitlement> entSet = new HashSet<Entitlement>();
    entSet.add(e);
    pool1.setEntitlements(entSet);
    pool1.getProduct().setAttribute("multi-entitlement", "yes");
    pool1.getProduct().setAttribute("stacking_id", "2");
    pool1.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    pool1.setQuantity(10L);

    // Consume 2 subscriptions with another stacking ID
    Entitlement toAdd = pool1.getEntitlements().iterator().next();
    toAdd.setQuantity(2);
    consumer.addEntitlement(toAdd);

    // Ensure the 2 attached entitlements do not cause the suggested quantity to change
    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(4), suggested.getSuggested());
  }
Exemple #4
0
 @Test
 public void testPhysicalRoundsUp() {
   consumer.setFact(SOCKET_FACT, "4");
   pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "3");
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(2), suggested.getSuggested());
 }
Exemple #5
0
 @Test
 public void testNonMultiEntitlementPool() {
   pool.getProduct().setAttribute("multi-entitlement", "no");
   SuggestedQuantity suggested =
       quantityRules.getSuggestedQuantity(pool, new Consumer(), new Date());
   assertEquals(new Long(1), suggested.getSuggested());
 }
Exemple #6
0
 @Test
 public void testVirtRoundsUp() {
   consumer.setFact(IS_VIRT, "true");
   consumer.setFact(CORES_FACT, "8");
   pool.getProduct().setAttribute(VCPU_ATTRIBUTE, "6");
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(2), suggested.getSuggested());
 }
Exemple #7
0
 @Test
 public void testUnlimitedQuantity() {
   consumer.setFact(SOCKET_FACT, "8");
   pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
   pool.setQuantity(new Long(-1));
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(4), suggested.getSuggested());
 }
Exemple #8
0
  @Test
  public void testIsNotVirtWhenFactIsEmpty() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
  }
Exemple #9
0
 @Test
 public void testVirtIgnoresSockets() {
   // Ensure that we start this test with no entitlements.
   consumer.getEntitlements().clear();
   consumer.setFact(IS_VIRT, "true");
   consumer.setFact(SOCKET_FACT, "4");
   pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(1), suggested.getSuggested());
 }
Exemple #10
0
 @Test
 public void testVirtUses1IfNoVcpu() {
   // Ensure that we start this test with no entitlements.
   consumer.getEntitlements().clear();
   consumer.setFact(IS_VIRT, "true");
   consumer.setFact(SOCKET_FACT, "4");
   consumer.setFact(CORES_FACT, "8");
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(1), suggested.getSuggested());
 }
Exemple #11
0
 @Test
 public void testNonMultiEntitlementPoolMultiPool() {
   pool.getProduct().setAttribute("multi-entitlement", "no");
   List<Pool> pools = new LinkedList<Pool>();
   pools.add(pool);
   Map<String, SuggestedQuantity> results =
       quantityRules.getSuggestedQuantities(pools, new Consumer(), new Date());
   assertTrue(results.containsKey(pool.getId()));
   SuggestedQuantity suggested = results.get(pool.getId());
   assertEquals(new Long(1), suggested.getSuggested());
 }
Exemple #12
0
  @Test
  public void testSingleSocketInstanceBasedOnPhysical() {
    consumer.setFact(IS_VIRT, "false");
    consumer.setFact(SOCKET_FACT, "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");
    pool.getProduct().setAttribute(INSTANCE_ATTRIBUTE, "2");

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
    assertEquals(new Long(2), suggested.getIncrement());
  }
Exemple #13
0
  @Test
  public void testInstanceBasedOnPhysicalNotEnoughAvailableUneven() {
    consumer.setFact(IS_VIRT, "false");
    consumer.setFact(SOCKET_FACT, "40"); // lots of ents required
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    pool.getProduct().setAttribute(INSTANCE_ATTRIBUTE, "2");

    pool.setQuantity(3L);
    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
    assertEquals(new Long(2), suggested.getIncrement());
  }
Exemple #14
0
  /*
   * Distributors should always get suggested=1, increment=1
   */
  @Test
  public void testInstanceBasedOnDistributor() {
    Consumer dist = TestUtil.createConsumer(owner);
    dist.getType().setManifest(true);
    dist.setFact(IS_VIRT, "false");
    dist.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    pool.getProduct().setAttribute(INSTANCE_ATTRIBUTE, "2");

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, dist, new Date());
    assertEquals(new Long(1), suggested.getSuggested());
    assertEquals(new Long(1), suggested.getIncrement());
  }
Exemple #15
0
 /*
  * Guest limit should not have any bearing on the suggested quantity
  */
 @Test
 public void testInsufficientGuestLimit() {
   consumer.setFact(SOCKET_FACT, "8");
   Map<String, String> guestAttrs = new HashMap<String, String>();
   guestAttrs.put("virtWhoType", "libvirt");
   guestAttrs.put("active", "1");
   for (int i = 0; i < 5; i++) {
     consumer.addGuestId(new GuestId("" + i, consumer, guestAttrs));
   }
   pool.getProduct().setAttribute(GUEST_LIMIT_ATTRIBUTE, "4");
   pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
   pool.setQuantity(new Long(-1));
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(4), suggested.getSuggested());
 }
Exemple #16
0
  @Test
  public void testPhysicalAccountsForCurrentlyConsumed() {
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
  }
Exemple #17
0
  @Test
  public void testCalculatedValueIsZeroWhenNegativeIsCalculated() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(1000);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(0), suggested.getSuggested());
  }
Exemple #18
0
  @Test
  public void testTotalConsumedDoesNotIncludeFutureEntitlements() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, null);
    pool.setStartDate(TestUtil.createDate(9000, 1, 1));
    pool.setEndDate(TestUtil.createDate(9001, 1, 1));
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested =
        quantityRules.getSuggestedQuantity(pool, consumer, TestUtil.createDate(2010, 1, 1));
    assertEquals(new Long(2), suggested.getSuggested());
  }
Exemple #19
0
  @Test
  public void testTotalConsumedIsZeroWhenNoMatches() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Product product2 = TestUtil.createProduct();
    Pool pool2 = TestUtil.createPool(owner, product2);

    Entitlement e = createValidEntitlement(pool2);
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
  }
Exemple #20
0
  @Test
  public void testPhysicalIgnoresPastConsumed() {
    pool.getProduct().setAttribute("multi-entitlement", "yes");
    pool.getProduct().setAttribute("stacking_id", "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    consumer.setFact(SOCKET_FACT, "4");

    // Green now, but we will ask for suggested quantity on a date in the future:
    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(4);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    // Ask for quantity in the future, past the end of the current pool:
    Calendar c = Calendar.getInstance();
    c.setTime(pool.getEndDate());
    Date futureDate = TestUtil.createDate(c.get(Calendar.YEAR) + 1, 1, 1);
    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, futureDate);
    assertEquals(new Long(4), suggested.getSuggested());
  }