From dabbc80105bdb3212d263e95e6a83b1454de8a11 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Thu, 19 Apr 2012 11:45:07 +0300 Subject: [PATCH] Use TimeHelpers.nowMillis --- .../scala/gr/grnet/aquarium/actor/service/rest/RESTActor.scala | 5 +++-- .../scala/gr/grnet/aquarium/actor/service/user/UserActor.scala | 6 +++--- .../scala/gr/grnet/aquarium/logic/accounting/Accounting.scala | 6 +++--- .../scala/gr/grnet/aquarium/service/EventProcessorService.scala | 7 ++++--- src/test/scala/gr/grnet/aquarium/logic/test/PerfTest.scala | 5 +++-- src/test/scala/gr/grnet/aquarium/logic/test/PolicyTest.scala | 2 +- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/scala/gr/grnet/aquarium/actor/service/rest/RESTActor.scala b/src/main/scala/gr/grnet/aquarium/actor/service/rest/RESTActor.scala index 3e16b92..ae51f2d 100644 --- a/src/main/scala/gr/grnet/aquarium/actor/service/rest/RESTActor.scala +++ b/src/main/scala/gr/grnet/aquarium/actor/service/rest/RESTActor.scala @@ -48,6 +48,7 @@ import gr.grnet.aquarium.actor.{RESTRole, AquariumActor, DispatcherRole} import RESTPaths.{UserBalancePath, UserStatePath, AdminPingAll} import com.ckkloverdos.maybe.{NoVal, Just} import message.service.dispatcher._ +import gr.grnet.aquarium.util.date.TimeHelpers /** * Spray-based REST service. This is the outer-world's interface to Aquarium functionality. @@ -78,7 +79,7 @@ class RESTActor(_id: String) extends AquariumActor with Loggable { protected def receive = { case RequestContext(HttpRequest(GET, "/ping", _, _, _), _, responder) ⇒ - responder.complete(stringResponse200("{\"pong\": %s}".format(System.currentTimeMillis()))) + responder.complete(stringResponse200("{\"pong\": %s}".format(TimeHelpers.nowMillis))) case RequestContext(HttpRequest(GET, "/stats", _, _, _), _, responder) ⇒ { (serverActor ? GetStats).mapTo[Stats].onComplete { @@ -100,7 +101,7 @@ class RESTActor(_id: String) extends AquariumActor with Loggable { case RequestContext(HttpRequest(GET, uri, headers, body, protocol), _, responder) ⇒ //+ Main business logic REST URIs are matched here - val millis = System.currentTimeMillis() + val millis = TimeHelpers.nowMillis uri match { case UserBalancePath(userId) ⇒ callDispatcher(RequestUserBalance(userId, millis), responder) diff --git a/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala b/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala index 5e0aeb4..eb97844 100644 --- a/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala +++ b/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala @@ -80,7 +80,7 @@ with Loggable { * Replay the event log for all events that affect the user state. */ def rebuildState(from: Long, to: Long): Unit = { - val start = System.currentTimeMillis() + val start = TimeHelpers.nowMillis if(_userState == null) createBlankState @@ -106,7 +106,7 @@ with Loggable { "%d resource events, %d wallet entries) in %d msec").format( numUserEvents + numResourceEvents + numWalletEntries, numUserEvents, numResourceEvents, numWalletEntries, - System.currentTimeMillis() - start)) + TimeHelpers.nowMillis - start)) } /** @@ -214,7 +214,7 @@ with Loggable { val userId = event.userId val timestamp = event.timestamp - if(System.currentTimeMillis() - _userState.newestSnapshotTime > 60 * 1000) { + if(TimeHelpers.nowMillis - _userState.newestSnapshotTime > 60 * 1000) { // calcWalletEntries() } self reply UserResponseGetBalance(userId, _userState.creditsSnapshot.creditAmount) diff --git a/src/main/scala/gr/grnet/aquarium/logic/accounting/Accounting.scala b/src/main/scala/gr/grnet/aquarium/logic/accounting/Accounting.scala index c92849f..d269853 100644 --- a/src/main/scala/gr/grnet/aquarium/logic/accounting/Accounting.scala +++ b/src/main/scala/gr/grnet/aquarium/logic/accounting/Accounting.scala @@ -41,11 +41,11 @@ import dsl._ import collection.immutable.SortedMap import java.util.Date import com.ckkloverdos.maybe.{NoVal, Maybe, Failed, Just} -import gr.grnet.aquarium.util.date.MutableDateCalc import gr.grnet.aquarium.util.{ContextualLogger, CryptoUtils, Loggable} import gr.grnet.aquarium.store.PolicyStore import gr.grnet.aquarium.AquariumException import gr.grnet.aquarium.events.{WalletEntry, ResourceEvent} +import gr.grnet.aquarium.util.date.{TimeHelpers, MutableDateCalc} /** * A timeslot together with the algorithm and unit price that apply for this particular timeslot. @@ -567,7 +567,7 @@ trait Accounting extends DSLUtils with Loggable { */ val chargeChunks = calcChangeChunks(agr, amount, dslResource, timeslot) - val timeReceived = System.currentTimeMillis + val timeReceived = TimeHelpers.nowMillis val rel = event.id :: related.map{x => x.sourceEventIDs}.flatten @@ -752,7 +752,7 @@ case class ChargeChunk(value: Double, algorithm: String, def id(): String = CryptoUtils.sha1("%f%s%f%s%s%d".format(value, algorithm, price, when.toString, - resource.name, System.currentTimeMillis())) + resource.name, TimeHelpers.nowMillis)) } /** An exception raised when something goes wrong with accounting */ diff --git a/src/main/scala/gr/grnet/aquarium/service/EventProcessorService.scala b/src/main/scala/gr/grnet/aquarium/service/EventProcessorService.scala index d9fb359..17e61e4 100644 --- a/src/main/scala/gr/grnet/aquarium/service/EventProcessorService.scala +++ b/src/main/scala/gr/grnet/aquarium/service/EventProcessorService.scala @@ -51,6 +51,7 @@ import java.util.concurrent.{ConcurrentHashMap, ConcurrentSkipListSet} import gr.grnet.aquarium.Configurator import com.ckkloverdos.maybe._ import gr.grnet.aquarium.events.AquariumEvent +import gr.grnet.aquarium.util.date.TimeHelpers /** * An abstract service that retrieves Aquarium events from a queue, @@ -165,7 +166,7 @@ abstract class EventProcessorService[E <: AquariumEvent] extends AkkaAMQP with L persisterManager.lb ! Persist(event, payload, queueReaderManager.lb, AckData(event.id, deliveryTag, queue.get)) } } else { - val eventWithReceivedMillis = event.copyWithReceivedMillis(System.currentTimeMillis()).asInstanceOf[E] + val eventWithReceivedMillis = event.copyWithReceivedMillis(TimeHelpers.nowMillis).asInstanceOf[E] persisterManager.lb ! Persist(eventWithReceivedMillis, payload, queueReaderManager.lb, AckData(event.id, deliveryTag, queue.get)) } @@ -227,11 +228,11 @@ abstract class EventProcessorService[E <: AquariumEvent] extends AkkaAMQP with L def receive = { case Persist(event, initialPayload, sender, ackData) ⇒ logger.debug("Persister-%s attempting store".format(self.getUuid())) - //val time = System.currentTimeMillis() + //val time = TimeHelpers.nowMillis if(exists(event)) sender ! Duplicate(ackData) else if(persist(event, initialPayload)) { - //logger.debug("Persist time: %d ms".format(System.currentTimeMillis() - time)) + //logger.debug("Persist time: %d ms".format(TimeHelpers.nowMillis - time)) sender ! PersistOK(ackData) } else sender ! PersistFailed(ackData) diff --git a/src/test/scala/gr/grnet/aquarium/logic/test/PerfTest.scala b/src/test/scala/gr/grnet/aquarium/logic/test/PerfTest.scala index cffc520..31ede37 100644 --- a/src/test/scala/gr/grnet/aquarium/logic/test/PerfTest.scala +++ b/src/test/scala/gr/grnet/aquarium/logic/test/PerfTest.scala @@ -40,6 +40,7 @@ import java.util.{Date} import org.junit.Assume._ import gr.grnet.aquarium.LogicTestsAssumptions import gr.grnet.aquarium.logic.accounting.dsl._ +import gr.grnet.aquarium.util.date.TimeHelpers /** * Performance tests for various critical path functions. @@ -53,7 +54,7 @@ class PerfTest extends DSLUtils with DSL { assumeTrue(LogicTestsAssumptions.EnablePerfTests) val iter = 1000 - var start = System.currentTimeMillis() + var start = TimeHelpers.nowMillis var numResolved = 0 val from = new Date(0) @@ -85,7 +86,7 @@ class PerfTest extends DSLUtils with DSL { numResolved += allEffectiveTimeslots(tf, Timeslot(new Date(min), new Date(max))).size } - var total = System.currentTimeMillis() - start + var total = TimeHelpers.nowMillis - start print("allEffectiveTimeslots: %d calls in %s msec. (%s resolved)\n".format(iter, total, numResolved)) } } \ No newline at end of file diff --git a/src/test/scala/gr/grnet/aquarium/logic/test/PolicyTest.scala b/src/test/scala/gr/grnet/aquarium/logic/test/PolicyTest.scala index e83ade5..9c223aa 100644 --- a/src/test/scala/gr/grnet/aquarium/logic/test/PolicyTest.scala +++ b/src/test/scala/gr/grnet/aquarium/logic/test/PolicyTest.scala @@ -69,7 +69,7 @@ class PolicyTest extends DSLTestBase with StoreConfigurator { //Touch the file to trigger reloading with non changed state Thread.sleep(200) - f.setLastModified(System.currentTimeMillis) + f.setLastModified(TimeHelpers.nowMillis) var polNew = Policy.reloadPolicies assertEquals(pol.keys.size, polNew.keys.size) -- 1.7.10.4