Skip to content

Commit

Permalink
remove joda time
Browse files Browse the repository at this point in the history
  • Loading branch information
micossow committed Sep 2, 2023
1 parent b82eee2 commit d5e6449
Show file tree
Hide file tree
Showing 32 changed files with 154 additions and 153 deletions.
1 change: 0 additions & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ This product uses the following libraries:

For the core system:
* scala (BSD-like license, http://www.scala-lang.org/node/146)
* joda-time (Apache 2)
* slf4j (MIT, http://www.slf4j.org/license.html)
* logback (EPL 1.0/LGPL 2.1, http://logback.qos.ch/license.html)

7 changes: 2 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.softwaremill.SbtSoftwareMillCommon.commonSmlBuildSettings
import com.typesafe.sbt.packager.docker.{Cmd, ExecCmd}
import sbt.Keys.javaOptions
import sbt.internal.util.complete.Parsers.spaceDelimited
import scoverage.ScoverageKeys._
import scoverage.ScoverageKeys.*

import scala.sys.process.Process

Expand All @@ -25,8 +25,6 @@ lazy val yarnTask = inputKey[Unit]("Run yarn with arguments")
lazy val ensureDockerBuildx = taskKey[Unit]("Ensure that docker buildx configuration exists")
lazy val dockerBuildWithBuildx = taskKey[Unit]("Build docker images using buildx")

val jodaTime = "joda-time" % "joda-time" % "2.12.5"
val jodaConvert = "org.joda" % "joda-convert" % "2.2.3"
val config = "com.typesafe" % "config" % "1.4.2"
val pureConfig = "com.github.pureconfig" %% "pureconfig" % "0.17.4"
val scalaXml = "org.scala-lang.modules" %% "scala-xml" % "2.2.0"
Expand Down Expand Up @@ -111,7 +109,7 @@ lazy val core: Project = (project in file("core"))
.settings(
Seq(
name := "elasticmq-core",
libraryDependencies ++= Seq(jodaTime, jodaConvert, akka2Actor, akka2Testkit) ++ common,
libraryDependencies ++= Seq(akka2Actor, akka2Testkit) ++ common,
coverageMinimumStmtTotal := 94
)
)
Expand Down Expand Up @@ -288,7 +286,6 @@ lazy val nativeServer: Project = (project in file("native-server"))
"-H:IncludeResources=.*conf",
"-H:IncludeResources=version",
"-H:IncludeResources=.*\\.properties",
"-H:IncludeResources=org/joda/time/tz/data/.*",
"-H:+ReportExceptionStackTraces",
"-H:-ThrowUnsafeOffsetErrors",
"--enable-http",
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/scala/org/elasticmq/CreateQueueData.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.elasticmq

import org.joda.time.{DateTime, Duration}
import java.time.{Duration, OffsetDateTime}

case class CreateQueueData(
name: String,
defaultVisibilityTimeout: Option[MillisVisibilityTimeout] = None,
delay: Option[Duration] = None,
receiveMessageWait: Option[Duration] = None,
created: Option[DateTime] = None,
lastModified: Option[DateTime] = None,
created: Option[OffsetDateTime] = None,
lastModified: Option[OffsetDateTime] = None,
deadLettersQueue: Option[DeadLettersQueueData] = None,
isFifo: Boolean = false,
hasContentBasedDeduplication: Boolean = false,
Expand All @@ -17,14 +17,14 @@ case class CreateQueueData(
tags: Map[String, String] = Map[String, String]()
) {
def toQueueData: QueueData = {
val now = new DateTime()
val now = OffsetDateTime.now()
QueueData(
name,
defaultVisibilityTimeout.getOrElse(
MillisVisibilityTimeout.fromSeconds(CreateQueueDefaults.DefaultVisibilityTimeout)
),
delay.getOrElse(Duration.standardSeconds(CreateQueueDefaults.DefaultDelay)),
receiveMessageWait.getOrElse(Duration.standardSeconds(CreateQueueDefaults.DefaultReceiveMessageWait)),
delay.getOrElse(Duration.ofSeconds(CreateQueueDefaults.DefaultDelay)),
receiveMessageWait.getOrElse(Duration.ofSeconds(CreateQueueDefaults.DefaultReceiveMessageWait)),
created.getOrElse(now),
lastModified.getOrElse(now),
deadLettersQueue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.typesafe.scalalogging.LazyLogging
import org.elasticmq.FifoDeduplicationIdsHistory.DeduplicationIntervalMinutes
import org.elasticmq.actor.queue.InternalMessage
import org.elasticmq.util.NowProvider
import org.joda.time.DateTime

import java.time.OffsetDateTime
import scala.annotation.tailrec

/** Contains history of used Deduplication IDs associated with incoming messages to FIFO queues
Expand Down Expand Up @@ -75,4 +75,4 @@ object FifoDeduplicationIdsHistory {
def newHistory(): FifoDeduplicationIdsHistory = FifoDeduplicationIdsHistory(Map.empty, List.empty)
}

case class DeduplicationIdWithCreationDate(id: DeduplicationId, creationDate: DateTime)
case class DeduplicationIdWithCreationDate(id: DeduplicationId, creationDate: OffsetDateTime)
4 changes: 2 additions & 2 deletions core/src/main/scala/org/elasticmq/MessageData.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.elasticmq

import org.joda.time.DateTime
import java.time.OffsetDateTime

case class MessageData(
id: MessageId,
deliveryReceipt: Option[DeliveryReceipt],
content: String,
messageAttributes: Map[String, MessageAttribute],
nextDelivery: MillisNextDelivery,
created: DateTime,
created: OffsetDateTime,
statistics: MessageStatistics,
messageGroupId: Option[String],
messageDeduplicationId: Option[DeduplicationId],
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/org/elasticmq/MessageStatistics.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.elasticmq

import org.joda.time.DateTime
import java.time.OffsetDateTime

case class MessageStatistics(approximateFirstReceive: Received, approximateReceiveCount: Int)

Expand All @@ -9,5 +9,5 @@ object MessageStatistics {
}

sealed trait Received
case class OnDateTimeReceived(when: DateTime) extends Received
case class OnDateTimeReceived(when: OffsetDateTime) extends Received
case object NeverReceived extends Received
6 changes: 3 additions & 3 deletions core/src/main/scala/org/elasticmq/QueueData.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.elasticmq

import org.joda.time.{Duration, DateTime}
import java.time.{Duration, OffsetDateTime}

case class QueueData(
name: String,
defaultVisibilityTimeout: MillisVisibilityTimeout,
delay: Duration,
receiveMessageWait: Duration,
created: DateTime,
lastModified: DateTime,
created: OffsetDateTime,
lastModified: OffsetDateTime,
deadLettersQueue: Option[DeadLettersQueueData] = None,
isFifo: Boolean = false,
hasContentBasedDeduplication: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.elasticmq.actor.queue

import java.util.UUID

import org.elasticmq._
import org.elasticmq.util.NowProvider
import org.joda.time.DateTime

import java.time.OffsetDateTime
import java.util.UUID
import scala.collection.mutable

case class InternalMessage(
Expand All @@ -15,7 +14,7 @@ case class InternalMessage(
content: String,
messageAttributes: Map[String, MessageAttribute],
messageSystemAttributes: Map[String, MessageAttribute],
created: DateTime,
created: OffsetDateTime,
orderIndex: Int,
var firstReceive: Received,
var receiveCount: Int,
Expand Down Expand Up @@ -52,7 +51,7 @@ case class InternalMessage(
receiveCount += 1

if (firstReceive == NeverReceived) {
firstReceive = OnDateTimeReceived(new DateTime(nowProvider.nowMillis))
firstReceive = OnDateTimeReceived(nowProvider.now)
}
}

Expand Down Expand Up @@ -95,11 +94,11 @@ object InternalMessage {
new InternalMessage(
newMessageData.id.getOrElse(generateId()).id,
mutable.Buffer.empty,
newMessageData.nextDelivery.toMillis(now, queueData.delay.getMillis).millis,
newMessageData.nextDelivery.toMillis(now, queueData.delay.toMillis).millis,
newMessageData.content,
newMessageData.messageAttributes,
newMessageData.messageSystemAttributes,
new DateTime(),
OffsetDateTime.now(),
newMessageData.orderIndex,
NeverReceived,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package org.elasticmq.actor.queue
import akka.actor.{ActorRef, Cancellable}
import org.elasticmq.actor.reply._
import org.elasticmq.msg.{QueueMessageMsg, ReceiveMessages, SendMessage, UpdateVisibilityTimeout}
import org.joda.time.Duration

import java.time.Duration
import scala.annotation.tailrec
import scala.concurrent.{duration => scd}

Expand Down Expand Up @@ -41,7 +41,7 @@ trait QueueActorWaitForMessagesOps extends ReplyingActor with QueueActorMessageO
val result = receiveMessages(visibilityTimeout, count, receiveRequestAttemptId)
val waitForMessages = waitForMessagesOpt.getOrElse(queueData.receiveMessageWait)

if (result.result.contains(Nil) && waitForMessages.getMillis > 0) {
if (result.result.contains(Nil) && waitForMessages.toMillis > 0) {
val seq = assignSequenceFor(rm, context.sender())
logger.debug(s"${queueData.name}: Awaiting messages: start for sequence $seq.")
scheduleTimeoutReply(seq, waitForMessages)
Expand Down Expand Up @@ -90,7 +90,7 @@ trait QueueActorWaitForMessagesOps extends ReplyingActor with QueueActorMessageO
}

private def scheduleTimeoutReply(seq: Long, waitForMessages: Duration): Unit = {
schedule(waitForMessages.getMillis, ReplyIfTimeout(seq, Nil))
schedule(waitForMessages.toMillis, ReplyIfTimeout(seq, Nil))
}

private def scheduleTryReplyWhenAvailable(): Unit = {
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/org/elasticmq/msg/QueueMsg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import akka.actor.ActorRef
import org.elasticmq._
import org.elasticmq.actor.queue.InternalMessage
import org.elasticmq.actor.reply.Replyable
import org.joda.time.Duration

import java.time.Duration

sealed trait QueueMsg[T] extends Replyable[T]

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/org/elasticmq/util/NowProvider.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.elasticmq.util

import org.joda.time.DateTime
import java.time.OffsetDateTime

class NowProvider {
def nowMillis: Long = System.currentTimeMillis()
def now = new DateTime()
def now: OffsetDateTime = OffsetDateTime.now()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.elasticmq.util

import java.time.{Instant, OffsetDateTime, ZoneOffset}

object OffsetDateTimeUtil {

def ofEpochMilli(millis: Long): OffsetDateTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneOffset.UTC)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package org.elasticmq

import org.elasticmq.actor.queue.InternalMessage
import org.elasticmq.util.NowProvider
import org.joda.time.DateTime
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

import java.time.OffsetDateTime
import scala.collection.mutable

class FifoDeduplicationIdsHistoryTest extends AnyFunSuite with Matchers {

test("Should store added deduplication IDs") {
val history = FifoDeduplicationIdsHistory.newHistory()
val updatedHistory = history
.addNew(newInternalMessage(Some(DeduplicationId("1")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("2")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("3")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("4")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("1")), OffsetDateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("2")), OffsetDateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("3")), OffsetDateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("4")), OffsetDateTime.now()))

updatedHistory.messagesByDeduplicationId.keys shouldBe Set(
DeduplicationId("1"),
Expand All @@ -30,26 +30,26 @@ class FifoDeduplicationIdsHistoryTest extends AnyFunSuite with Matchers {

test("History should not override given deduplication ID entry if such one already exists") {
val history = FifoDeduplicationIdsHistory.newHistory()
val dateTimeInPast = DateTime.now().minusMinutes(10)
val OffsetDateTimeInPast = OffsetDateTime.now().minusMinutes(10)
val updatedHistory = history
.addNew(newInternalMessage(Some(DeduplicationId("1")), dateTimeInPast))
.addNew(newInternalMessage(Some(DeduplicationId("1")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("1")), OffsetDateTimeInPast))
.addNew(newInternalMessage(Some(DeduplicationId("1")), OffsetDateTime.now()))

updatedHistory.messagesByDeduplicationId.keys shouldBe Set(
DeduplicationId("1")
)
updatedHistory.deduplicationIdsByCreationDate shouldBe List(
DeduplicationIdWithCreationDate(DeduplicationId("1"), dateTimeInPast)
DeduplicationIdWithCreationDate(DeduplicationId("1"), OffsetDateTimeInPast)
)
}

test("History should show if given deduplication ID was already used or not") {
val history = FifoDeduplicationIdsHistory.newHistory()
val updatedHistory = history
.addNew(newInternalMessage(Some(DeduplicationId("1")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("2")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("3")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("4")), DateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("1")), OffsetDateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("2")), OffsetDateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("3")), OffsetDateTime.now()))
.addNew(newInternalMessage(Some(DeduplicationId("4")), OffsetDateTime.now()))

updatedHistory.wasRegistered(Some(DeduplicationId("1"))) should be(defined)
updatedHistory.wasRegistered(Some(DeduplicationId("4"))) should be(defined)
Expand All @@ -59,7 +59,7 @@ class FifoDeduplicationIdsHistoryTest extends AnyFunSuite with Matchers {

test("History should erase all entries that were created 5 or more minutes ago") {
val history = FifoDeduplicationIdsHistory.newHistory()
val now = DateTime.now()
val now = OffsetDateTime.now()
val updatedHistory = history
.addNew(newInternalMessage(Some(DeduplicationId("1")), now.minusMinutes(20)))
.addNew(newInternalMessage(Some(DeduplicationId("2")), now.minusMinutes(10)))
Expand All @@ -77,7 +77,7 @@ class FifoDeduplicationIdsHistoryTest extends AnyFunSuite with Matchers {

test("Cleaning outdated IDs should stop at first ID which was created in last 5 minutes") {
val history = FifoDeduplicationIdsHistory.newHistory()
val now = DateTime.now()
val now = OffsetDateTime.now()
val updatedHistory = history
.addNew(newInternalMessage(Some(DeduplicationId("1")), now.minusMinutes(20)))
.addNew(newInternalMessage(Some(DeduplicationId("2")), now.minusMinutes(4)))
Expand All @@ -100,7 +100,7 @@ class FifoDeduplicationIdsHistoryTest extends AnyFunSuite with Matchers {
)
}

def newInternalMessage(maybeDeduplicationId: Option[DeduplicationId], created: DateTime): InternalMessage =
def newInternalMessage(maybeDeduplicationId: Option[DeduplicationId], created: OffsetDateTime): InternalMessage =
InternalMessage(
id = "1",
deliveryReceipts = mutable.Buffer.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import org.elasticmq._
import org.elasticmq.actor.reply._
import org.elasticmq.actor.test.{ActorTest, DataCreationHelpers, QueueManagerForEachTest}
import org.elasticmq.msg._
import org.joda.time.DateTime
import org.scalatest.EitherValues
import org.scalatest.matchers.should.Matchers

import java.time.OffsetDateTime
import scala.concurrent.Await
import scala.concurrent.duration.DurationInt

Expand All @@ -33,7 +33,7 @@ class DeduplicationTimerTest
} yield (fifoQueue, firstLookup),
1.second
)
nowProvider.mutableNowMillis.set(DateTime.now().plusMinutes(5).plusSeconds(1).getMillis)
nowProvider.mutableNowMillis.set(OffsetDateTime.now().plusMinutes(5).plusSeconds(1).toInstant.toEpochMilli)

// Timer is scheduled to run each second, to eliminate random time errors we are waiting a little bit longer
Thread.sleep(1500)
Expand Down
Loading

0 comments on commit d5e6449

Please sign in to comment.