~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestClient.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JBoss, Home of Professional Open Source.
 
3
 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
 
4
 * as indicated by the @author tags. See the copyright.txt file in the
 
5
 * distribution for a 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.test.remoting.connection.deadlock;
 
24
 
 
25
import java.net.InetAddress;
 
26
import java.util.HashMap;
 
27
import java.util.Map;
 
28
 
 
29
import junit.framework.TestCase;
 
30
 
 
31
import org.apache.log4j.ConsoleAppender;
 
32
import org.apache.log4j.Level;
 
33
import org.apache.log4j.Logger;
 
34
import org.apache.log4j.PatternLayout;
 
35
import org.jboss.remoting.Client;
 
36
import org.jboss.remoting.ConnectionListener;
 
37
import org.jboss.remoting.ConnectionValidator;
 
38
import org.jboss.remoting.InvokerLocator;
 
39
 
 
40
/**
 
41
 * Unit test for JBREM-1070.
 
42
 * 
 
43
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
44
 * @version 
 
45
 * <p>
 
46
 * Copyright Nov 29, 2008
 
47
 * </p>
 
48
 */
 
49
public class DeadlockTestClient extends TestCase
 
50
{
 
51
   private static Logger log = Logger.getLogger(DeadlockTestClient.class);
 
52
   
 
53
   private static boolean firstTime = true;
 
54
   
 
55
   protected String host;
 
56
   protected int port = 7777;
 
57
   protected String locatorURI;
 
58
   protected InvokerLocator serverLocator;
 
59
 
 
60
   
 
61
   public void setUp() throws Exception
 
62
   {
 
63
      if (firstTime)
 
64
      {
 
65
         firstTime = false;
 
66
         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
 
67
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
68
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
69
         PatternLayout layout = new PatternLayout(pattern);
 
70
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
71
         Logger.getRootLogger().addAppender(consoleAppender);  
 
72
      }
 
73
   }
 
74
 
 
75
   
 
76
   public void tearDown()
 
77
   {
 
78
   }
 
79
   
 
80
   
 
81
   public void testForDeadlock() throws Throwable
 
82
   {
 
83
      log.info("entering " + getName());
 
84
      for (int i = 0; i < 10; i++)
 
85
      {
 
86
         assertTrue("failed execution: " + i, doTest());
 
87
         log.info("execution " + i + " PASSES\n");
 
88
      }
 
89
      log.info(getName() + " PASSES");
 
90
   }
 
91
   
 
92
   
 
93
   public boolean doTest() throws Throwable
 
94
   {
 
95
      // Create client.
 
96
      host = InetAddress.getLocalHost().getHostAddress();
 
97
      locatorURI = getTransport() + "://" + host + ":" + port;
 
98
      String metadata = System.getProperty("remoting.metadata");
 
99
      if (metadata != null)
 
100
      {
 
101
         locatorURI += "/?" + metadata;
 
102
      }
 
103
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
 
104
      HashMap clientConfig = new HashMap();
 
105
      clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "5000");
 
106
      clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1000");
 
107
      addExtraClientConfig(clientConfig);
 
108
      Client client = new Client(clientLocator, clientConfig);
 
109
      client.connect();
 
110
      log.info("client is connected");
 
111
      
 
112
      // Test connections.
 
113
      assertEquals("abc", client.invoke("abc"));
 
114
      log.info("connection is good");
 
115
      
 
116
      // Add ConnectionListener.
 
117
      TestConnectionListener listener = new TestConnectionListener();
 
118
      client.addConnectionListener(listener);
 
119
      
 
120
      // Wait for notification.
 
121
      for (int i = 0; i < 20; i++)
 
122
      {
 
123
         if (listener.ok)
 
124
         {
 
125
            break;
 
126
         }
 
127
         Thread.sleep(1000);
 
128
      }
 
129
      
 
130
      client.disconnect();
 
131
      return listener.ok;
 
132
   }
 
133
   
 
134
   
 
135
   protected String getTransport()
 
136
   {
 
137
      return "socket";
 
138
   }
 
139
   
 
140
   
 
141
   protected void addExtraClientConfig(Map config) {}
 
142
 
 
143
   
 
144
   static class TestConnectionListener implements ConnectionListener
 
145
   {
 
146
      public boolean ok;
 
147
      
 
148
      public void handleConnectionException(Throwable throwable, Client client)
 
149
      {
 
150
         ok = true;
 
151
         log.info("handleConnectionException() called");
 
152
      }
 
153
   }
 
154
}
 
 
b'\\ No newline at end of file'