github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/syndtr/goleveldb/leveldb/external_test.go (about) 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 7 package leveldb 8 9 import ( 10 . "github.com/insionng/yougam/libraries/onsi/ginkgo" 11 . "github.com/insionng/yougam/libraries/onsi/gomega" 12 13 "github.com/insionng/yougam/libraries/syndtr/goleveldb/leveldb/opt" 14 "github.com/insionng/yougam/libraries/syndtr/goleveldb/leveldb/testutil" 15 ) 16 17 var _ = testutil.Defer(func() { 18 Describe("Leveldb external", func() { 19 o := &opt.Options{ 20 DisableBlockCache: true, 21 BlockRestartInterval: 5, 22 BlockSize: 80, 23 Compression: opt.NoCompression, 24 OpenFilesCacheCapacity: -1, 25 Strict: opt.StrictAll, 26 WriteBuffer: 1000, 27 CompactionTableSize: 2000, 28 } 29 30 Describe("write test", func() { 31 It("should do write correctly", func(done Done) { 32 db := newTestingDB(o, nil, nil) 33 t := testutil.DBTesting{ 34 DB: db, 35 Deleted: testutil.KeyValue_Generate(nil, 500, 1, 50, 5, 5).Clone(), 36 } 37 testutil.DoDBTesting(&t) 38 db.TestClose() 39 done <- true 40 }, 20.0) 41 }) 42 43 Describe("read test", func() { 44 testutil.AllKeyValueTesting(nil, nil, func(kv testutil.KeyValue) testutil.DB { 45 // Building the 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()) 50 }) 51 52 return db 53 }, func(db testutil.DB) { 54 db.(*testingDB).TestClose() 55 }) 56 }) 57 58 Describe("transaction test", func() { 59 It("should do transaction correctly", func(done Done) { 60 db := newTestingDB(o, nil, nil) 61 62 By("creating first transaction") 63 var err error 64 tr := &testingTransaction{} 65 tr.Transaction, err = db.OpenTransaction() 66 Expect(err).NotTo(HaveOccurred()) 67 t0 := &testutil.DBTesting{ 68 DB: tr, 69 Deleted: testutil.KeyValue_Generate(nil, 200, 1, 50, 5, 5).Clone(), 70 } 71 testutil.DoDBTesting(t0) 72 testutil.TestGet(tr, t0.Present) 73 testutil.TestHas(tr, t0.Present) 74 75 By("committing first transaction") 76 err = tr.Commit() 77 Expect(err).NotTo(HaveOccurred()) 78 testutil.TestIter(db, nil, t0.Present) 79 testutil.TestGet(db, t0.Present) 80 testutil.TestHas(db, t0.Present) 81 82 By("manipulating DB without transaction") 83 t0.DB = db 84 testutil.DoDBTesting(t0) 85 86 By("creating second transaction") 87 tr.Transaction, err = db.OpenTransaction() 88 Expect(err).NotTo(HaveOccurred()) 89 t1 := &testutil.DBTesting{ 90 DB: tr, 91 Deleted: t0.Deleted.Clone(), 92 Present: t0.Present.Clone(), 93 } 94 testutil.DoDBTesting(t1) 95 testutil.TestIter(db, nil, t0.Present) 96 97 By("discarding second transaction") 98 tr.Discard() 99 testutil.TestIter(db, nil, t0.Present) 100 101 By("creating third transaction") 102 tr.Transaction, err = db.OpenTransaction() 103 Expect(err).NotTo(HaveOccurred()) 104 t0.DB = tr 105 testutil.DoDBTesting(t0) 106 107 By("committing third transaction") 108 err = tr.Commit() 109 Expect(err).NotTo(HaveOccurred()) 110 testutil.TestIter(db, nil, t0.Present) 111 112 db.TestClose() 113 done <- true 114 }, 30.0) 115 }) 116 }) 117 })