1 // Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
2 // All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
10 . "github.com/onsi/ginkgo"
11 . "github.com/onsi/gomega"
13 "github.com/syndtr/goleveldb/leveldb/opt"
14 "github.com/syndtr/goleveldb/leveldb/testutil"
17 var _ = testutil.Defer(func() {
18 Describe("Leveldb external", func() {
20 DisableBlockCache: true,
21 BlockRestartInterval: 5,
23 Compression: opt.NoCompression,
24 OpenFilesCacheCapacity: -1,
25 Strict: opt.StrictAll,
27 CompactionTableSize: 2000,
30 Describe("write test", func() {
31 It("should do write correctly", func(done Done) {
32 db := newTestingDB(o, nil, nil)
33 t := testutil.DBTesting{
35 Deleted: testutil.KeyValue_Generate(nil, 500, 1, 1, 50, 5, 5).Clone(),
37 testutil.DoDBTesting(&t)
43 Describe("read test", func() {
44 testutil.AllKeyValueTesting(nil, nil, func(kv testutil.KeyValue) testutil.DB {
46 db := newTestingDB(o, nil, nil)
47 kv.IterateShuffled(nil, func(i int, key, value []byte) {
48 err := db.TestPut(key, value)
49 Expect(err).NotTo(HaveOccurred())
53 }, func(db testutil.DB) {
54 db.(*testingDB).TestClose()
58 Describe("transaction test", func() {
59 It("should do transaction correctly", func(done Done) {
60 db := newTestingDB(o, nil, nil)
62 By("creating first transaction")
64 tr := &testingTransaction{}
65 tr.Transaction, err = db.OpenTransaction()
66 Expect(err).NotTo(HaveOccurred())
67 t0 := &testutil.DBTesting{
69 Deleted: testutil.KeyValue_Generate(nil, 200, 1, 1, 50, 5, 5).Clone(),
71 testutil.DoDBTesting(t0)
72 testutil.TestGet(tr, t0.Present)
73 testutil.TestHas(tr, t0.Present)
75 By("committing first transaction")
77 Expect(err).NotTo(HaveOccurred())
78 testutil.TestIter(db, nil, t0.Present)
79 testutil.TestGet(db, t0.Present)
80 testutil.TestHas(db, t0.Present)
82 By("manipulating DB without transaction")
84 testutil.DoDBTesting(t0)
86 By("creating second transaction")
87 tr.Transaction, err = db.OpenTransaction()
88 Expect(err).NotTo(HaveOccurred())
89 t1 := &testutil.DBTesting{
91 Deleted: t0.Deleted.Clone(),
92 Present: t0.Present.Clone(),
94 testutil.DoDBTesting(t1)
95 testutil.TestIter(db, nil, t0.Present)
97 By("discarding second transaction")
99 testutil.TestIter(db, nil, t0.Present)
101 By("creating third transaction")
102 tr.Transaction, err = db.OpenTransaction()
103 Expect(err).NotTo(HaveOccurred())
105 testutil.DoDBTesting(t0)
107 By("committing third transaction")
109 Expect(err).NotTo(HaveOccurred())
110 testutil.TestIter(db, nil, t0.Present)