|
19 | 19 |
|
20 | 20 | package swaydb.core.level |
21 | 21 |
|
22 | | -import java.nio.file.{Files, NoSuchFileException} |
| 22 | +import java.nio.file.NoSuchFileException |
23 | 23 |
|
24 | 24 | import org.scalamock.scalatest.MockFactory |
25 | 25 | import org.scalatest.PrivateMethodTester |
26 | | -import swaydb.core.TestBase |
| 26 | +import swaydb.core.{TestBase, TestQueues} |
27 | 27 | import swaydb.core.actor.TestActor |
28 | 28 | import swaydb.core.data.Transient.Delete |
29 | 29 | import swaydb.core.data._ |
30 | 30 | import swaydb.core.io.file.{DBFile, IO} |
31 | 31 | import swaydb.core.level.actor.LevelAPI |
32 | | -import swaydb.core.level.actor.LevelCommand.{PullRequest, PushMap, PushSegments, PushSegmentsResponse} |
33 | | -import swaydb.core.map.{Map, MapEntry} |
| 32 | +import swaydb.core.level.actor.LevelCommand.{PushSegments, PushSegmentsResponse} |
34 | 33 | import swaydb.core.map.serializer.{KeyValuesMapSerializer, SegmentsMapSerializer} |
| 34 | +import swaydb.core.map.{Map, MapEntry} |
35 | 35 | import swaydb.core.segment.Segment |
36 | 36 | import swaydb.core.util.Extension |
37 | 37 | import swaydb.core.util.FileUtil._ |
| 38 | +import swaydb.core.util.PipeOps._ |
38 | 39 | import swaydb.data.compaction.Throttle |
| 40 | +import swaydb.data.config.Dir |
39 | 41 | import swaydb.data.slice.Slice |
| 42 | +import swaydb.data.storage.LevelStorage |
40 | 43 | import swaydb.data.util.StorageUnits._ |
41 | 44 | import swaydb.order.KeyOrder |
42 | 45 | import swaydb.serializers.Default._ |
43 | | -import swaydb.core.util.PipeOps._ |
44 | | -import swaydb.data.config.{Dir, RecoveryMode} |
45 | | -import swaydb.data.storage.LevelStorage |
46 | 46 | import swaydb.serializers._ |
47 | 47 |
|
48 | 48 | import scala.collection.mutable.ListBuffer |
@@ -79,8 +79,8 @@ class LevelWriteSpec extends TestBase with MockFactory with PrivateMethodTester |
79 | 79 | // override def deleteFiles: Boolean = |
80 | 80 | // false |
81 | 81 |
|
82 | | - implicit val maxSegmentsOpenCacheImplicitLimiter: DBFile => Unit = fileOpenLimiter |
83 | | - implicit val keyValuesLimitImplicitLimiter: (PersistentReadOnly, Segment) => Unit = keyValueLimiter |
| 82 | + implicit val maxSegmentsOpenCacheImplicitLimiter: DBFile => Unit = TestQueues.fileOpenLimiter |
| 83 | + implicit val keyValuesLimitImplicitLimiter: (PersistentReadOnly, Segment) => Unit = TestQueues.keyValueLimiter |
84 | 84 |
|
85 | 85 | "Level" should { |
86 | 86 | "initialise" in { |
@@ -307,57 +307,59 @@ class LevelWriteSpec extends TestBase with MockFactory with PrivateMethodTester |
307 | 307 | } |
308 | 308 |
|
309 | 309 | "distribute Segments to multiple directories based on the distribution ratio" in { |
310 | | - val dir = testDir.resolve("distributeSegmentsTest") |
311 | | - |
312 | | - def assertDistribution = { |
313 | | - dir.resolve(1.toString).files(Extension.Seg) should have size 7 |
314 | | - dir.resolve(2.toString).files(Extension.Seg) should have size 14 |
315 | | - dir.resolve(3.toString).files(Extension.Seg) should have size 21 |
316 | | - dir.resolve(4.toString).files(Extension.Seg) should have size 28 |
317 | | - dir.resolve(5.toString).files(Extension.Seg) should have size 30 |
318 | | - } |
| 310 | + if (persistent) { |
| 311 | + val dir = testDir.resolve("distributeSegmentsTest") |
| 312 | + |
| 313 | + def assertDistribution = { |
| 314 | + dir.resolve(1.toString).files(Extension.Seg) should have size 7 |
| 315 | + dir.resolve(2.toString).files(Extension.Seg) should have size 14 |
| 316 | + dir.resolve(3.toString).files(Extension.Seg) should have size 21 |
| 317 | + dir.resolve(4.toString).files(Extension.Seg) should have size 28 |
| 318 | + dir.resolve(5.toString).files(Extension.Seg) should have size 30 |
| 319 | + } |
319 | 320 |
|
320 | | - val storage = |
321 | | - LevelStorage.Persistent( |
322 | | - mmapSegmentsOnWrite = mmapSegmentsOnWrite, |
323 | | - mmapSegmentsOnRead = mmapSegmentsOnRead, |
324 | | - dir = dir.resolve(1.toString), |
325 | | - otherDirs = |
326 | | - Seq( |
327 | | - Dir(dir.resolve(2.toString), 2), |
328 | | - Dir(dir.resolve(3.toString), 3), |
329 | | - Dir(dir.resolve(4.toString), 4), |
330 | | - Dir(dir.resolve(5.toString), 5) |
331 | | - ) |
332 | | - ) |
333 | | - val keyValues = randomIntKeyStringValues(keyValuesCount, valueSize = 1000) |
334 | | - |
335 | | - val level = TestLevel(throttle = (_) => Throttle(Duration.Zero, 0), segmentSize = 1.byte, levelStorage = storage) |
| 321 | + val storage = |
| 322 | + LevelStorage.Persistent( |
| 323 | + mmapSegmentsOnWrite = mmapSegmentsOnWrite, |
| 324 | + mmapSegmentsOnRead = mmapSegmentsOnRead, |
| 325 | + dir = dir.resolve(1.toString), |
| 326 | + otherDirs = |
| 327 | + Seq( |
| 328 | + Dir(dir.resolve(2.toString), 2), |
| 329 | + Dir(dir.resolve(3.toString), 3), |
| 330 | + Dir(dir.resolve(4.toString), 4), |
| 331 | + Dir(dir.resolve(5.toString), 5) |
| 332 | + ) |
| 333 | + ) |
| 334 | + val keyValues = randomIntKeyStringValues(keyValuesCount, valueSize = 1000) |
| 335 | + |
| 336 | + val level = TestLevel(throttle = (_) => Throttle(Duration.Zero, 0), segmentSize = 1.byte, levelStorage = storage) |
336 | 337 |
|
337 | | - level.putKeyValues(keyValues).assertGet |
338 | | - level.segmentsCount() shouldBe 100 |
339 | | - assertDistribution |
| 338 | + level.putKeyValues(keyValues).assertGet |
| 339 | + level.segmentsCount() shouldBe 100 |
| 340 | + assertDistribution |
340 | 341 |
|
341 | | - //write the same key-values again so that all Segments are updated. This should still maintain the Segment distribution |
342 | | - level.putKeyValues(keyValues).assertGet |
343 | | - assertDistribution |
| 342 | + //write the same key-values again so that all Segments are updated. This should still maintain the Segment distribution |
| 343 | + level.putKeyValues(keyValues).assertGet |
| 344 | + assertDistribution |
344 | 345 |
|
345 | | - //shuffle key-values should still maintain distribution order |
346 | | - Random.shuffle(keyValues.grouped(10).map(_.updateStats)).foreach { |
347 | | - keyValues => |
348 | | - level.putKeyValues(keyValues).assertGet |
349 | | - } |
350 | | - assertDistribution |
| 346 | + //shuffle key-values should still maintain distribution order |
| 347 | + Random.shuffle(keyValues.grouped(10).map(_.updateStats)).foreach { |
| 348 | + keyValues => |
| 349 | + level.putKeyValues(keyValues).assertGet |
| 350 | + } |
| 351 | + assertDistribution |
351 | 352 |
|
352 | | - //delete some key-values |
353 | | - Random.shuffle(keyValues.grouped(10).map(_.updateStats)).take(2).foreach { |
354 | | - keyValues => |
355 | | - val deleteKeyValues = Slice(keyValues.map(keyValue => Delete(keyValue.key)).toArray).updateStats |
356 | | - level.putKeyValues(deleteKeyValues).assertGet |
357 | | - } |
| 353 | + //delete some key-values |
| 354 | + Random.shuffle(keyValues.grouped(10).map(_.updateStats)).take(2).foreach { |
| 355 | + keyValues => |
| 356 | + val deleteKeyValues = Slice(keyValues.map(keyValue => Delete(keyValue.key)).toArray).updateStats |
| 357 | + level.putKeyValues(deleteKeyValues).assertGet |
| 358 | + } |
358 | 359 |
|
359 | | - level.putKeyValues(keyValues).assertGet |
360 | | - assertDistribution |
| 360 | + level.putKeyValues(keyValues).assertGet |
| 361 | + assertDistribution |
| 362 | + } |
361 | 363 | } |
362 | 364 |
|
363 | 365 | "fail when writing a deleted segment" in { |
|
0 commit comments