Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rejigger tests to use /tmp and add many_key_test

  • Loading branch information...
commit 595e9f0a4536f02d9db263df895998fb2c79006b 1 parent 5975fd7
@wmorgan authored
Showing with 73 additions and 42 deletions.
  1. +27 −23 test/db_test.rb
  2. +26 −19 test/iteration_test.rb
  3. +20 −0 test/many_key_test.rb
View
50 test/db_test.rb
@@ -3,55 +3,59 @@
require 'fileutils'
class DBTest < Test::Unit::TestCase
- path = File.expand_path("../db_test.db", __FILE__)
- FileUtils.rm_rf path
- DB = LevelDB::DB.new(path)
+ DB_PATH = "/tmp/iteration.db"
+
+ def initialize(*a)
+ super
+ FileUtils.rm_rf DB_PATH
+ @db = LevelDB::DB.new DB_PATH
+ end
def test_get
- DB.put 'test:read', '1'
+ @db.put 'test:read', '1'
- assert_equal '1', DB.get('test:read')
- assert_equal '1', DB.get('test:read', :fill_cache => false)
- assert_equal '1', DB.get('test:read',
+ assert_equal '1', @db.get('test:read')
+ assert_equal '1', @db.get('test:read', :fill_cache => false)
+ assert_equal '1', @db.get('test:read',
:fill_cache => false,
:verify_checksums => true)
end
def test_put
- DB.put "test:async", "1"
- DB.put "test:sync", "1", :sync => true
+ @db.put "test:async", "1"
+ @db.put "test:sync", "1", :sync => true
- assert_equal "1", DB.get("test:async")
- assert_equal "1", DB.get("test:sync")
+ assert_equal "1", @db.get("test:async")
+ assert_equal "1", @db.get("test:sync")
end
def test_delete
- DB.put 'test:async', '1'
- DB.put 'test:sync', '1'
+ @db.put 'test:async', '1'
+ @db.put 'test:sync', '1'
- assert DB.delete("test:async")
- assert DB.delete("test:sync", :sync => true)
+ assert @db.delete("test:async")
+ assert @db.delete("test:sync", :sync => true)
end
def test_batch
- DB.put 'a', '1'
- DB.put 'b', '1'
+ @db.put 'a', '1'
+ @db.put 'b', '1'
- DB.batch do |b|
+ @db.batch do |b|
b.put 'a', 'batch'
b.delete 'b'
end
- assert_equal 'batch', DB.get('a')
- assert_nil DB.get('b')
+ assert_equal 'batch', @db.get('a')
+ assert_nil @db.get('b')
- DB.batch :sync => true do |b|
+ @db.batch :sync => true do |b|
b.put 'b', 'batch'
b.delete 'a'
end
- assert_equal 'batch', DB.get('b')
- assert_nil DB.get('a')
+ assert_equal 'batch', @db.get('b')
+ assert_nil @db.get('a')
end
end
View
45 test/iteration_test.rb
@@ -1,18 +1,25 @@
require 'test/unit'
require File.expand_path("../../lib/leveldb", __FILE__)
+require 'fileutils'
class IterationTest < Test::Unit::TestCase
- DB = LevelDB::DB.new(File.expand_path("../iteration.db", __FILE__))
- DB.put "a/1", "1"
- DB.put "b/1", "2"
- DB.put "b/2", "3"
- DB.put "b/3", "4"
- DB.put "c/1", "5"
+ DB_PATH = "/tmp/iteration.db"
+
+ def initialize(*a)
+ super
+ FileUtils.rm_rf DB_PATH
+ @db = LevelDB::DB.new DB_PATH
+ @db.put "a/1", "1"
+ @db.put "b/1", "2"
+ @db.put "b/2", "3"
+ @db.put "b/3", "4"
+ @db.put "c/1", "5"
+ end
def test_each
expected = %w(a/1 b/1 b/2 b/3 c/1)
keys = []
- DB.each do |key, value|
+ @db.each do |key, value|
keys << key
end
@@ -22,7 +29,7 @@ def test_each
def test_each_with_key_from
expected = %w(b/1 b/2 b/3 c/1)
keys = []
- DB.each(:from => 'b') do |key, value|
+ @db.each(:from => 'b') do |key, value|
keys << key
end
@@ -32,7 +39,7 @@ def test_each_with_key_from
def test_each_with_key_from_to
expected = %w(b/1 b/2 b/3)
keys = []
- DB.each(:from => 'b', :to => 'b/4') do |key, value|
+ @db.each(:from => 'b', :to => 'b/4') do |key, value|
keys << key
end
@@ -42,7 +49,7 @@ def test_each_with_key_from_to
def test_reverse_each
expected = %w(c/1 b/3 b/2 b/1 a/1)
keys = []
- DB.each(:reversed => true) do |key, value|
+ @db.each(:reversed => true) do |key, value|
keys << key
end
@@ -52,7 +59,7 @@ def test_reverse_each
def test_reverse_each_with_key_from
expected = %w(b/1 a/1)
keys = []
- DB.each(:from => 'b', :reversed => true) do |key, value|
+ @db.each(:from => 'b', :reversed => true) do |key, value|
keys << key
end
@@ -62,7 +69,7 @@ def test_reverse_each_with_key_from
def test_reverse_each_with_key_from_to
expected = %w(c/1 b/3 b/2 b/1)
keys = []
- DB.each(:from => 'c', :to => 'b', :reversed => true) do |key, value|
+ @db.each(:from => 'c', :to => 'b', :reversed => true) do |key, value|
keys << key
end
@@ -75,7 +82,7 @@ def test_iterator_reverse_each_with_key_from_to
keys = []
values = []
- iter = LevelDB::Iterator.new DB, :from => 'c', :to => 'b', :reversed => true
+ iter = LevelDB::Iterator.new @db, :from => 'c', :to => 'b', :reversed => true
iter.each do |key, value|
keys << key
values << value
@@ -90,7 +97,7 @@ def test_iterator_each
expected_values = %w(1 2 3 4 5)
keys = []
values = []
- iter = LevelDB::Iterator.new DB
+ iter = LevelDB::Iterator.new @db
iter.each do |key, value|
keys << key
values << value
@@ -101,7 +108,7 @@ def test_iterator_each
end
def test_iterator_peek
- iter = LevelDB::Iterator.new DB
+ iter = LevelDB::Iterator.new @db
assert_equal %w(a/1 1), iter.peek, iter.invalid_reason
assert_equal %w(a/1 1), iter.peek, iter.invalid_reason
assert_nil iter.scan
@@ -109,16 +116,16 @@ def test_iterator_peek
end
def test_iterator_init_with_default_options
- iter = LevelDB::Iterator.new DB
- assert_equal DB, iter.db
+ iter = LevelDB::Iterator.new @db
+ assert_equal @db, iter.db
assert_nil iter.from
assert_nil iter.to
assert !iter.reversed?
end
def test_iterator_init_with_options
- iter = LevelDB::Iterator.new DB, :from => 'abc', :to => 'def', :reversed => true
- assert_equal DB,iter.db
+ iter = LevelDB::Iterator.new @db, :from => 'abc', :to => 'def', :reversed => true
+ assert_equal @db,iter.db
assert_equal 'abc', iter.from
assert_equal 'def', iter.to
assert iter.reversed?
View
20 test/many_key_test.rb
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+require 'test/unit'
+require File.expand_path("../../lib/leveldb", __FILE__)
+require 'fileutils'
+
+class ManyKeyTest < Test::Unit::TestCase
+ DB_PATH = "/tmp/manykey.db"
+
+ def initialize(*a)
+ super
+ FileUtils.rm_rf DB_PATH
+ @db = LevelDB::DB.new DB_PATH
+ end
+
+ def test_get
+ 100_000.times { |x| @db.put x.to_s, "abcdefghijklmnopqrstuvwxyz" }
+ assert_equal 100_000, @db.size
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.