KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > statetransfer > FailedStateTransferTest


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22
23 package org.jboss.cache.statetransfer;
24
25 import org.jboss.cache.CacheException;
26 import org.jboss.cache.CacheImpl;
27 import org.jboss.cache.Version;
28 import org.jboss.cache.factories.XmlConfigurationParser;
29 import org.jboss.cache.lock.TimeoutException;
30
31 import java.io.InputStream JavaDoc;
32
33 /**
34  * A FailedStateTransferTest.
35  *
36  * @author Brian Stansberry
37  * @version $Revision$
38  */

39 public class FailedStateTransferTest extends StateTransferTestBase
40 {
41
42    public void testFailedStateTransfer() throws Exception JavaDoc
43    {
44       CacheImpl cache = new SecretiveStateCache();
45       cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replAsync-service.xml"));
46       cache.getConfiguration().setClusterName("VersionedTestBase");
47       cache.getConfiguration().setReplVersionString(getReplicationVersion());
48       // Use a long timeout to facilitate setting debugger breakpoints
49
cache.getConfiguration().setInitialStateRetrievalTimeout(60000);
50
51       // Put the cache in the map before starting, so if it fails in
52
// start it can still be destroyed later
53
caches.put("secretive", cache);
54
55       cache.create();
56       cache.start();
57
58
59       CacheImpl recipient = new SecretiveStateCache();
60       recipient.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replAsync-service.xml"));
61       recipient.getConfiguration().setClusterName("VersionedTestBase");
62       recipient.getConfiguration().setReplVersionString(getReplicationVersion());
63       // Use a long timeout to facilitate setting debugger breakpoints
64
recipient.getConfiguration().setInitialStateRetrievalTimeout(60000);
65
66       //Put the cache in the map before starting, so if it fails in
67
// start it can still be destroyed later
68
caches.put("secretive2", recipient);
69
70       try
71       {
72          recipient.create();
73          recipient.start();
74          fail("start() should throw an exception");
75       }
76       catch (CacheException good)
77       {
78          // this is what we want
79
}
80    }
81
82    protected String JavaDoc getReplicationVersion()
83    {
84       return Version.version;
85    }
86
87    private static class SecretiveStateCache extends CacheImpl
88    {
89       SecretiveStateCache() throws Exception JavaDoc
90       {
91          super();
92          ml = new Adaptor();
93       }
94
95       class Adaptor extends MessageListenerAdaptor
96       {
97
98          @Override JavaDoc
99          public void setState(byte[] new_state)
100          {
101             setStateException = new TimeoutException("Planned Timeout");
102          }
103
104          @Override JavaDoc
105          public void setState(InputStream JavaDoc istream)
106          {
107             setStateException = new TimeoutException("Planned Timeout");
108          }
109
110          @Override JavaDoc
111          public void setState(String JavaDoc state_id, byte[] state)
112          {
113             setStateException = new TimeoutException("Planned Timeout");
114          }
115
116          @Override JavaDoc
117          public void setState(String JavaDoc state_id, InputStream JavaDoc istream)
118          {
119             setStateException = new TimeoutException("Planned Timeout");
120          }
121       }
122    }
123 }
124
Popular Tags