You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/07/03 02:03:58 UTC

[james-project] 03/15: JAMES-3150 change wording of delete to dereference in json serialization format

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 52232238f5ba060240d354342e1949df019d5ab9
Author: RĂ©mi KOWALSKI <rk...@linagora.com>
AuthorDate: Mon Jun 22 15:41:32 2020 +0200

    JAMES-3150 change wording of delete to dereference in json serialization format
---
 .../server/blob/deduplication/GCJsonReporter.scala | 20 +++----
 .../src/test/resources/gcReport.json               | 12 ++--
 .../blob/deduplication/GCJsonReporterTest.scala    | 66 +++++++++++-----------
 3 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/server/blob/blob-deduplicating/src/main/scala/org/apache/james/server/blob/deduplication/GCJsonReporter.scala b/server/blob/blob-deduplicating/src/main/scala/org/apache/james/server/blob/deduplication/GCJsonReporter.scala
index a37ec36..9f68ef8 100644
--- a/server/blob/blob-deduplicating/src/main/scala/org/apache/james/server/blob/deduplication/GCJsonReporter.scala
+++ b/server/blob/blob-deduplicating/src/main/scala/org/apache/james/server/blob/deduplication/GCJsonReporter.scala
@@ -19,7 +19,7 @@
 package org.apache.james.server.blob.deduplication
 
 import org.apache.james.blob.api.BlobId
-import org.apache.james.server.blob.deduplication.RelatedAction.{Delete, GarbageCollect, Init, Save}
+import org.apache.james.server.blob.deduplication.RelatedAction.{GarbageCollect, Init, Save}
 import play.api.libs.json.{JsString, Json, Writes}
 
 import scala.collection.immutable.TreeSet
@@ -29,7 +29,7 @@ sealed trait RelatedAction
 object RelatedAction {
   case object Init extends RelatedAction
   case class Save(blobId: BlobId, reference: ExternalID) extends RelatedAction
-  case class Delete(reference: ExternalID) extends RelatedAction
+  case class Dereference(reference: ExternalID) extends RelatedAction
   case object GarbageCollect extends RelatedAction
 }
 
@@ -44,14 +44,14 @@ object JsonReport {
                    `garbage-collection-iterations`: TreeSet[String],
                    blobs: Seq[BlobId],
                    references: Seq[Reference],
-                   deletions: Seq[Dereference])
+                   dereferences: Seq[Dereference])
 
 
   //action
   implicit val relatedActionWrites: Writes[RelatedAction] = {
     case Init => JsString("init")
     case Save(blobId, reference) => JsString(s"save(blob = ${blobId.asString()}, reference = ${reference.id})")
-    case Delete(reference) => JsString(s"delete(reference = ${reference.id})")
+    case RelatedAction.Dereference(reference) => JsString(s"dereference(reference = ${reference.id})")
     case GarbageCollect => JsString(s"garbageCollect")
   }
   //generation
