aboutsummaryrefslogtreecommitdiffstats
path: root/toys/brhute-rb/spike/drbssh_test.rb
blob: 8a1f2c27ad1dbe4c3b488a241a450dca19da5f1d (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$:.unshift File.dirname(__FILE__)

require 'drbssh' # local version of drbssh sudo gem install drbssh

class Ohmy
    def toto
        puts 'i am '+`hostname`
        return 'i am '+`hostname`
    end
end

# Connect - OK
DRb.start_service 'drbssh://'
remote = DRbObject.new_with_uri("drbssh://_sd/ruby")

# Simple eval - OK
puts remote.eval('`hostname`')
puts remote.eval('1+1')

# Send classobj - FAIL
#o = DRbObject.new_with_uri "drbssh://_sd/ruby", Ohmy.new
#Ohmy.new
#o = remote.eval("Ohmy.new")
#class << remote
#    undef :instance_eval
#    def bla
#        puts 'i am '+`hostname`
#    end
#end
#remote.bla

# Create objects - OK
#l = Hash
#l2 = DRbObject.new(l, "drbssh://_sd/ruby")
#remote_hash = remote.eval("@a = {}.extend(DRb::DRbUndumped)")
#puts l2
#remote_hash = remote.eval("@a = {}.extend(DRb::DRbUndumped)")

# Send object - OK
l = [1,2,3]
obj = remote.eval("@data = \""+Marshal.dump(l)+"\"")
obj = remote.eval("@a = Marshal.load(@data)")
obj = remote.eval("@a += [4]")
obj += [5]
puts obj

# Send class object - FAIL
#o = Ohmy.new
#eval("puts o.toto")
#eval("puts Ohmy.new.toto")
#eval("@c = \"Marshal.dump(Ohmy)\"; @d=Marshal.load(eval(@c))")
#eval("@d.new.toto")
#obj = remote.eval("@c = \""+Marshal.dump(Ohmy)+"\"")
#puts obj
#obj = remote.eval("@c.class")
#puts obj
#obj = remote.eval("@c.size")
#puts obj
#obj = remote.eval("@cc = Marshal.load(eval(@c))")
#puts obj
#obj = remote.eval("@o = @cc.new.toto")
#puts obj
#obj = remote.eval("@obj = @o.toto")
#puts obj
#obj = remote.eval("@obj = \""+Marshal.dump(o)+"\"")
#puts obj
#obj = remote.eval("puts Ohmy.new.toto")
#puts obj