remove deprecated Admin class

This commit is contained in:
Kyle Banker 2010-02-23 13:12:14 -05:00
parent d6111f535c
commit b9e8bb4e03
3 changed files with 0 additions and 163 deletions

View File

@ -52,7 +52,6 @@ require 'mongo/util/conversions'
require 'mongo/util/server_version' require 'mongo/util/server_version'
require 'mongo/util/bson_ruby' require 'mongo/util/bson_ruby'
require 'mongo/admin'
require 'mongo/collection' require 'mongo/collection'
require 'mongo/connection' require 'mongo/connection'
require 'mongo/cursor' require 'mongo/cursor'

View File

@ -1,95 +0,0 @@
# --
# Copyright (C) 2008-2010 10gen Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ++
module Mongo
# @deprecated this class is deprecated. Methods defined here will
# henceforth be available in Mongo::DB.
class Admin
def initialize(db)
warn "The Admin class has been DEPRECATED. All admin methods now exist in DB."
@db = db
end
# Return the current database profiling level.
#
# @return [Symbol] :off, :slow_only, or :all
#
# @deprecated please use DB#profiling_level instead.
def profiling_level
warn "Admin#profiling_level has been DEPRECATED. Please use DB#profiling_level instead."
oh = OrderedHash.new
oh[:profile] = -1
doc = @db.command(oh)
raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc) && doc['was'].kind_of?(Numeric)
case doc['was'].to_i
when 0
:off
when 1
:slow_only
when 2
:all
else
raise "Error: illegal profiling level value #{doc['was']}"
end
end
# Set database profiling level to :off, :slow_only, or :all.
#
# @deprecated please use DB#profiling_level= instead.
def profiling_level=(level)
warn "Admin#profiling_level= has been DEPRECATED. Please use DB#profiling_level= instead."
oh = OrderedHash.new
oh[:profile] = case level
when :off
0
when :slow_only
1
when :all
2
else
raise "Error: illegal profiling level value #{level}"
end
doc = @db.command(oh)
raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc)
end
# Returns an array containing current profiling information.
#
# @deprecated please use DB#profiling_info instead.
def profiling_info
warn "Admin#profiling_info has been DEPRECATED. Please use DB#profiling_info instead."
Cursor.new(Collection.new(@db, DB::SYSTEM_PROFILE_COLLECTION), :selector => {}).to_a
end
# Validate a named collection by raising an exception if there is a
# problem or returning an interesting hash (see especially the
# 'result' string value) if all is well.
#
# @deprecated please use DB#validate_collection instead.
def validate_collection(name)
warn "Admin#validate_collection has been DEPRECATED. Please use DB#validate_collection instead."
doc = @db.command(:validate => name)
raise "Error with validate command: #{doc.inspect}" unless @db.ok?(doc)
result = doc['result']
raise "Error with validation data: #{doc.inspect}" unless result.kind_of?(String)
raise "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i
doc
end
end
end

View File

@ -1,67 +0,0 @@
require 'test/test_helper'
# NOTE: assumes Mongo is running
class AdminTest < Test::Unit::TestCase
include Mongo
@@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
@@coll = @@db.collection('test')
def setup
# Insert some data to make sure the database itself exists.
@@coll.remove
@r1 = @@coll.insert('a' => 1) # collection not created until it's used
@@coll_full_name = 'ruby-mongo-test.test'
@admin = @@db.admin
end
def teardown
@admin.profiling_level = :off
@@coll.remove if @@coll
@@db.error
end
def test_default_profiling_level
assert_equal :off, @admin.profiling_level
end
def test_change_profiling_level
@admin.profiling_level = :slow_only
assert_equal :slow_only, @admin.profiling_level
@admin.profiling_level = :off
assert_equal :off, @admin.profiling_level
@admin.profiling_level = :all
assert_equal :all, @admin.profiling_level
begin
@admin.profiling_level = :medium
fail "shouldn't be able to do this"
rescue
end
end
def test_profiling_info
# Perform at least one query while profiling so we have something to see.
@admin.profiling_level = :all
@@coll.find()
@admin.profiling_level = :off
info = @admin.profiling_info
assert_kind_of Array, info
assert info.length >= 1
first = info.first
assert_kind_of String, first['info']
assert_kind_of Time, first['ts']
assert_kind_of Numeric, first['millis']
end
def test_validate_collection
doc = @admin.validate_collection(@@coll.name)
assert_not_nil doc
result = doc['result']
assert_not_nil result
assert_match /firstExtent/, result
end
end