(Failing) test for the findEffective algorithm
authorGeorgios Gousios <gousiosg@gmail.com>
Wed, 30 Nov 2011 11:27:22 +0000 (13:27 +0200)
committerGeorgios Gousios <gousiosg@gmail.com>
Wed, 30 Nov 2011 11:27:22 +0000 (13:27 +0200)
Also, fixes to the policy test file

logic/src/test/resources/policy.yaml
logic/src/test/scala/gr/grnet/aquarium/logic/test/DSLUtilsTest.scala

index f49e1f3..59da14a 100644 (file)
@@ -33,6 +33,12 @@ aquariumpolicy:
       vmtime: $price times $volume
       diskspace: $price times $volume
       effective:
+        from: 0
+    - algorithm:
+      name: freedisk
+      overrides: default
+      diskspace: 0
+      effective:
         repeat:
           - start: "00 00 12 * *"
             end:   "00 00 14 * *"
@@ -40,10 +46,6 @@ aquariumpolicy:
             end:   "00 00 20 * *"
         from: 0
         to: 124443
-    - algorithm:
-      name: freedisk
-      overrides: default
-      diskspace: 0
 
   pricelists:
     - pricelist: 
@@ -56,6 +58,7 @@ aquariumpolicy:
         from: 0
     - pricelist: 
       name: everyTue2
+      override: default
       bandwidthup: 0.01
       bandwidthdown: 0.02
       vmtime: 0.1
@@ -67,6 +70,7 @@ aquariumpolicy:
         from: 0
     - pricelist:
       name: foobar
+      override: default
       bandwidthup: 0.04
       bandwidthdown: 0.04
       vmtime: 0.6
@@ -103,6 +107,7 @@ aquariumpolicy:
     - agreement:
       overrides: default
       name: scaledbandwidth
+      pricelist: foobar
       algorithm:
         bandwidthup: |
                 if $volume gt 15 then
index 86b72d9..6d5b054 100644 (file)
@@ -174,6 +174,31 @@ class DSLUtilsTest extends DSLTestBase with DSLUtils with TestMethods {
     return
   }
 
+  @Test
+  def testFindEffective = {
+    before
+
+    val agr = creditpolicy.findAgreement("scaledbandwidth").get
+
+    val ts1 = 1322649482000L //Wed, 30 Nov 2011 10:38:02 GMT
+    val ts2 = 1322656682000L //Wed, 30 Nov 2011 12:38:02 GMT
+    val ts3 = 1322660282000L //Wed, 30 Nov 2011 13:38:02 GMT
+    val ts4 = 1322667482000L //Wed, 30 Nov 2011 15:38:02 GMT
+    val ts5 = 1322689082000L //Wed, 30 Nov 2011 21:38:02 GMT
+
+    var pricelists = resolveEffectivePricelistsForTimeslot((new Date(ts1), new Date(ts2)), agr)
+    assertEquals(2, pricelists.keySet.size)
+
+    pricelists = resolveEffectivePricelistsForTimeslot((new Date(ts2), new Date(ts3)), agr)
+    assertEquals(1, pricelists.keySet.size)
+
+    pricelists = resolveEffectivePricelistsForTimeslot((new Date(ts1), new Date(ts4)), agr)
+    assertEquals(3, pricelists.keySet.size)
+
+    pricelists = resolveEffectivePricelistsForTimeslot((new Date(ts1), new Date(ts5)), agr)
+    assertEquals(5, pricelists.keySet.size)
+  }
+
   @tailrec
   private def testSuccessiveTimeslots(result: List[(Date, Date)]): Unit = {
     if (result.isEmpty) return