1 |
| package org.jboss.cache; |
2 |
| |
3 |
| import junit.framework.TestCase; |
4 |
| import org.jgroups.Address; |
5 |
| import org.jgroups.Channel; |
6 |
| import org.jgroups.ChannelException; |
7 |
| import org.jgroups.JChannel; |
8 |
| import org.jgroups.conf.ProtocolStackConfigurator; |
9 |
| import org.w3c.dom.Element; |
10 |
| |
11 |
| import java.io.File; |
12 |
| import java.net.URL; |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| public class HungChannelTest extends TestCase |
20 |
| { |
21 |
| private CacheImpl cache; |
22 |
| |
23 |
2
| protected void setUp() throws Exception
|
24 |
| { |
25 |
2
| cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
|
26 |
2
| cache.getConfiguration().setCacheMode("REPL_SYNC");
|
27 |
| } |
28 |
| |
29 |
2
| protected void tearDown()
|
30 |
| { |
31 |
2
| if (cache != null)
|
32 |
| { |
33 |
2
| if (cache.channel != null)
|
34 |
| { |
35 |
0
| cache.channel.close();
|
36 |
0
| cache.channel.disconnect();
|
37 |
0
| cache.channel = null;
|
38 |
| } |
39 |
2
| cache.stop();
|
40 |
2
| cache = null;
|
41 |
| } |
42 |
| } |
43 |
| |
44 |
1
| public void testFailingStateTransfer()
|
45 |
| { |
46 |
1
| try
|
47 |
| { |
48 |
1
| cache.create();
|
49 |
1
| JChannel ch = new FailingStateChannel(cache.getConfiguration().getClusterConfig());
|
50 |
1
| ch.setOpt(Channel.GET_STATE_EVENTS, Boolean.TRUE);
|
51 |
1
| ch.setOpt(Channel.AUTO_RECONNECT, Boolean.TRUE);
|
52 |
1
| ch.setOpt(Channel.AUTO_GETSTATE, Boolean.TRUE);
|
53 |
1
| cache.channel = ch;
|
54 |
| |
55 |
1
| cache.start();
|
56 |
0
| fail("Expecting the startService() method to throw an exception");
|
57 |
| } |
58 |
| catch (Exception e) |
59 |
| { |
60 |
| |
61 |
| } |
62 |
| |
63 |
1
| Channel c = cache.channel;
|
64 |
| |
65 |
1
| assertFalse("Channel should not have connected!", c.isConnected());
|
66 |
1
| assertFalse("Channel should not be open", c.isOpen());
|
67 |
| |
68 |
1
| cache.stop();
|
69 |
| |
70 |
1
| assertFalse("Channel should not have connected!", c.isConnected());
|
71 |
1
| assertFalse("Channel should not be open", c.isOpen());
|
72 |
| |
73 |
1
| assertNull("Should be null", cache.channel);
|
74 |
| } |
75 |
| |
76 |
1
| public void testSucceedingStateTransfer()
|
77 |
| { |
78 |
1
| try
|
79 |
| { |
80 |
1
| cache.start();
|
81 |
| } |
82 |
| catch (Exception e) |
83 |
| { |
84 |
0
| fail("NOT expecting the startService() method to throw an exception");
|
85 |
| } |
86 |
| |
87 |
1
| Channel c = cache.channel;
|
88 |
| |
89 |
1
| assertTrue("Channel should have connected!", c.isConnected());
|
90 |
1
| assertTrue("Channel should be open", c.isOpen());
|
91 |
| |
92 |
| |
93 |
1
| cache.stop();
|
94 |
| |
95 |
1
| assertFalse("Channel should not have connected!", c.isConnected());
|
96 |
1
| assertFalse("Channel should not be open", c.isOpen());
|
97 |
| |
98 |
1
| assertNull("Should be null", cache.channel);
|
99 |
| } |
100 |
| |
101 |
| static class FailingStateChannel extends JChannel |
102 |
| { |
103 |
| |
104 |
| |
105 |
0
| public FailingStateChannel() throws ChannelException
|
106 |
| { |
107 |
0
| super();
|
108 |
| } |
109 |
| |
110 |
0
| public FailingStateChannel(File file) throws ChannelException
|
111 |
| { |
112 |
0
| super(file);
|
113 |
| } |
114 |
| |
115 |
0
| public FailingStateChannel(Element element) throws ChannelException
|
116 |
| { |
117 |
0
| super(element);
|
118 |
| } |
119 |
| |
120 |
0
| public FailingStateChannel(URL url) throws ChannelException
|
121 |
| { |
122 |
0
| super(url);
|
123 |
| } |
124 |
| |
125 |
1
| public FailingStateChannel(String string) throws ChannelException
|
126 |
| { |
127 |
1
| super(string);
|
128 |
| } |
129 |
| |
130 |
0
| public FailingStateChannel(ProtocolStackConfigurator protocolStackConfigurator) throws ChannelException
|
131 |
| { |
132 |
0
| super(protocolStackConfigurator);
|
133 |
| } |
134 |
| |
135 |
1
| public boolean getState(Address a, long l)
|
136 |
| { |
137 |
1
| throw new RuntimeException("Dummy Exception getting state");
|
138 |
| } |
139 |
| } |
140 |
| |
141 |
| } |