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.
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.
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.
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.
23
package org.jboss.test.remoting.transport.servlet.callback;
25
import java.util.HashMap;
27
import junit.framework.TestCase;
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;
43
* Unit test for pull callbacks over servlet transport: JBREM-1079.
45
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
48
* Copyright Jan 16, 2009
51
public class CallbackTestClient extends TestCase
53
private static Logger log = Logger.getLogger(CallbackTestClient.class);
55
private static boolean firstTime = true;
57
protected String host;
59
protected String locatorURI;
60
protected InvokerLocator serverLocator;
61
protected Connector connector;
62
protected TestInvocationHandler invocationHandler;
65
public void setUp() throws Exception
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);
80
public void tearDown()
85
public void testMethod() throws Throwable
87
log.info("entering " + getName());
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);
96
log.info("client is connected");
99
log.info("result: " + client.invoke("abc"));
100
assertEquals(null, client.invoke("abc"));
101
log.info("connection is good");
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);
110
// Request callbacks.
112
for (int i = 0; i < COUNT; i++)
114
client.invoke("callback");
117
log.info("sleeping for 2000 ms");
119
log.info("waking up");
121
// Verify all callbacks arrived.
122
assertEquals(COUNT, callbackHandler1.counter);
123
assertEquals(COUNT, callbackHandler1.counter);
125
client.removeListener(callbackHandler1);
126
client.removeListener(callbackHandler2);
128
log.info(getName() + " PASSES");
132
static class TestCallbackHandler implements InvokerCallbackHandler
136
public void handleCallback(Callback callback) throws HandleCallbackException
b'\\ No newline at end of file'