~ubuntu-branches/ubuntu/trusty/ruby-ferret/trusty

« back to all changes in this revision

Viewing changes to test/unit/largefile/tc_largefile.rb

  • Committer: Bazaar Package Importer
  • Author(s): Antonio Terceiro
  • Date: 2011-07-28 00:02:49 UTC
  • Revision ID: james.westby@ubuntu.com-20110728000249-v0443y69ftcpxwi6
Tags: upstream-0.11.6
ImportĀ upstreamĀ versionĀ 0.11.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require File.dirname(__FILE__) + "/../../test_helper"
 
2
 
 
3
class SampleLargeTest < Test::Unit::TestCase
 
4
  include Ferret::Index
 
5
  include Ferret::Search
 
6
  include Ferret::Store
 
7
  include Ferret::Utils
 
8
  
 
9
  INDEX_DIR = File.dirname(__FILE__) + "/../../temp/largefile"
 
10
  RECORDS = 750
 
11
  RECORD_SIZE = 10e5
 
12
  
 
13
  def setup
 
14
    @index = Index.new(:path => INDEX_DIR, :create_if_missing => true, :key => :id)
 
15
    create_index! if @index.size == 0 or ENV["RELOAD_LARGE_INDEX"]
 
16
  end
 
17
 
 
18
  def test_file_index_created
 
19
    assert @index.size == RECORDS, "Index size should be #{RECORDS}, is #{@index.size}"
 
20
  end
 
21
  
 
22
  def test_keys_work
 
23
    @index << {:content => "foo", :id => RECORDS - 4}
 
24
    assert @index.size == RECORDS, "Index size should be #{RECORDS}, is #{@index.size}"
 
25
  end
 
26
  
 
27
  def test_read_file_after_two_gigs
 
28
    assert @index.reader[RECORDS - 5].load.is_a?Hash
 
29
  end
 
30
  
 
31
  def create_index!
 
32
    @@already_built_large_index ||= false
 
33
    return if @@already_built_large_index
 
34
    @@already_built_large_index = true
 
35
    a = "a"
 
36
    RECORDS.times { |i|
 
37
      seq = (a.succ! + " ") * RECORD_SIZE
 
38
      record = {:id => i, :content => seq}
 
39
        @index << record
 
40
        print "i"
 
41
        STDOUT.flush
 
42
    }
 
43
    puts "o"
 
44
    @index.optimize
 
45
  end
 
46
end