From 21daa03a2fd389beeb785a4569ea45fd23264f60 Mon Sep 17 00:00:00 2001 From: Jim Menard Date: Thu, 5 Feb 2009 14:47:33 -0500 Subject: [PATCH] new test; added self-test initialization for each test --- tests/mongo-qa/admin | 6 +++++- tests/mongo-qa/capped | 5 +++++ tests/mongo-qa/circular | 4 ++++ tests/mongo-qa/count1 | 8 ++++++++ tests/mongo-qa/dbs | 22 ++++++++++++++++++++++ tests/mongo-qa/find | 4 ++++ tests/mongo-qa/find1 | 8 ++++++++ tests/mongo-qa/indices | 7 +++++++ tests/mongo-qa/remove | 10 ++++++++++ tests/mongo-qa/stress1 | 4 ++++ tests/mongo-qa/test1 | 6 +++++- tests/mongo-qa/update | 11 ++++++++--- 12 files changed, 90 insertions(+), 5 deletions(-) create mode 100755 tests/mongo-qa/dbs diff --git a/tests/mongo-qa/admin b/tests/mongo-qa/admin index 5e41cf7..fcba1fb 100755 --- a/tests/mongo-qa/admin +++ b/tests/mongo-qa/admin @@ -4,9 +4,13 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) db.collection('test').insert({'test' => 1}) - admin = db.admin +if __FILE__ == $0 + db.drop_collection('tester') + admin.profiling_level = :slow_only +end + ['test', 'pdlskwmf', '$'].each { |name| begin admin.validate_collection(name) diff --git a/tests/mongo-qa/capped b/tests/mongo-qa/capped index 31ef1b7..85b8fa5 100755 --- a/tests/mongo-qa/capped +++ b/tests/mongo-qa/capped @@ -3,6 +3,11 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +if __FILE__ == $0 + db.drop_collection('capped1') + db.drop_collection('capped2') +end + db.create_collection('capped1', :capped => true, :size => 500) coll = db.collection('capped1') coll.insert('x' => 1) diff --git a/tests/mongo-qa/circular b/tests/mongo-qa/circular index a8c0d10..4c99ff6 100755 --- a/tests/mongo-qa/circular +++ b/tests/mongo-qa/circular @@ -3,6 +3,10 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +if __FILE__ == $0 + %w(a b c).each { |name| db.drop_collection(name) } +end + colla = db.collection('a') collb = db.collection('b') collc = db.collection('c') diff --git a/tests/mongo-qa/count1 b/tests/mongo-qa/count1 index 745b941..6465b55 100755 --- a/tests/mongo-qa/count1 +++ b/tests/mongo-qa/count1 @@ -3,6 +3,14 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +if __FILE__ == $0 + 3.times { |i| db.drop_collection("test#{i+1}") } + db.create_collection('test1') + db.collection('test2').insert({:name => 'a'}) + c = db.collection('test3') + 100.times { |i| c.insert(:i => i, :foo => 'bar') } +end + puts db.collection('test1').count puts db.collection('test2').count puts db.collection('test3').count('i' => 'a') diff --git a/tests/mongo-qa/dbs b/tests/mongo-qa/dbs new file mode 100755 index 0000000..a82d8f9 --- /dev/null +++ b/tests/mongo-qa/dbs @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +require File.join(File.dirname(__FILE__), '_common.rb') +db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) + +if __FILE__ == $0 + 3.times { |i| db.drop_collection("dbs_#{i+1}") } +end + +def print_dbs_names(db) + db.collection_names.select{ |n| n =~ /\.dbs/ }.sort.each { |name| + puts name.sub(/^#{db.name}\./, '') + } +end + +db.collection('dbs_1').insert('foo' => 'bar') +db.collection('dbs_2').insert('psi' => 'phi') +puts db.name +print_dbs_names(db) +db.drop_collection('dbs_1') +db.create_collection('dbs_3') +print_dbs_names(db) diff --git a/tests/mongo-qa/find b/tests/mongo-qa/find index 0ff7f4b..2b948b0 100755 --- a/tests/mongo-qa/find +++ b/tests/mongo-qa/find @@ -3,4 +3,8 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +if __FILE__ == $0 + db.drop_collection('test') +end + db.collection('test').insert('a' => 2) diff --git a/tests/mongo-qa/find1 b/tests/mongo-qa/find1 index aee9c5a..f45ce1f 100755 --- a/tests/mongo-qa/find1 +++ b/tests/mongo-qa/find1 @@ -3,5 +3,13 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +if __FILE__ == $0 + db.drop_collection('c') + c = db.collection('c') + (5..15).each { |i| c.insert(:x => 0, :y => i, :z => (i+64).chr) } + (1..50).each { |i| c.insert(:x => 1, :y => i, :z => (i+64).chr) } + (5..15).each { |i| c.insert(:x => 2, :y => i, :z => (i+64).chr) } +end + cursor = db.collection('c').find({'x' => 1}, :sort => 'y', :offset => 20, :limit => 10) cursor.each { |row| puts row['z'] } diff --git a/tests/mongo-qa/indices b/tests/mongo-qa/indices index 9b82ea1..6a37f7f 100755 --- a/tests/mongo-qa/indices +++ b/tests/mongo-qa/indices @@ -5,6 +5,13 @@ db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) x = db.collection('x') y = db.collection('y') +if __FILE__ == $0 + x.drop + x.insert('field1' => 'f1', 'field2' => 'f2') + x.create_index('field1', 'field1') + x.create_index('field2', 'field2') +end + def print_sorted_info_keys(info) puts info[:keys].keys.sort.collect { |key| "#{key}_1" }.join("_") end diff --git a/tests/mongo-qa/remove b/tests/mongo-qa/remove index 7241c8d..cb9fa88 100755 --- a/tests/mongo-qa/remove +++ b/tests/mongo-qa/remove @@ -3,5 +3,15 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) +if __FILE__ == $0 + c = db.collection('remove1') + 50.times { |i| c.insert(:a => i) } + c = db.collection('remove2') + c.insert(:a => 3, :b => 1) + c.insert(:a => 3, :b => 3) + c.insert(:a => 2, :b => 3) + c.insert(:b => 3) +end + db.collection('remove1').clear db.collection('remove2').remove('a' => 3) diff --git a/tests/mongo-qa/stress1 b/tests/mongo-qa/stress1 index d93f1ab..46ba4c3 100755 --- a/tests/mongo-qa/stress1 +++ b/tests/mongo-qa/stress1 @@ -6,6 +6,10 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) c = db.collection('stress1') +if __FILE__ == $0 + c.drop +end + 50000.times { |i| c.insert(:name => "asdf#{i}", :date => Time.now, :_id => i, :blah => LONG_STRING, :subarray => []) diff --git a/tests/mongo-qa/test1 b/tests/mongo-qa/test1 index a0b0dda..667babf 100755 --- a/tests/mongo-qa/test1 +++ b/tests/mongo-qa/test1 @@ -2,6 +2,10 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) - coll = db.collection('part1') + +if __FILE__ == $0 + coll.drop +end + 100.times { |i| coll.insert('x' => i) } diff --git a/tests/mongo-qa/update b/tests/mongo-qa/update index 5249341..562c12b 100755 --- a/tests/mongo-qa/update +++ b/tests/mongo-qa/update @@ -4,6 +4,11 @@ require File.join(File.dirname(__FILE__), '_common.rb') db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) foo = db.collection('foo') -foo.update({:x => 1}, {:x => 1, :y => 2}) -foo.update({:x => 2}, {:x => 1, :y => 7}) -foo.update({:x => 3}, {:x => 4, :y => 1}) +if __FILE__ == $0 + foo.drop + foo.insert(:x => 1) +end + +foo.replace({:x => 1}, {:x => 1, :y => 2}) +foo.replace({:x => 2}, {:x => 1, :y => 7}) +foo.replace({:x => 3}, {:x => 4, :y => 1})