Sha256: 28ee5082071de419e904e1210329cd26c8bed029a2b5e452ecdfcf15f605ffb8
Contents?: true
Size: 1.78 KB
Versions: 4
Compression:
Stored size: 1.78 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/unittest_helper') class TestTaskQueue < Test::Unit::TestCase def test_task_queue tq = Pmux::TaskQueue.new # push v = {:id=>0} tq.push(v) tq.push({:id=>1}) tq.push({:id=>2, :job_id=>99}) ae 3, tq.size ae 2, tq.at(2)[:id] assert_nil tq.at(3) # inject_tasks, shift, delete_job tq.inject_tasks [{:id=>3}, {:id=>4}, {:id=>5}, {:id=>6}, {:id=>7}] #tq.each {|v| p v} ae 8, tq.size a = tq.shift ae 0, a[:id] ae 7, tq.size a = tq.shift ae 1, a[:id] # ae 3, a[:id] ae 6, tq.size tq.delete_job 99 ae 5, tq.size # clear tq.clear ae 0, tq.size # inject, shift tasks = (0..9).map {|i|{:id=>i, :job_id=>99}} tq.inject_tasks tasks tmpq = Pmux::TaskQueue.new while item = tq.shift if item[:id] % 2 == 0 item.delete :_f #XXX tmpq.push item end break if item[:id] == 6 end # delete tq.delete_job 99 ae 0, tq.size # clear, inject tmpq.clear tmpq.inject_tasks [{:id=>0}, {:id=>1}] ae 2, tmpq.size end # inject_tasks ĎņŹň def test_inject_tasks tq = Pmux::TaskQueue.new ae 0, tq.size tasks = [] tq.inject_tasks tasks ae 0, tq.size tasks = [{:id=>0}, {:id=>1}] tq.inject_tasks tasks ae 2, tq.size ae 0, tq.at(0)[:id] ae 1, tq.at(1)[:id] tasks = [{:id=>2, :mapper_class=>true}, {:id=>3}, {:id=>4}] tq.inject_tasks tasks ae 5, tq.size # TaskQueue#inject_tasks ae 0, tq.at(0)[:id] ae 1, tq.at(1)[:id] ae 2, tq.at(2)[:id] ae 3, tq.at(3)[:id] ae 4, tq.at(4)[:id] tasks = (5..6).map {|i|{:id=>i}} tq.inject_tasks tasks ae 7, tq.size tasks = (7..14).map {|i|{:id=>i}} tq.inject_tasks tasks end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
pmux-0.1.3 | test/test_task_queue.rb |
pmux-0.1.2 | test/test_task_queue.rb |
pmux-0.1.1 | test/test_task_queue.rb |
pmux-0.1.0 | test/test_task_queue.rb |