예제 #1
0
		Describe("write test", func() {
			It("should do write correctly", func(done Done) {
				db := newTestingDB(o, nil, nil)
				t := testutil.DBTesting{
					DB:      db,
					Deleted: testutil.KeyValue_Generate(nil, 500, 1, 50, 5, 5).Clone(),
				}
				testutil.DoDBTesting(&t)
				db.TestClose()
				done <- true
			}, 9.0)
		})

		Describe("read test", func() {
			testutil.AllKeyValueTesting(nil, func(kv testutil.KeyValue) testutil.DB {
				// Building the DB.
				db := newTestingDB(o, nil, nil)
				kv.IterateShuffled(nil, func(i int, key, value []byte) {
					err := db.TestPut(key, value)
					Expect(err).NotTo(HaveOccurred())
				})
				testutil.Defer("teardown", func() {
					db.TestClose()
				})

				return db
			})
		})
	})
})
예제 #2
0
				// Building the table.
				tw := NewWriter(buf, o)
				kv.Iterate(func(i int, key, value []byte) {
					tw.Append(key, value)
				})
				tw.Close()

				// Opening the table.
				tr := NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()), nil, o)
				return tableWrapper{tr}
			}
			Test := func(kv *testutil.KeyValue, body func(r *Reader)) func() {
				return func() {
					db := Build(*kv)
					if body != nil {
						body(db.(tableWrapper).Reader)
					}
					testutil.KeyValueTesting(nil, db, *kv)
				}
			}

			testutil.AllKeyValueTesting(nil, Build)
			Describe("with one key per block", Test(testutil.KeyValue_Generate(nil, 9, 1, 10, 512, 512), func(r *Reader) {
				It("should have correct blocks number", func() {
					Expect(r.indexBlock.restartsLen).Should(Equal(9))
				})
			}))
		})
	})
})
예제 #3
0
			testutil.AllKeyValueTesting(nil, func(kv testutil.KeyValue) testutil.DB {
				// Building the DB.
				db := New(comparer.DefaultComparer, 0)
				kv.IterateShuffled(nil, func(i int, key, value []byte) {
					db.Put(key, value)
				})

				if kv.Len() > 1 {
					It("Should find correct keys with findLT", func() {
						testutil.ShuffledIndex(nil, kv.Len()-1, 1, func(i int) {
							key_, key, _ := kv.IndexInexact(i + 1)
							expectedKey, expectedValue := kv.Index(i)

							// Using key that exist.
							rkey, rvalue, err := db.TestFindLT(key)
							Expect(err).ShouldNot(HaveOccurred(), "Error for key %q -> %q", key, expectedKey)
							Expect(rkey).Should(Equal(expectedKey), "Key")
							Expect(rvalue).Should(Equal(expectedValue), "Value for key %q -> %q", key, expectedKey)

							// Using key that doesn't exist.
							rkey, rvalue, err = db.TestFindLT(key_)
							Expect(err).ShouldNot(HaveOccurred(), "Error for key %q (%q) -> %q", key_, key, expectedKey)
							Expect(rkey).Should(Equal(expectedKey))
							Expect(rvalue).Should(Equal(expectedValue), "Value for key %q (%q) -> %q", key_, key, expectedKey)
						})
					})
				}

				if kv.Len() > 0 {
					It("Should find last key with findLast", func() {
						key, value := kv.Index(kv.Len() - 1)
						rkey, rvalue, err := db.TestFindLast()
						Expect(err).ShouldNot(HaveOccurred())
						Expect(rkey).Should(Equal(key))
						Expect(rvalue).Should(Equal(value))
					})
				}

				return db
			})