You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.1 KiB

  1. // Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license that can be
  5. // found in the LICENSE file.
  6. package leveldb
  7. import (
  8. . "github.com/onsi/ginkgo"
  9. . "github.com/onsi/gomega"
  10. "github.com/syndtr/goleveldb/leveldb/opt"
  11. "github.com/syndtr/goleveldb/leveldb/testutil"
  12. )
  13. var _ = testutil.Defer(func() {
  14. Describe("Leveldb external", func() {
  15. o := &opt.Options{
  16. DisableBlockCache: true,
  17. BlockRestartInterval: 5,
  18. BlockSize: 80,
  19. Compression: opt.NoCompression,
  20. OpenFilesCacheCapacity: -1,
  21. Strict: opt.StrictAll,
  22. WriteBuffer: 1000,
  23. CompactionTableSize: 2000,
  24. }
  25. Describe("write test", func() {
  26. It("should do write correctly", func(done Done) {
  27. db := newTestingDB(o, nil, nil)
  28. t := testutil.DBTesting{
  29. DB: db,
  30. Deleted: testutil.KeyValue_Generate(nil, 500, 1, 1, 50, 5, 5).Clone(),
  31. }
  32. testutil.DoDBTesting(&t)
  33. db.TestClose()
  34. done <- true
  35. }, 80.0)
  36. })
  37. Describe("read test", func() {
  38. testutil.AllKeyValueTesting(nil, nil, func(kv testutil.KeyValue) testutil.DB {
  39. // Building the DB.
  40. db := newTestingDB(o, nil, nil)
  41. kv.IterateShuffled(nil, func(i int, key, value []byte) {
  42. err := db.TestPut(key, value)
  43. Expect(err).NotTo(HaveOccurred())
  44. })
  45. return db
  46. }, func(db testutil.DB) {
  47. db.(*testingDB).TestClose()
  48. })
  49. })
  50. Describe("transaction test", func() {
  51. It("should do transaction correctly", func(done Done) {
  52. db := newTestingDB(o, nil, nil)
  53. By("creating first transaction")
  54. var err error
  55. tr := &testingTransaction{}
  56. tr.Transaction, err = db.OpenTransaction()
  57. Expect(err).NotTo(HaveOccurred())
  58. t0 := &testutil.DBTesting{
  59. DB: tr,
  60. Deleted: testutil.KeyValue_Generate(nil, 200, 1, 1, 50, 5, 5).Clone(),
  61. }
  62. testutil.DoDBTesting(t0)
  63. testutil.TestGet(tr, t0.Present)
  64. testutil.TestHas(tr, t0.Present)
  65. By("committing first transaction")
  66. err = tr.Commit()
  67. Expect(err).NotTo(HaveOccurred())
  68. testutil.TestIter(db, nil, t0.Present)
  69. testutil.TestGet(db, t0.Present)
  70. testutil.TestHas(db, t0.Present)
  71. By("manipulating DB without transaction")
  72. t0.DB = db
  73. testutil.DoDBTesting(t0)
  74. By("creating second transaction")
  75. tr.Transaction, err = db.OpenTransaction()
  76. Expect(err).NotTo(HaveOccurred())
  77. t1 := &testutil.DBTesting{
  78. DB: tr,
  79. Deleted: t0.Deleted.Clone(),
  80. Present: t0.Present.Clone(),
  81. }
  82. testutil.DoDBTesting(t1)
  83. testutil.TestIter(db, nil, t0.Present)
  84. By("discarding second transaction")
  85. tr.Discard()
  86. testutil.TestIter(db, nil, t0.Present)
  87. By("creating third transaction")
  88. tr.Transaction, err = db.OpenTransaction()
  89. Expect(err).NotTo(HaveOccurred())
  90. t0.DB = tr
  91. testutil.DoDBTesting(t0)
  92. By("committing third transaction")
  93. err = tr.Commit()
  94. Expect(err).NotTo(HaveOccurred())
  95. testutil.TestIter(db, nil, t0.Present)
  96. db.TestClose()
  97. done <- true
  98. }, 240.0)
  99. })
  100. })
  101. })