new test; added self-test initialization for each test
This commit is contained in:
parent
547ee748ad
commit
21daa03a2f
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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)
|
|
@ -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)
|
||||
|
|
|
@ -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'] }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 => [])
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Reference in New Issue