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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/servlet/callback/CallbackTestClient.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.transport.servlet.callback;
 
24
 
 
25
import java.util.HashMap;
 
26
 
 
27
import junit.framework.TestCase;
 
28
 
 
29
import org.apache.log4j.ConsoleAppender;
 
30
import org.apache.log4j.Level;
 
31
import org.apache.log4j.Logger;
 
32
import org.apache.log4j.PatternLayout;
 
33
import org.jboss.logging.XLevel;
 
34
import org.jboss.remoting.Client;
 
35
import org.jboss.remoting.InvokerLocator;
 
36
import org.jboss.remoting.callback.Callback;
 
37
import org.jboss.remoting.callback.HandleCallbackException;
 
38
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
39
import org.jboss.remoting.transport.Connector;
 
40
 
 
41
 
 
42
/**
 
43
 * Unit test for pull callbacks over servlet transport: JBREM-1079.
 
44
 * 
 
45
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
46
 * @version 
 
47
 * <p>
 
48
 * Copyright Jan 16, 2009
 
49
 * </p>
 
50
 */
 
51
public class CallbackTestClient extends TestCase
 
52
{
 
53
   private static Logger log = Logger.getLogger(CallbackTestClient.class);
 
54
   
 
55
   private static boolean firstTime = true;
 
56
   
 
57
   protected String host;
 
58
   protected int port;
 
59
   protected String locatorURI;
 
60
   protected InvokerLocator serverLocator;
 
61
   protected Connector connector;
 
62
   protected TestInvocationHandler invocationHandler;
 
63
 
 
64
   
 
65
   public void setUp() throws Exception
 
66
   {
 
67
      if (firstTime)
 
68
      {
 
69
         firstTime = false;
 
70
         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
 
71
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
72
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
73
         PatternLayout layout = new PatternLayout(pattern);
 
74
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
75
         Logger.getRootLogger().addAppender(consoleAppender);  
 
76
      }
 
77
   }
 
78
 
 
79
   
 
80
   public void tearDown()
 
81
   {
 
82
   }
 
83
   
 
84
   
 
85
   public void testMethod() throws Throwable
 
86
   {
 
87
      log.info("entering " + getName());
 
88
 
 
89
      // Create client.
 
90
      locatorURI = "servlet://localhost:8080/servlet-invoker/ServerInvokerServlet";
 
91
      locatorURI += "/?createUniqueObjectName=true&useAllParams=true&blockingMode=blocking";
 
92
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
 
93
      HashMap clientConfig = new HashMap();
 
94
      Client client = new Client(clientLocator, clientConfig);
 
95
      client.connect();
 
96
      log.info("client is connected");
 
97
      
 
98
      // Test connection.
 
99
      log.info("result: " + client.invoke("abc"));
 
100
      assertEquals(null, client.invoke("abc"));
 
101
      log.info("connection is good");
 
102
      
 
103
      // Install client side callback handlers.
 
104
      TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
 
105
      TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
 
106
      HashMap metadata = new HashMap();
 
107
      client.addListener(callbackHandler1, metadata);
 
108
      client.addListener(callbackHandler2, metadata);
 
109
      
 
110
      // Request callbacks.
 
111
      int COUNT = 100;
 
112
      for (int i = 0; i < COUNT; i++)
 
113
      {
 
114
         client.invoke("callback");
 
115
      }
 
116
      
 
117
      log.info("sleeping for 2000 ms");
 
118
      Thread.sleep(2000);
 
119
      log.info("waking up");
 
120
      
 
121
      // Verify all callbacks arrived.
 
122
      assertEquals(COUNT, callbackHandler1.counter);
 
123
      assertEquals(COUNT, callbackHandler1.counter);
 
124
      
 
125
      client.removeListener(callbackHandler1);
 
126
      client.removeListener(callbackHandler2);
 
127
      client.disconnect();
 
128
      log.info(getName() + " PASSES");
 
129
   }
 
130
   
 
131
   
 
132
   static class TestCallbackHandler implements InvokerCallbackHandler
 
133
   {
 
134
      public int counter;
 
135
      
 
136
      public void handleCallback(Callback callback) throws HandleCallbackException
 
137
      {
 
138
         counter++;
 
139
      }  
 
140
   }
 
141
}
 
 
b'\\ No newline at end of file'