Sha256: bd980bc66a6facd3930fddb6607a2a4b5d7438c569e6fb0c3be41acde32e5ae1

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/ruby

$: << "../lib"

require 'rubygems'
require 'runit/testcase'
require 'runit/cui/testrunner'
require 'rubygems'
require 'needle'
require 'jiji/util/synchronize_interceptor'
require 'fileutils'

class SynchronizeInterceptorTest <  RUNIT::TestCase
  
  def setup
    @dir = File.dirname(__FILE__) + "/CSVTest.tmp"
    FileUtils.mkdir_p @dir    
  end

  def teardown
    FileUtils.rm_rf @dir
  end

  def test_basic
    
    # レジストリ
    p = proc {
      5.times {|i| print "#{i},"; sleep 0.1 }
    }
    registry = Needle::Registry.define {|builder|
      builder.loop_no { p }
      builder.loop_x1 { p }
      builder.loop_x2 { p }
      builder.loop_y1 { p }
      builder.loop_y2 { p }
    }
    
    # インターセプタを適用
    registry.intercept( :loop_x1 ).with { SynchronizeInterceptor }.with_options( :id=>"x" )
    registry.intercept( :loop_x2 ).with { SynchronizeInterceptor }.with_options( :id=>"x" )
    registry.intercept( :loop_y1 ).with { SynchronizeInterceptor }.with_options( :id=>"y" )
    registry.intercept( :loop_y2 ).with { SynchronizeInterceptor }.with_options( :id=>"y" )
    
    loops = [
      :loop_no, :loop_x1, :loop_x2, :loop_y1, :loop_y2
    ]
    loops.each {|a|
      loops.each {|b|
        puts "\n\n---#{a} x #{b}"
        [registry[a],registry[b]].map {|x|
          Thread.fork(x) {|l| l.call }
        }.each{|t| t.value }
      }
    }
  end
  
  # 同じインターセプタが2重に適用されている場合のテスト
  def test_dual
    registry = Needle::Registry.new {|r|
        r.register( :a ) {
          proc { puts "aaa" }
        }
        r.register( :b ) {
          a = r.a
          proc { a.call; puts "bbb" }
        }
    }
    registry.intercept( :a ).with { SynchronizeInterceptor }.with_options( :id=>"x" )
    registry.intercept( :b ).with { SynchronizeInterceptor }.with_options( :id=>"x" )
    
    b = registry.b
    3.times{|i| b.call }
  end
 
  
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
unageanu-jiji-1.2.1 test/util/test_SynchronizeInterceptor.rb
unageanu-jiji-1.2.3 test/util/test_SynchronizeInterceptor.rb
unageanu-jiji-1.2.4 test/util/test_SynchronizeInterceptor.rb
jiji-1.2.8 test/util/test_SynchronizeInterceptor.rb
jiji-1.2.7 test/util/test_SynchronizeInterceptor.rb
jiji-1.2.6 test/util/test_SynchronizeInterceptor.rb
jiji-1.2.5 test/util/test_SynchronizeInterceptor.rb