@@ -134,7 +134,7 @@ object GCJsonReporter {
       `garbage-collection-iterations` = lastState.`garbage-collection-iterations` + gcReports.iteration.asString,
       blobs = lastState.blobs.diff(gcReports.blobsToDelete.map { case (generation, blobId) => JsonReport.BlobId(blobId.asString, generation) }.toSeq),
       references = lastState.references.filterNot(reference => blobsToDeleteAsString.contains(reference.blob)),
-      deletions = lastState.deletions.filterNot(dereference => blobsToDeleteAsString.contains(dereference.blob)))
+      dereferences = lastState.dereferences.filterNot(dereference => blobsToDeleteAsString.contains(dereference.blob)))
   }
 
   private def stateForDereference(reportStates: JsonReport, dereference: Dereference) = {
@@ -143,14 +143,14 @@ object GCJsonReporter {
     val iterations = previousState.`garbage-collection-iterations`
     val references = previousState.references
     val lastIteration = previousState.`garbage-collection-iterations`.last
-    val dereferences = previousState.deletions :+ JsonReport.Dereference(dereference.blob.asString(), dereference.generation, lastIteration)
+    val dereferences = previousState.dereferences :+ JsonReport.Dereference(dereference.blob.asString(), dereference.generation, lastIteration)
 
-    JsonReport.State(Delete(dereference.externalId),
+    JsonReport.State(RelatedAction.Dereference(dereference.externalId),
       `reference-generations` = referenceGenerations,
       `garbage-collection-iterations` = iterations,
       blobs = previousState.blobs,
       references = references,
-      deletions = dereferences)
+      dereferences = dereferences)
   }
 
   private def stateForReference(reportStates: JsonReport, add: Reference) = {
@@ -163,8 +163,8 @@ object GCJsonReporter {
     else
       previousState.blobs :+ JsonReport.BlobId(add.blobId.asString(), add.generation)
     val references = previousState.references :+ JsonReport.Reference(add.externalId.id, add.blobId.asString(), add.generation)
-    val deletions = previousState.deletions
+    val dereferences = previousState.dereferences
 
-    JsonReport.State(Save(add.blobId, add.externalId), referenceGenerations, iterations, blobs, references, deletions)
+    JsonReport.State(Save(add.blobId, add.externalId), referenceGenerations, iterations, blobs, references, dereferences)
   }
 }
diff --git a/server/blob/blob-deduplicating/src/test/resources/gcReport.json b/server/blob/blob-deduplicating/src/test/resources/gcReport.json
index 8c87a57..7d4ae89 100644
--- a/server/blob/blob-deduplicating/src/test/resources/gcReport.json
+++ b/server/blob/blob-deduplicating/src/test/resources/gcReport.json
@@ -5,7 +5,7 @@
     "garbage-collection-iterations" : [ "0" ],
     "blobs" : [ ],
     "references" : [ ],
-    "deletions" : [ ]
+    "dereferences" : [ ]
   }, {
     "related-action" : "save(blob = 0_myHash, reference = message1)",
     "reference-generations" : [ "0" ],
@@ -19,7 +19,7 @@
       "blob" : "0_myHash",
       "reference-generation" : "0"
     } ],
-    "deletions" : [ ]
+    "dereferences" : [ ]
   }, {
     "related-action" : "garbageCollect",
     "reference-generations" : [ "0" ],
@@ -33,9 +33,9 @@
       "blob" : "0_myHash",
       "reference-generation" : "0"
     } ],
-    "deletions" : [ ]
+    "dereferences" : [ ]
   }, {
-    "related-action" : "delete(reference = message1)",
+    "related-action" : "dereference(reference = message1)",
     "reference-generations" : [ "0", "1" ],
     "garbage-collection-iterations" : [ "0", "1" ],
     "blobs" : [ {
@@ -47,7 +47,7 @@
       "blob" : "0_myHash",
       "reference-generation" : "0"
     } ],
-    "deletions" : [ {
+    "dereferences" : [ {
       "blob" : "0_myHash",
       "reference-generation" : "1",
       "garbage-collection-iterations" : "1"
@@ -58,6 +58,6 @@
     "garbage-collection-iterations" : [ "0", "1", "2" ],
     "blobs" : [ ],
     "references" : [ ],
-    "deletions" : [ ]
+    "dereferences" : [ ]
   } ]
 }
\ No newline at end of file
diff --git a/server/blob/blob-deduplicating/src/test/scala/org/apache/james/server/blob/deduplication/GCJsonReporterTest.scala b/server/blob/blob-deduplicating/src/test/scala/org/apache/james/server/blob/deduplication/GCJsonReporterTest.scala
index c5961c2..6988e00 100644
--- a/server/blob/blob-deduplicating/src/test/scala/org/apache/james/server/blob/deduplication/GCJsonReporterTest.scala
+++ b/server/blob/blob-deduplicating/src/test/scala/org/apache/james/server/blob/deduplication/GCJsonReporterTest.scala
@@ -19,9 +19,7 @@
 
 package org.apache.james.server.blob.deduplication
 
-import java.time.Instant
-
-import org.apache.james.server.blob.deduplication.RelatedAction.{Delete, GarbageCollect, Init, Save}
+import org.apache.james.server.blob.deduplication.RelatedAction.{GarbageCollect, Init, Save}
 import org.apache.james.util.ClassLoaderUtils
 import org.scalatest.matchers.should.Matchers
 import org.scalatest.wordspec.AnyWordSpec
@@ -42,19 +40,19 @@ class GCJsonReporterTest extends AnyWordSpec with Matchers {
       `garbage-collection-iterations` = TreeSet(initialIteration),
       blobs = Seq[JsonReport.BlobId](),
       references = Nil,
-      deletions = Nil)
+      dereferences = Nil)
     val firstSaveReport = JsonReport.State(Save(blobId, externalId),
       `reference-generations` = TreeSet(generation),
       `garbage-collection-iterations` = TreeSet(initialIteration),
       blobs = Seq[JsonReport.BlobId](JsonReport.BlobId(blobId.asString, blobId.generation)),
       references = Seq(JsonReport.Reference(externalId.id, blobId.asString, generation)),
-      deletions = Nil)
-    val firstDeleteReport = JsonReport.State(Delete(externalId),
+      dereferences = Nil)
+    val firstDeleteReport = JsonReport.State(RelatedAction.Dereference(externalId),
       `reference-generations` = TreeSet(generation),
       `garbage-collection-iterations` = TreeSet(initialIteration),
       blobs = Seq[JsonReport.BlobId](JsonReport.BlobId(blobId.asString, blobId.generation)),
       references = Seq(JsonReport.Reference(externalId.id, blobId.asString, generation)),
-      deletions = Seq(JsonReport.Dereference(blobId.asString(), generation, initialIteration)))
+      dereferences = Seq(JsonReport.Dereference(blobId.asString(), generation, initialIteration)))
 
     val iterationForImmediateGC = Iteration(1L, Set(), generation)
     val gcReportImmediate = GCIterationReport(iterationForImmediateGC, Set())
