File: base.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (41 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

require_relative '../base'

module Mongo
  module DriverBench
    module Parallel
      module GridFS
        # Abstract base class of parallel GridFS micro-benchmarks.
        #
        # @api private
        class Base < Mongo::DriverBench::Parallel::Base
          def file_name_at(index)
            format('parallel/gridfs_multi/file%02d.txt', index)
          end

          private

          attr_reader :bucket

          def setup
            super
            @dataset_size = 50.times.sum { |i| File.size(path_to_file(file_name_at(i))) }
          end

          def prepare_bucket(initialize: true)
            @bucket = client.database.fs
            @bucket.drop
            @bucket.upload_from_stream 'one-byte-file', "\n" if initialize
          end

          def upload_file(file_name)
            File.open(path_to_file(file_name), 'r') do |file|
              bucket.upload_from_stream file_name, file
            end
          end
        end
      end
    end
  end
end