Sha256: 18c913b05ee73e5de5675426aa52e04d3c4828243a49e43f529a21dd32f52aef

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

describe Fastdfs::Client::Tracker do 

  let(:host){ "192.168.9.16" }
  let(:port){ "22122" }

  let(:tracker){ FC::Tracker.new(host, port) }

  it "initialize the server" do 
    expect(FC::Socket).to receive(:new).with(host, port, nil) 
    FC::Tracker.new(host, port) 
  end

  it "should have access to the storage connection" do
    expect(tracker.socket).to receive(:connection).and_return({})
    expect(tracker.socket).to receive(:close)
    tracker.get_storage
  end

  it "should have access to the storage class" do 
    expect(tracker.get_storage.class).to eq(FC::Storage)
  end

  it "verify the server address and port" do 
    expect(tracker.get_storage.socket.host).to eq(TestConfig::STORAGE_IP)

    expect(tracker.get_storage.socket.port.to_s).to eq(TestConfig::STORAGE_PORT)
    expect(tracker.get_storage.store_path).to eq(TestConfig::STORE_PATH)
  end

  it "get to the server failed" do 
    result = FC::ProtoCommon.header_bytes(FC::CMD::RESP_CODE, 0, 22)
    MockTCPSocket.any_instance.stub("recv").and_return(result.pack("C*"))
    expect(tracker.get_storage).to be_a_kind_of(Hash)
    expect(tracker.get_storage[:status]).to be_falsey
  end

  it "multi thread upload" do 
    items = 6.times.map do
      Thread.new do 
        storage = tracker.get_storage
        res = storage.upload(File.open(File.expand_path("../page.png", __FILE__)))
        expect(res[:status]).to be_truthy
        results = res[:result]
        res = storage.delete(results[:path], results[:group_name])
        expect(res[:status]).to be_truthy
      end
    end

    items.map{|item|  item.join }
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fastdfs-client-1.4.4 spec/tracker_spec.rb
fastdfs-client-1.4.3 spec/tracker_spec.rb
fastdfs-client-1.4.1 spec/tracker_spec.rb
fastdfs-client-1.4.0 spec/tracker_spec.rb