Class: ServicesTestServer::DbController
- Inherits:
-
Object
- Object
- ServicesTestServer::DbController
- Defined in:
- lib/services_test_server/db_controller.rb
Class Method Summary collapse
Instance Method Summary collapse
- #begin_transaction ⇒ Object
-
#initialize ⇒ DbController
constructor
A new instance of DbController.
- #rollback_transaction ⇒ Object
Constructor Details
#initialize ⇒ DbController
Returns a new instance of DbController.
25 26 27 |
# File 'lib/services_test_server/db_controller.rb', line 25 def initialize @mutex = Mutex.new end |
Class Method Details
.only_one_connection ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/services_test_server/db_controller.rb', line 6 def self.only_one_connection ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do alias_method :old_checkout, :checkout def checkout @cached_connection ||= old_checkout end end end |
.start ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/services_test_server/db_controller.rb', line 16 def self.start only_one_connection port = ServicesTestServer.control_port DRb.start_service("druby://localhost:#{port}", new) ServicesTestServer.logger.info "DbController service started on druby://localhost:#{port}" end |
Instance Method Details
#begin_transaction ⇒ Object
29 30 31 32 33 |
# File 'lib/services_test_server/db_controller.rb', line 29 def begin_transaction @mutex.lock ServicesTestServer.logger.debug "Beginning remote transaction" ActiveRecord::Base.connection.begin_transaction(joinable: false) end |
#rollback_transaction ⇒ Object
35 36 37 38 39 |
# File 'lib/services_test_server/db_controller.rb', line 35 def rollback_transaction ServicesTestServer.logger.debug "Rolling back remote transaction" ActiveRecord::Base.connection.rollback_transaction @mutex.unlock end |