@@ -63,13 +61,16 @@ class GCJsonReporterTest extends AnyWordSpec with Matchers {
       "on initial state" in {
         GCJsonReporter
           .report(GCIterationEvent(gcReportImmediate) :: Nil)
-          .states should be (Seq(initialReport,
-          JsonReport.State(GarbageCollect,
-          `reference-generations` = TreeSet(Generation.first),
-          `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration),
-          blobs = Seq[JsonReport.BlobId](),
-          references = Nil,
-          deletions = Nil)))
+          .states should be(
+          Seq(
+            initialReport,
+            JsonReport.State(
+              GarbageCollect,
+              `reference-generations` = TreeSet(Generation.first),
+              `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration),
+              blobs = Seq[JsonReport.BlobId](),
+              references = Nil,
+              dereferences = Nil)))
       }
     }
 
@@ -77,21 +78,21 @@ class GCJsonReporterTest extends AnyWordSpec with Matchers {
       "one reference is added" in {
         GCJsonReporter
           .report(ReferenceEvent(Reference(externalId, blobId, generation)) :: GCIterationEvent(gcReportImmediate) :: Nil)
-          .states should be (Seq(
+          .states should be(Seq(
           initialReport,
           firstSaveReport,
           JsonReport.State(GarbageCollect,
-          `reference-generations` = TreeSet(generation),
-          `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration),
-          blobs = Seq[JsonReport.BlobId](JsonReport.BlobId(blobId.asString, blobId.generation)),
-          references = Seq(JsonReport.Reference(externalId.id, blobId.asString, generation)),
-          deletions = Nil )))
+            `reference-generations` = TreeSet(generation),
+            `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration),
+            blobs = Seq[JsonReport.BlobId](JsonReport.BlobId(blobId.asString, blobId.generation)),
+            references = Seq(JsonReport.Reference(externalId.id, blobId.asString, generation)),
+            dereferences = Nil)))
       }
 
       "one reference is added then removed" in {
         val reference = Reference(externalId, blobId, generation)
         GCJsonReporter.report(ReferenceEvent(reference) :: DereferenceEvent(Dereference(generation, reference)) :: GCIterationEvent(gcReportImmediate) :: Nil)
-          .states should be (Seq(
+          .states should be(Seq(
           initialReport,
           firstSaveReport,
           firstDeleteReport,
@@ -100,20 +101,20 @@ class GCJsonReporterTest extends AnyWordSpec with Matchers {
             `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration),
             blobs = Seq[JsonReport.BlobId](JsonReport.BlobId(blobId.asString, blobId.generation)),
             references = Seq(JsonReport.Reference(externalId.id, blobId.asString, generation)),
-            deletions = Seq(JsonReport.Dereference(blobId.asString(), generation, initialIteration)))))
+            dereferences = Seq(JsonReport.Dereference(blobId.asString(), generation, initialIteration)))))
       }
     }
 
     "GC has been ran" when {
       "report added and removed references" when {
-        "one reference is added then removed and the GC is ran 2 generation later" in {
+        "one reference is added then removed and the GC is run 2 generations later" in {
           val reference = Reference(externalId, blobId, generation)
           val gcReportGenNPlus2 = GC.plan(StabilizedState(Map(generation -> List(reference)), Map(generation -> List(Dereference(generation, reference)))),
             lastIteration = Iteration.initial,
             targetedGeneration = generation.next(2))
 
           GCJsonReporter.report(ReferenceEvent(reference) :: DereferenceEvent(Dereference(generation, reference)) :: GCIterationEvent(gcReportGenNPlus2) :: Nil)
-            .states should be (Seq(
+            .states should be(Seq(
             initialReport,
             firstSaveReport,
             firstDeleteReport,
@@ -122,10 +123,10 @@ class GCJsonReporterTest extends AnyWordSpec with Matchers {
               `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration),
               blobs = Nil,
               references = Nil,
-              deletions = Nil )))
+              dereferences = Nil)))
         }
 
