From jboss-remoting-commits at lists.jboss.org Fri Apr 25 04:24:09 2008 Content-Type: multipart/mixed; boundary="===============3315310250551114317==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r4079 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/interrupt. Date: Fri, 25 Apr 2008 04:24:09 -0400 Message-ID: --===============3315310250551114317== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2008-04-25 04:24:09 -0400 (Fri, 25 Apr 2008) New Revision: 4079 Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socke= t/interrupt/MockInvokerInterruptTestCase.java Log: JBREM-955: Another unit test (from Galder). Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/s= ocket/interrupt/MockInvokerInterruptTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/interrupt/MockInvokerInterruptTestCase.java (rev= 0) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/sock= et/interrupt/MockInvokerInterruptTestCase.java 2008-04-25 08:24:09 UTC (rev= 4079) @@ -0,0 +1,131 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2008, Red Hat Middleware LLC, and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.test.remoting.transport.socket.interrupt; + +import junit.framework.TestCase; + +import org.apache.log4j.Logger; +import org.jboss.remoting.CannotConnectException; +import org.jboss.remoting.InvocationRequest; +import org.jboss.remoting.InvokerLocator; +import org.jboss.remoting.marshal.Marshaller; +import org.jboss.remoting.marshal.UnMarshaller; +import org.jboss.remoting.transport.socket.MicroSocketClientInvoker; +import org.jboss.remoting.transport.socket.SocketWrapper; + +import EDU.oswego.cs.dl.util.concurrent.CountDown; + +/** + * Unit test for JBREM-955. + * = + * @author Galder Zamarren= o + */ +public class MockInvokerInterruptTestCase extends TestCase +{ + private static final Logger log =3D Logger.getLogger(MockInvokerInterru= ptTestCase.class); + = + public void test000() throws Throwable + { + InvokerLocator il =3D new InvokerLocator("unittest", "127.0.0.1", 99= 99, "mock", null); + CountDown startGate =3D new CountDown(1); + MockMicroSocketClientInvoker ci =3D new MockMicroSocketClientInvoker= (il, startGate); + InvocationRequest ir =3D new InvocationRequest("", "", null, null, n= ull, il); + = + Runnable interrupterRunnable =3D new ThreadInterrupter(Thread.curren= tThread(), startGate); + Thread interrupter =3D new Thread(interrupterRunnable); + interrupter.start(); + = + ci.setMaxPoolSize(0); + ci.connect(); + try + { + ci.invoke(ir); + } + catch(CannotConnectException cce) + { + log.error("We interrupted the connection, a more meaningul except= ion should be thrown"); + throw cce; + } + catch (RuntimeException re) + { + assertTrue(re.getCause() instanceof InterruptedException); + } + } + + class MockMicroSocketClientInvoker extends MicroSocketClientInvoker + { + private CountDown startGate; + = + public MockMicroSocketClientInvoker(InvokerLocator locator, CountDow= n start) + { + super(locator); + startGate =3D start; + } + + public void setMaxPoolSize(int maxPoolSize) + { + this.maxPoolSize =3D maxPoolSize; + } + + protected SocketWrapper getConnection(Marshaller marshaller, UnMarsh= aller unmarshaller, + boolean tryPool, int timeAllow= ed) + throws Exception + { + log.info("Request a connection but before that, let's open the st= art gate"); + startGate.release(); + return super.getConnection(marshaller, unmarshaller, true, timeAl= lowed); + } + } + = + class ThreadInterrupter implements Runnable + { + private Thread threadToInterrupt; + = + private CountDown startGate; + = + ThreadInterrupter(Thread thread, CountDown start) + { + threadToInterrupt =3D thread; + startGate =3D start; + } + + public void run() + { + try + { + log.info("Wait for start gate to be opened"); + startGate.acquire(); + = + log.info("Start gate opened, let's sleep briefly..."); + Thread.sleep(200); + = + log.info("Sleep finished, interrupt the target thread"); + threadToInterrupt.interrupt(); + } + catch (InterruptedException e) + { + log.error("Error", e); + } + } + = + } +} --===============3315310250551114317==--