Skip to content

Commit

Permalink
test big file copy
Browse files Browse the repository at this point in the history
  • Loading branch information
lp committed Mar 13, 2009
1 parent cd556b1 commit 4db032f
Showing 1 changed file with 53 additions and 29 deletions.
82 changes: 53 additions & 29 deletions test/tc_sambala_main.rb
Expand Up @@ -5,8 +5,11 @@
require File.join( File.dirname( File.expand_path(__FILE__)), '..', 'lib', 'sambala') require File.join( File.dirname( File.expand_path(__FILE__)), '..', 'lib', 'sambala')


TESTFILE = 'sambala_test' TESTFILE = 'sambala_test'
TESTDIR = 'sambala_test_dir' LOCAL_DIR = File.join( File.dirname( File.expand_path(__FILE__)), 'sambala_test_dir')
REMOTE_DIR = 'sambala_test_dir'
WELCOME = <<TITLE WELCOME = <<TITLE
.|'''.| '|| '|| .|'''.| '|| '||
||.. ' .... .. .. .. || ... .... || .... ||.. ' .... .. .. .. || ... .... || ....
''|||. '' .|| || || || ||' || '' .|| || '' .|| ''|||. '' .|| || || || ||' || '' .|| || '' .||
Expand All @@ -25,38 +28,40 @@ def setup
get_samba_param_from_input get_samba_param_from_input
init_sambala init_sambala
put_marker put_marker
Dir.mkdir(TESTDIR) Dir.mkdir(LOCAL_DIR)
end end


def test_main def test_main
@log_test.info("Testing sample SMB operations...") @log_test.info("Testing sample SMB operations...")
ls_one = check_ls ls_one = check_ls
check_mkdir(TESTDIR) check_mkdir(REMOTE_DIR)
check_exist(TESTDIR) check_exist(REMOTE_DIR)
check_cd(TESTDIR) check_cd(REMOTE_DIR)


ls_two = check_ls ls_two = check_ls
assert(ls_one != ls_two) assert(ls_one != ls_two)


check_lcd_put_get check_lcd_put_get
check_queue check_queue

check_big_chunk


check_cd('..') check_cd('..')
check_rmdir(TESTDIR) check_rmdir(REMOTE_DIR)
end end


def teardown def teardown
back_to_marker back_to_marker
@log_test.info("All Test Done!!! Tearing Down!!!") @log_test.info("All Test Done!!! Tearing Down!!!")
@samba.rmdir(TESTDIR).to_s if @samba.exist?(TESTDIR) @samba.rmdir(REMOTE_DIR).to_s if @samba.exist?(REMOTE_DIR)
@log_test.debug("remote directory clean") @log_test.debug("remote directory clean")
close = @samba.close close = @samba.close
assert(close) assert(close)
@log_test.debug("samba client closed") @log_test.debug("samba client closed")
FileUtils.remove_dir(TESTDIR) if File.exist?(TESTDIR) FileUtils.remove_dir(LOCAL_DIR) if File.exist?(LOCAL_DIR)
@log_test.debug("local directory clean") @log_test.debug("local directory clean")
@log_test.close @log_test.close
puts "\nBEWARE, if test fails you may have to clean up your server and the test directory,\na folder named #{TESTDIR} may be left after exiting... Sorry!" puts "\nBEWARE, if test fails you may have to clean up your server and the test directory,\na folder named #{REMOTE_DIR} may be left after exiting... Sorry!"
end end


private private
Expand All @@ -78,6 +83,7 @@ def check_smbclient_presence


def get_samba_param_from_input def get_samba_param_from_input
puts WELCOME puts WELCOME
puts "ATTENTION!!! You need 1gb free space on your local machine and 10gb on your server for this test to run!!!"
puts "I will need you to input some working Samba connection settings..." puts "I will need you to input some working Samba connection settings..."
print "\n"; sleep 1 print "\n"; sleep 1
print "host name or IP: " print "host name or IP: "
Expand Down Expand Up @@ -133,23 +139,23 @@ def check_rmdir(path)


def check_lcd_put_get def check_lcd_put_get
@log_test.debug("cd in testdir") @log_test.debug("cd in testdir")
re = @samba.lcd(TESTDIR) re = @samba.lcd(LOCAL_DIR)
assert_equal(true,re) assert_equal(true,re)


@log_test.debug("making local test file") @log_test.debug("making local test file")
f = File.new("#{TESTDIR}/#{TESTFILE}",'w') f = File.new(File.join(LOCAL_DIR,TESTFILE),'w')
f.puts "test file" f.puts "test file"
f.close f.close
assert(File.exist?("#{TESTDIR}/#{TESTFILE}")) assert(File.exist?(File.join(LOCAL_DIR,TESTFILE)))