-        "one reference is added, a gc run two generation later, then  it is removed and the GC is ran again" in {
+        "one reference is added, a gc run two generations later, then it is removed and the GC is run again" in {
           val reference = Reference(externalId, blobId, generation)
           val gcReportGenNPlus2 = GC.plan(StabilizedState(Map(generation -> List(reference)), Map.empty),
             lastIteration = Iteration.initial,
@@ -138,7 +139,7 @@ class GCJsonReporterTest extends AnyWordSpec with Matchers {
             targetedGeneration = generationPlusOne.next(2))
 
           GCJsonReporter.report(ReferenceEvent(reference) :: GCIterationEvent(gcReportGenNPlus2) :: DereferenceEvent(dereference) :: GCIterationEvent(gcReportGenNPlus3) :: Nil)
-            .states should be (Seq(
+            .states should be(Seq(
             initialReport,
             firstSaveReport,
             //first gc
@@ -147,32 +148,31 @@ class GCJsonReporterTest extends AnyWordSpec with Matchers {
               `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration),
               blobs = Seq[JsonReport.BlobId](JsonReport.BlobId(blobId.asString, blobId.generation)),
               references = Seq(JsonReport.Reference(externalId.id, blobId.asString, generation)),
-              deletions = Nil),
+              dereferences = Nil),
             //delete
-            JsonReport.State(Delete(externalId),
+            JsonReport.State(RelatedAction.Dereference(externalId),
               `reference-generations` = TreeSet(generation, generationPlusOne),
               `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration),
               blobs = Seq[JsonReport.BlobId](JsonReport.BlobId(blobId.asString, blobId.generation)),
               references = Seq(JsonReport.Reference(externalId.id, blobId.asString, generation)),
-              deletions = Seq(JsonReport.Dereference(blobId.asString(), generationPlusOne, gcReportGenNPlus2.iteration.asString))),
+              dereferences = Seq(JsonReport.Dereference(blobId.asString(), generationPlusOne, gcReportGenNPlus2.iteration.asString))),
             //second gc
             JsonReport.State(GarbageCollect,
               `reference-generations` = TreeSet(generation, generationPlusOne),
               `garbage-collection-iterations` = TreeSet(initialIteration, firstIteration, gcReportGenNPlus3.iteration.asString),
               blobs = Nil,
               references = Nil,
-              deletions = Nil)))
+              dereferences = Nil)))
         }
 
 
-
         "json serialization" in {
           val reference = Reference(externalId, blobId, generation)
           val gcReportGenNPlus2 = GC.plan(StabilizedState(Map(generation -> List(reference)), Map.empty),
             lastIteration = Iteration.initial,
             targetedGeneration = generation.next(2))
 
-          val generationPlusOne= generation.next
+          val generationPlusOne = generation.next
           val dereference = Dereference(generation.next, reference)
           val gcReportGenNPlus3 = GC.plan(StabilizedState(Map(generation -> List(reference)), Map(generationPlusOne -> List(dereference))),
             lastIteration = gcReportGenNPlus2.iteration,


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org