Added support for ZeroMQ2 transport.
[cl-cluster.git] / tests.lisp
blob9148f899c5858ba95cc42e7689eddb7cefd7d927
1 (require :cl-cluster)
3 (in-package :cl-cluster)
5 ;;; tests
6 (let ((node1 (make-instance 'node :host "rhel4" :connect t))
7 (node2 (make-instance 'node :host "rhel5" :connect t))
8 (node3 (make-instance 'node :host "rhel5" :lisp "/usr/bin/clisp -q" :connect t)))
9 ; (declare (special node1 node2 node3))
11 (dolist (node (list node1 node2 node3))
12 (when (node-alive-p node)
13 (handler-case
14 (progn
15 (format t "Remote \"~A\" runs ~A ~A~%"
16 (node-host node)
17 (node-exec node "(lisp-implementation-type)")
18 (node-exec node "(lisp-implementation-version)"))
19 (node-exec node "(killallhumans)"))
20 (error (condition)
21 (format t "got error: ~A~%" condition)))))
23 (print (rplet node3
24 ((a (with-remote node1
25 (+ 1 2)))
26 (b (with-remote node2
27 (sqrt 7d0))))
28 (* a b))))
30 (setq n1 (make-instance 'node :host "rhel4" :connect t))
31 (setq n2 (make-instance 'node :host "rhel5" :connect t))
32 ;; connect to host's different lisp
33 (setq n3 (make-instance 'node :host "rhel5" :lisp "/usr/bin/clisp -q" :connect t))
35 (setq n4 (make-instance 'node :host "rhel4" :lisp "/usr/bin/clisp -q" :connect t))
37 ;; node-exec expects only strings
38 (node-exec n1 1)
40 ;; catch remote exception locally
41 (node-exec n1 "(lisp-implementation-type1)")
43 (with-remote n1
44 (lisp-implementation-type)
45 (lisp-implementation-version))
47 ;; calculate some stuff on remote lisps and aggregate answers on another remote
48 (rplet n3
49 ((a (with-remote n1
50 (+ 1 2)))
51 (b (with-remote n2
52 (sqrt 7d0))))
54 (* a b))
56 (plet
57 ((a (with-remote n1
58 (+ 1 2)))
59 (b (with-remote n2
60 (sqrt 7d0))))
62 (* a b))
64 ;; catch exception
65 (with-remote n1
66 nil
67 (dotimes (i 10)
68 (+ i j)))
70 ;; eval body in progn
71 (rplet n1 ()
72 (lisp-implementation-type)
73 (lisp-implementation-version))
75 ;; avoid reader error
76 (with-remote n1
77 (require 'asdf)
78 (asdf:oos 'asdf:load-op :asdf-install))
80 (defun exit-from (n)
81 (node-exec n "(save-lisp-and-die \"core\")")
82 (node-disconnect n))
84 (setq n1 (make-instance 'node :host "rhel5" :connect t))
86 (with-remote n1
87 (defvar a 1))
89 (with-remote n1
90 (+ a 2))
92 (exit-from n1)
95 (require :cl-cluster)
97 (in-package :cl-cluster)
99 (setq my-remote (make-instance 'node-ssh :host "rhel5" :connect t))
100 (setq my-remote (make-instance 'node-zmq :endpoint "tcp://127.0.0.1:5555" :connect t))
101 (setq my-remote (make-instance 'node-zmq :endpoint "pgm://lo;226.0.0.1:5555" :connect t))
103 (node-exec my-remote "1")
105 (with-remote my-remote
106 (defvar remote-list '(1 2 3 4 5 6 7 8)))
108 (with-remote my-remote "123")
110 (node-alive-p my-remote)
112 (node-disconnect my-remote)
114 (node-sexp my-remote)
116 (with-remote my-remote
117 remote-list)
119 (with-remote my-remote
120 (loop for i in remote-list
121 when (oddp i) collect i))
123 (with-remote my-remote
124 (unintern 'remote-list))
126 (with-remote my-remote
127 remote-list)
129 (with-remote my-remote
130 (defclass abc () ; #<...> <- fails to read
131 ((foo :initform 1))))
133 (with-remote my-remote
134 (setq bar (make-instance 'abc)))
136 (with-remote my-remote
137 (slot-value bar 'foo))
139 Error: The variable REMOTE-LIST is unbound.
140 In form: (PROGN REMOTE-LIST)
141 At node: #N<HOST:"rhel5" LISP:"/usr/bin/sbcl --noinform --core core">
143 [Condition of type SIMPLE-ERROR]