@log_test.debug("putting file") @log_test.debug("putting file")
re = @samba.put(:from => TESTFILE, :to => TESTFILE) re = @samba.put(:from => TESTFILE, :to => TESTFILE)
assert_kind_of(Array,re) assert_kind_of(Array,re)
assert_equal(true,re[0]) assert_equal(true,re[0])


@log_test.debug("deleting local test file") @log_test.debug("deleting local test file")
File.delete("#{TESTDIR}/#{TESTFILE}") File.delete(File.join(LOCAL_DIR,TESTFILE))
assert(!File.exist?("#{TESTDIR}/#{TESTFILE}")) assert(!File.exist?(File.join(LOCAL_DIR,TESTFILE)))


check_exist(TESTFILE) check_exist(TESTFILE)


Expand All @@ -163,35 +169,31 @@ def check_lcd_put_get
assert_equal(true,re) assert_equal(true,re)


@log_test.debug("check local test file") @log_test.debug("check local test file")
assert(File.exist?("#{TESTDIR}/#{TESTFILE}")) assert(File.exist?(File.join(LOCAL_DIR,TESTFILE)))
File.delete("#{TESTDIR}/#{TESTFILE}") File.delete(File.join(LOCAL_DIR,TESTFILE))
assert(!File.exist?("#{TESTDIR}/#{TESTFILE}")) assert(!File.exist?(File.join(LOCAL_DIR,TESTFILE)))


re = @samba.lcd('..') re = @samba.lcd('..')
assert_equal(true,re) assert_equal(true,re)


end end


def check_queue def check_queue
jobs = 30 jobs = 23
@log_test.info("Testing queue... (be patient, this will take a couple minutes)") @log_test.info("Testing queue... (be patient, this will take a couple minutes)")
assert_equal(true, @samba.queue_empty?) assert_equal(true, @samba.queue_empty?)
assert_equal(true, @samba.queue_done?) assert_equal(true, @samba.queue_done?)
assert_equal(0,@samba.queue_waiting) assert_equal(0,@samba.queue_waiting)


files = Array.new(jobs) { |id| "file_" + id.to_s } local_file = File.join(LOCAL_DIR,'dummy')
content = "01" * 10000000 system("mkfile 1k #{local_file}")
files.each do |file|
f = File.new("#{TESTDIR}/#{file}",'w')
f.puts content
f.close
end


re = @samba.lcd(TESTDIR) re = @samba.lcd(LOCAL_DIR)
assert_equal(true,re) assert_equal(true,re)


files = Array.new(jobs) { |id| "file_" + id.to_s }
files.each do |file| files.each do |file|
@samba.put(:from => file, :to => file, :queue => true) @samba.put(:from => local_file, :to => file, :queue => true)
end end


assert_equal(false, @samba.queue_empty?) assert_equal(false, @samba.queue_empty?)
Expand All @@ -204,7 +206,7 @@ def check_queue
301.times do |n| 301.times do |n|
break unless result[0].nil? break unless result[0].nil?
sleep 1 sleep 1
result = @samba.queue_completed result = @samba.queue_processing
flunk("Could not get any queue done...") if n == 300 flunk("Could not get any queue done...") if n == 300
end end
assert_kind_of(Array,result[0]) assert_kind_of(Array,result[0])
Expand Down Expand Up @@ -245,14 +247,36 @@ def check_queue
assert_equal(true, @samba.queue_done?) assert_equal(true, @samba.queue_done?)
assert_equal(0,@samba.queue_waiting) assert_equal(0,@samba.queue_waiting)


File.delete(local_file)
files.each do |file| files.each do |file|
del = @samba.del(file) del = @samba.del(file)
@log_test.debug("remote delete: #{del.inspect}") @log_test.debug("remote delete: #{del.inspect}")
File.delete("#{TESTDIR}/#{file}")
end end


re = @samba.lcd('..') re = @samba.lcd('..')
assert_equal(true,re) assert_equal(true,re)
end end

def check_big_chunk
jobs = 2
@log_test.info("Testing a big copy... (be patient, this can also take a couple minutes)")
local_file = File.join(LOCAL_DIR,'dummy')
system("mkfile 1g #{local_file}")

before = @samba.ls
files = Array.new(jobs) { |id| "file_" + id.to_s }
files.each do |file|
@samba.put(:from => local_file, :to => file, :queue => true)
end

result = @samba.queue_results
assert_equal(1, result.map { |item| item[1] }.uniq.size, "results were: #{result.inspect}")

File.delete(local_file)
files.each do |file|
del = @samba.del(file)
@log_test.debug("remote delete: #{del.inspect}")
end
end


end end

0 comments on commit 4db032f

Please sign in to comment.