To edit pages or tickets please login with username/password: aaf/aaf

Changeset 272

Show
Ignore:
Timestamp:
11/17/07 20:36:16 (11 months ago)
Author:
jk
Message:

added search to smoke test

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/db/migrate/006_create_stats.rb

    r271 r272  
    22  def self.up 
    33    create_table :stats do |t| 
    4       t.integer :process_id, :records, :processing_time, :open_connections 
     4      t.integer :process_id, :processing_time, :open_connections 
     5      t.string :kind, :info 
    56      t.datetime :created_at 
    67    end 
     8    add_index :stats, 'kind' 
    79  end 
    810 
    911  def self.down 
     12    remove_index :stats, 'kind' 
    1013    drop_table :stats 
    1114  end 
  • trunk/demo/test/smoke/drb_smoke_test.rb

    r271 r272  
    88# AAF_REMOTE=true script/runner -e test test/smoke/drb_smoke_test.rb 
    99 
    10 RECORDS_PER_PROCESS = 100000 
    11 NUM_PROCESSES       = 10 
    12 NUM_RECORDS_PER_LOGENTRY = 100 
     10module DrbSmokeTest 
    1311 
    14 class DrbSmokeTest 
    15   def initialize(id) 
    16     @id = id 
    17   end 
    18   def self.count_connections 
    19     res = Content.connection.execute("show status where variable_name = 'Threads_connected'") 
    20     if res 
    21       res.fetch_row.last 
    22     else 
    23       "error getting connection count" 
     12  RECORDS_PER_PROCESS = 1000 
     13  NUM_PROCESSES       = 10 # should be an even number 
     14  NUM_RECORDS_PER_LOGENTRY = 10 
     15  NUM_DOCS = 100 
     16  NUM_TERMS = 1000 
     17 
     18  TIME_FACTOR = 1000.to_f / NUM_RECORDS_PER_LOGENTRY 
     19 
     20  class Words 
     21    DICTIONARY = '/usr/share/dict/words' 
     22    def initialize 
     23      @words = [] 
     24      File.open(DICTIONARY) do |file| 
     25        file.each_line do |word| 
     26          @words << word.strip unless word =~ /'/ 
     27        end 
     28      end 
     29    end 
     30 
     31    def to_s 
     32      "#{@words.size} words" 
     33    end 
     34 
     35    def random_word 
     36      @words[rand(@words.size)] 
    2437    end 
    2538  end 
    26   def run 
    27     @t1 = Time.now 
    28     RECORDS_PER_PROCESS.times do |i| 
    29       Content.create! :title => "process #{@id}", :description => "record #{i}\n#{'Lorem ipsum. ' * 100 }" 
    30       if i % NUM_RECORDS_PER_LOGENTRY == 0 
    31         time = Time.now - @t1 
    32         puts "#{@id}: #{i} records indexed, last 100 in #{time}" 
    33         Stats.create! :process_id => @id, :records => NUM_RECORDS_PER_LOGENTRY, :processing_time => time, :open_connections => self.class.count_connections 
     39 
     40  puts "compiling sample documents..." 
     41  WORDS = Words.new 
     42  puts WORDS 
     43  DOCUMENTS = [] 
     44 
     45  NUM_DOCS.times do 
     46    doc = '' 
     47    NUM_TERMS.times { doc << WORDS.random_word << ' ' } 
     48    DOCUMENTS << doc 
     49  end 
     50 
     51  def self.random_document 
     52    DOCUMENTS[rand(DOCUMENTS.size)] 
     53  end 
     54 
     55  puts "built #{NUM_DOCS} documents with an avg. size of #{DOCUMENTS.join.size / NUM_DOCS} Byte." 
     56 
     57  class Monitor 
     58    class << self 
     59      def count_connections 
     60        res = Content.connection.execute("show status where variable_name = 'Threads_connected'") 
     61        if res 
     62          res.fetch_row.last 
     63        else 
     64          "error getting connection count" 
     65        end 
     66      end 
     67      def running? 
     68        Stats.count_by_sql("select count(*) from stats where kind='finished'") < (NUM_PROCESSES/2) 
     69      end 
     70    end 
     71  end 
     72 
     73  class TestBase 
     74    def initialize(id) 
     75      @id = id 
     76      @t1 = Time.now 
     77    end 
     78 
     79    def get_time 
     80      returning(Time.now - @t1) do 
    3481        @t1 = Time.now 
     82      end 
     83    end 
     84 
     85  end 
     86 
     87  class Writer < TestBase 
     88    def run 
     89      RECORDS_PER_PROCESS.times do |i| 
     90        Content.create! :title => "record #{@id} / #{i}", :description => DrbSmokeTest::random_document 
     91        if i % NUM_RECORDS_PER_LOGENTRY == 0 
     92          # write stats 
     93          time = get_time 
     94          puts "#{@id}: #{i} records indexed, last #{NUM_RECORDS_PER_LOGENTRY} in #{time}" 
     95          Stats.create! :process_id => @id, :kind => 'write', :info => i,  
     96                        :processing_time => time * TIME_FACTOR, 
     97                        :open_connections => Monitor::count_connections 
     98        end 
     99      end 
     100      Stats.create! :process_id => @id, :kind => 'finished' 
     101    end 
     102  end 
     103 
     104  class Searcher < TestBase 
     105    def run 
     106      while Monitor::running? 
     107        t = Time.now 
     108        result = Content.find_with_ferret 'findme', :lazy => true 
     109        time = Time.now - t 
     110        Stats.create! :process_id => @id, :kind => 'search', :info => "total_hits: #{result.total_hits} ; results: #{result.size}",  
     111                      :processing_time => time * 1000, 
     112                      :open_connections => Monitor::count_connections 
     113        sleep 1 
     114      end 
     115    end 
     116 
     117  end 
     118 
     119  def self.run 
     120    @start = Time.now 
     121 
     122    NUM_PROCESSES.times do |i| 
     123      unless fork 
     124        @id = i 
     125        break 
     126      end 
     127    end 
     128 
     129    if @id 
     130      @id.even? ? Writer.new(@id).run : Searcher.new(@id).run 
     131    else 
     132 
     133      # create some records to search for 
     134      20.times do |i| 
     135        Content.create! :title => "to find #{i}", :description => ("findme #{i} " << random_document) 
     136      end 
     137 
     138      while true  
     139        puts "open connections: #{Monitor::count_connections}; time elapsed: #{Time.now - @start} seconds" 
     140        sleep 10  
    35141      end 
    36142    end 
     
    38144end 
    39145 
    40  
    41 #Content.delete_all 
    42  
    43 @start = Time.now 
    44  
    45 NUM_PROCESSES.times do |i| 
    46   unless fork 
    47     @id = i 
    48     break 
    49   end 
    50 end 
    51  
    52 if @id 
    53   DrbSmokeTest.new(@id).run 
    54 else 
    55   while true  
    56     puts "open connections: #{DrbSmokeTest::count_connections}; time elapsed: #{Time.now - @start} seconds" 
    57     sleep 10  
    58   end 
    59 end 
    60  
     146DrbSmokeTest::run 
  • trunk/demo/test/unit/content_test.rb

    r268 r272  
    763763  end 
    764764 
     765  def test_limits_and_offsets 
     766    more_contents 
     767    r = Content.find_with_ferret 'title' 
     768    assert_equal 30, r.total_hits 
     769    assert_equal 10, r.size 
     770 
     771    r = Content.find_with_ferret 'title', :limit => :all 
     772    assert_equal 30, r.total_hits 
     773    assert_equal 30, r.size 
     774  end 
     775 
    765776  def test_limits_and_offsets_with_ar_conditions 
    766777    more_contents 

To edit pages or tickets please login with username/password: aaf/aaf