trait DSLUtils extends DateUtils {
/**
+ * Get a list of all timeslots within which a algorithm/pricelist
+ * is effective.
+ */
+ def allEffectiveTimeslots(spec: DSLTimeFrame, from: Date, to: Date):
+ List[(Date, Date)] = {
+
+
+
+ spec.repeat.flatMap{r =>effectiveTimeslots(r, from, Some(to))} sortWith sorter
+ }
+
+ /**
* Get a list of all time periods within which a time frame is active.
* If the to date is None, the expansion takes place within a timeframe
* between `from .. from` + 1 year. The result is returned sorted by
* timeframe start date.
*/
- def expandTimeRepeat(spec: DSLTimeFrameRepeat, from: Date, to: Option[Date]):
+ def effectiveTimeslots(spec: DSLTimeFrameRepeat, from: Date, to: Option[Date]):
List[(Date, Date)] = {
assert(spec.start.size == spec.end.size)
case Some(y) => y
}
- def sorter(x: (Date, Date), y: (Date, Date)) : Boolean =
- if (y._1 after x._1) true else false
-
coExpandTimespecs(spec.start.zip(spec.end), from, endDate) sortWith sorter
}
+
+ private def sorter(x: (Date, Date), y: (Date, Date)) : Boolean =
+ if (y._1 after x._1) true else false
+
/**
* Calculate periods of activity for a list of timespecs
*/
}
@Test
- def testExpandTimeRepeat = {
+ def testEffectiveTimeslots = {
val from = new Date(1321621969000L) //Fri Nov 18 15:12:49 +0200 2011
val to = new Date(1324214719000L) //Sun Dec 18 15:25:19 +0200 2011
var repeat = DSLTimeFrameRepeat(parseCronString("00 12 * * *"),
parseCronString("00 14 * * *"))
- var result = expandTimeRepeat(repeat, from, Some(to))
+ var result = effectiveTimeslots(repeat, from, Some(to))
assertNotEmpty(result)
assertEquals(31, result.size)
//Expansion outside timeframe
repeat = DSLTimeFrameRepeat(parseCronString("00 12 * May *"),
parseCronString("00 14 * Sep *"))
- result = expandTimeRepeat(repeat, from, Some(to))
+ result = effectiveTimeslots(repeat, from, Some(to))
assertEquals(0, result.size)
repeat = DSLTimeFrameRepeat(parseCronString("00 12 * * 5"),
parseCronString("00 14 * * 1"))
- result = expandTimeRepeat(repeat, from, Some(to))
+ result = effectiveTimeslots(repeat, from, Some(to))
assertEquals(4, result.size)
repeat = DSLTimeFrameRepeat(parseCronString("00 12 * * Mon,Wed,Fri"),
parseCronString("00 14 * * Tue,Thu,Sat"))
- result = expandTimeRepeat(repeat, from, Some(to))
+ result = effectiveTimeslots(repeat, from, Some(to))
assertEquals(13, result.size)
}
}
\ No newline at end of file
package gr.grnet.aquarium.logic.test
-import java.util.Date
-import gr.grnet.aquarium.logic.events._
import org.junit.Test
class EventProcessorTest {
- def getEvents(): List[Event] = {
- //Tmp list of events
- List[Event](
- new VMCreated(1, new Date(123), 2, 1),
- new VMStarted(2, new Date(123), 2, 1),
- new VMCreated(3, new Date(125), 2, 2),
- new DiskSpaceChanged(4, new Date(122), 2, 1554),
- new DataUploaded(5, new Date(122), 2, 1554),
- new DiskSpaceChanged(6, new Date(122), 1, 1524),
- new DataUploaded(7, new Date(122), 1, 1524),
- new DiskSpaceChanged(8, new Date(122), 1, 1332)
- )
- }
-
@Test
def testProcess() = {
}