File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
main/scala/org/mitchelllisle/analysers Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package org.mitchelllisle.analysers
33import org .apache .spark .sql .{DataFrame , functions => F }
44import org .apache .spark .sql .types ._
55import java .security .MessageDigest
6+ import java .time .Instant
67import scala .annotation .tailrec
78
89/** MerkleTreeAnalyser provides cryptographic proof capabilities for data retention and deletion verification.
@@ -14,7 +15,7 @@ object MerkleTree {
1415 rootHash : String ,
1516 recordCount : Long ,
1617 leafHashes : Seq [String ],
17- timestamp : Long = System .currentTimeMillis ()
18+ timestamp : Instant = Instant .now ()
1819 )
1920
2021 case class DeletionProof (
@@ -98,7 +99,7 @@ object MerkleTree {
9899 rootHash = rootHash,
99100 recordCount = recordCount,
100101 leafHashes = leafHashes,
101- timestamp = System .currentTimeMillis ()
102+ timestamp = Instant .now ()
102103 )
103104 }
104105
Original file line number Diff line number Diff line change 11import org .apache .spark .sql .DataFrame
22import org .mitchelllisle .analysers .MerkleTree
33import org .scalatest .flatspec .AnyFlatSpec
4+ import java .time .Instant
45
56class MerkleTreeTest extends AnyFlatSpec with SparkFunSuite {
67 import spark .implicits ._
@@ -21,7 +22,8 @@ class MerkleTreeTest extends AnyFlatSpec with SparkFunSuite {
2122 assert(proof.rootHash.nonEmpty)
2223 assert(proof.recordCount == 4 )
2324 assert(proof.leafHashes.length == 4 )
24- assert(proof.timestamp > 0 )
25+ assert(proof.timestamp.isInstanceOf [Instant ])
26+ assert(proof.timestamp.isBefore(Instant .now().plusSeconds(1 )))
2527 }
2628
2729 " apply" should " produce same result as createMerkleProof" in {
@@ -183,4 +185,14 @@ class MerkleTreeTest extends AnyFlatSpec with SparkFunSuite {
183185
184186 assert(hashes1.sameElements(hashes2))
185187 }
188+
189+ " timestamp" should " use proper Instant type and be recent" in {
190+ val beforeTime = Instant .now().minusSeconds(1 )
191+ val proof = MerkleTree .createMerkleProof(testData, columns, idColumn)
192+ val afterTime = Instant .now().plusSeconds(1 )
193+
194+ assert(proof.timestamp.isInstanceOf [Instant ])
195+ assert(proof.timestamp.isAfter(beforeTime))
196+ assert(proof.timestamp.isBefore(afterTime))
197+ }
186198}
You can’t perform that action at this time.
0 commit comments