public
Description: StrokeDB is an embeddable distributed document database written in Ruby
Homepage: http://strokedb.com/
Clone URL: git://github.com/yrashk/strokedb.git
oleganza (author)
Sun Jun 08 14:05:26 -0700 2008
commit  9785ab9c6245d9c23e95a0a1f04bb8c300984323
tree    bdf4d03182ec4efeb86d64cb1a95ee887eee9256
parent  ff4c04e1f3e2f65f3984ce9d75166278c1391118
strokedb / spec / lib / strokedb / volumes / skiplist_volume_spec.rb
100644 100 lines (79 sloc) 3.311 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
require File.dirname(__FILE__) + '/spec_helper'
 
describe "SkiplistVolume inserts and finds", :shared => true do
  it "should find & insert some data" do
    @volume.find("key").should == nil
    @volume.insert("key", "value")
    @volume.find("key").should == "value"
    @volume.insert("key2", "value2")
    @volume.find("key").should == "value"
    @volume.find("key2").should == "value2"
    @volume.insert("key", nil)
    @volume.find("key").should == nil
    @volume.find("key2").should == "value2"
  end
end
 
#Skiplist.with_optimizations(OPTIMIZATIONS) do |lang|
lang = "Ruby {FIXME: with_optimizations is irreversible operation for now}"
  describe "Brand new SkiplistVolume [#{lang}]" do
    before(:each) do
      @path = TEMP_STORAGES + '/skiplist_volume_files/volume'
      FileUtils.rm_rf(TEMP_STORAGES + '/skiplist_volume_files')
      @volume = SkiplistVolume.new(:path => @path, :max_log_size => 1024, :silent => true)
    end
    
    it "should be empty" do
      @volume.should be_empty
    end
    
    it_should_behave_like "SkiplistVolume inserts and finds"
  end
  
  describe "Brand new SkiplistVolume with immediate dumps [#{lang}]" do
    before(:each) do
      @path = TEMP_STORAGES + '/skiplist_volume_files/volume'
      FileUtils.rm_rf(TEMP_STORAGES + '/skiplist_volume_files')
      @volume = SkiplistVolume.new(:path => @path, :max_log_size => 0, :silent => true)
    end
    
    it "should be empty" do
      @volume.should be_empty
    end
    
    it_should_behave_like "SkiplistVolume inserts and finds"
  end
  
  describe "Dumping SkiplistVolume" do
    before(:each) do
      @path = TEMP_STORAGES + '/skiplist_volume_files/volume'
      FileUtils.rm_rf(TEMP_STORAGES + '/skiplist_volume_files')
      @volume = SkiplistVolume.new(:path => @path, :max_log_size => 1024, :silent => true)
    end
    
    it "should dump and load the dumped list" do
      @volume.insert("k", "v")
      @volume.insert("k2", "v2")
      
      @volume.close!
      @volume.find("k").should == "v"
      @volume.find("k2").should == "v2"
      
      lambda { @volume.insert("k3", "v3") }.should raise_error(SkiplistVolume::VolumeClosedException)
      @volume.find("k3").should == nil
      
      @volume = SkiplistVolume.new(:path => @path, :max_log_size => 1024, :silent => true)
      @volume.find("k").should == "v"
      @volume.find("k2").should == "v2"
      @volume.find("k3").should == nil
    end
    
    it "should store a lot of values" do
      @arr = (1..1000).to_a.map{|a| a.to_s}.sort
      
      @arr.each{|e| @volume.insert(e,e) }
      
      @volume.close!
      @volume = SkiplistVolume.new(:path => @path, :max_log_size => 1024, :silent => true)
      
      @arr.each{|e| @volume.find(e).should == e }
 
    end
  end
  
  describe "SkiplistVolume errors" do
    it "should throw an exception if the message is too big" do
      @volume = init_volume
      lambda {
        @volume.insert("key", "a"*SkiplistVolume::MAX_LOG_MSG_LENGTH)
      }.should raise_error(SkiplistVolume::MessageTooBig)
    end
    
    def init_volume
      @path = TEMP_STORAGES + '/skiplist_volume_files/volume'
      FileUtils.rm_rf(TEMP_STORAGES + '/skiplist_volume_files')
      SkiplistVolume.new(:path => @path, :max_log_size => 1024, :silent => true)
    end
    
  end
 
#end