public
Rubygem
Fork of atduskgreg/slipcover
Description: treat a group of objects as a cluster with concurrent access. great for accessing couchdb clusters via CouchRest
Clone URL: git://github.com/jchris/slipcover.git
got doctest to pass
jchris (author)
Thu Jul 17 13:07:33 -0700 2008
commit  966dc3b025d0b34a09a823fcd22635f0c036e768
tree    e6378efc29faade8fa714edb476cd507ee1e4add
parent  456fcc3c28c13de6830f4e3d85778c0ff2c3fc46
...
15
16
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
...
24
25
26
27
 
28
29
30
...
33
34
35
36
37
38
39
 
 
 
 
40
41
42
43
 
44
45
46
47
48
 
49
50
51
...
15
16
17
 
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
36
37
38
 
39
40
41
42
...
45
46
47
 
 
 
 
48
49
50
51
52
53
54
 
55
56
57
58
59
 
60
61
62
63
0
@@ -15,8 +15,20 @@ Require CouchRest and Slipcover:
0
 
0
 Create the members of the cluster (these could be on different hosts, but we'll just simulate that here):
0
     
0
- >> db1 = CouchRest.new('localhost:5984').database('grabbit-import')
0
- >> db2 = CouchRest.new('127.0.0.1:5984').database('test_suite_db')
0
+ >> cr1 = CouchRest.new('localhost:5984')
0
+ >> cr1.database('slipcover-test').delete!
0
+ >> begin; cr1.create_db('slipcover-test'); rescue; nil; end;
0
+
0
+Create cluster member two.
0
+
0
+ >> cr2 = CouchRest.new('127.0.0.1:5984')
0
+ >> cr2.database('slipcover-test2').delete!
0
+ >> begin; cr2.create_db('slipcover-test2'); rescue; nil; end;
0
+ >> db1 = cr1.database('slipcover-test')
0
+ >> db2 = cr2.database('slipcover-test2')
0
+ >> saved = db1.save({"test"=>"doc"})
0
+ >> saved['ok']
0
+ => true
0
 
0
 Assign them to Slipcover for management:
0
         
0
@@ -24,7 +36,7 @@ Assign them to Slipcover for management:
0
 
0
 By default, our cluster will re-raise any errors that occur in individual members
0
   
0
- >> lambda{ cluster.get( "00485b412155c325a3e6982470931ccd" )}.raises_error? RestClient::Request::RequestFailed
0
+ >> lambda{ cluster.get( saved['id'] )}.raises_error? RestClient::Request::RequestFailed
0
   => true
0
 
0
 but, if we want to ignore certain errors in the members (like in this case where we only want to hear back from the member of the cluster that actually has the document we're looking for), we can tell Slipcover to silence errors of a certain type
0
@@ -33,19 +45,19 @@ but, if we want to ignore certain errors in the members (like in this case where
0
   => [RestClient::Request::RequestFailed]
0
 
0
 and then getting a document that's present on only one of the members will return the document without any noise from the other cluster members:
0
-
0
- >> result = cluster.get( "00485b412155c325a3e6982470931ccd" )
0
- >> result.first["metadata"].first["artist"]
0
- => "All My Friends"
0
+
0
+ >> result = cluster.get( saved['id'] )
0
+ >> result.first['test']
0
+ => "doc"
0
 
0
 If members raise other errors that aren't included in the list to be silenced, however, they will bring things to a halt. For example, if we add another member to the cluster on a broken connection
0
 
0
- >> db3 = CouchRest.new('broken-socket').database('grabbit-import')
0
+ >> db3 = CouchRest.new('broken-socket').database('no-couch-here')
0
   >> cluster.add_member db3
0
 
0
 then the resulting errors will still raise:
0
 
0
- >> lambda{ cluster.get( "00485b412155c325a3e6982470931ccd" )}.raises_error? SocketError
0
+ >> lambda{ cluster.get( saved['id'] )}.raises_error? SocketError
0
   => true
0
 
0
 Let's remove this broken cluster member so we can continue our tests:

Comments

    No one has commented yet.