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