Sha256: e8fa6d2f4ff36975c6d18ef182419d17adf84d1fa5c68c1bf116191785f322c4

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

require 'yaml'
require 'fileutils'
require 'mongo'

class MongoEnvMaker

  attr_reader :pids

  def initialize(root_folder)
    @root_folder = root_folder
    @pids = []
  end


  def spawn(port, rs_name = nil)
    `mkdir -p #{@root_folder}/logs/#{port}`
    out_log = "#{@root_folder}/logs/#{port}/out.log"
    err_log = "#{@root_folder}/logs/#{port}/err.log"
    pid = Process.spawn mongod(port, rs_name), :out=> out_log, :err => err_log
    @pids << pid
  end

  private
  def mongod(port, set_name = nil)
    path = mk_db_dir(port)
    out = "mongod --port #{port} --dbpath #{path}  --smallfiles --oplogSize 128"
    out << " --replSet #{set_name}" unless set_name.nil?
    out
  end

  def mk_db_dir(port)
    path = "#{@root_folder}/dbs/#{port}"
    FileUtils.rm_rf path
    `mkdir -p #{path}`
    path
  end
end


class DummyData
  def self.seed(host, port)
    puts "[DummyData] Seed #{host}:#{port} with some dummy data"
    include Mongo
    mongo_client = MongoClient.new(host, port)
    db = mongo_client.db("dummy")
    coll = db.collection("some_collection")
    doc = {"name" => "MongoDB", "type" => "database", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
    id = coll.insert(doc)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongo-db-utils-0.2.1 integration-test-env/helper.rb
mongo-db-utils-0.2.0 integration-test-env/helper.rb
mongo-db-utils-0.1.6 integration-test-env/helper.rb
mongo-db-utils-0.1.5 integration-test-env/helper.rb
mongo-db-utils-0.1.4 integration-test-env/helper.rb
mongo-db-utils-0.1.3 integration-test-env/helper.rb
mongo-db-utils-0.1.2 integration-test-env/helper.rb
mongo-db-utils-0.1.0 integration-test-env/helper.rb
mongo-db-utils-0.0.9.3 integration-test-env/helper.rb
mongo-db-utils-0.0.9.2 integration-test-env/helper.rb