From jboss-remoting-commits at lists.jboss.org Mon Aug 30 22:49:18 2010 Content-Type: multipart/mixed; boundary="===============2508625909879108455==" 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: r6076 - remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test. Date: Mon, 30 Aug 2010 22:49:18 -0400 Message-ID: <201008310249.o7V2nINr016499@svn01.web.mwc.hst.phx2.redhat.com> --===============2508625909879108455== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2010-08-30 22:49:18 -0400 (Mon, 30 Aug 2010) New Revision: 6076 Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/At= tachmentsTestCase.java Log: JBREM-1228: New unit test for org.jboss.remoting3.AttachmentsImpl. Added: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/tes= t/AttachmentsTestCase.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 --- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/A= ttachmentsTestCase.java (rev 0) +++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/test/A= ttachmentsTestCase.java 2010-08-31 02:49:18 UTC (rev 6076) @@ -0,0 +1,135 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt 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.remoting3.test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.io.IOException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.Executor; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import org.jboss.remoting3.Attachments; +import org.jboss.remoting3.Endpoint; +import org.jboss.remoting3.Remoting; +import org.jboss.xnio.OptionMap; +import org.jboss.xnio.log.Logger; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Tests org.jboss.remoting3.AttachmentsImpl. + * = + * @author Ron Sigal + * @version $Revision: 1.1 $ + *

+ * Copyright August 27, 2010 + */ +(a)Test(suiteName =3D "Attachments") +public class AttachmentsTestCase extends RemotingTestBase { + + private static final Logger log =3D Logger.getLogger(AttachmentsTestCas= e.class); + + @BeforeMethod + public void setUp() { + } + + @AfterMethod + public void tearDown() throws IOException { + } + = + @Test + public void testAttachments() throws Exception { + enter(); + = + try { + Executor executor =3D new ThreadPoolExecutor(8, 64, 30, TimeUnit.= SECONDS, new ArrayBlockingQueue(64)); + Endpoint endpoint =3D Remoting.createEndpoint("attachments", exec= utor, OptionMap.EMPTY); + Attachments attachments =3D endpoint.getAttachments(); + Attachments.Key key1 =3D new Attachments.Key(Obje= ct.class); + Object value1 =3D new Object(); + attachments.attach(key1, value1); + assertEquals(value1, attachments.getAttachment(key1)); + = + Object value2 =3D new Object(); + attachments.attachIfAbsent(key1, value2); + assertEquals(value1, attachments.getAttachment(key1)); + Attachments.Key key2 =3D new Attachments.Key(Obje= ct.class); + attachments.attachIfAbsent(key2, value2); + assertEquals(value2, attachments.getAttachment(key2)); + = + assertFalse(attachments.replaceAttachment(key1, value2, value2)); + assertEquals(value1, attachments.getAttachment(key1)); + = + assertTrue(attachments.replaceAttachment(key1, value1, value2)); + assertEquals(value2, attachments.getAttachment(key1)); + = + Attachments.Key key3 =3D new Attachments.Key(Obje= ct.class); + Object value3 =3D new ComparableObject(3); + attachments.attach(key3, value3); + Object value4 =3D new ComparableObject(7); + assertFalse(attachments.replaceAttachment(key3, value4, value3)); + assertEquals(value3, attachments.getAttachment(key3)); + assertTrue(attachments.replaceAttachment(key3, new ComparableObje= ct(3), value4)); + assertEquals(value4, attachments.getAttachment(key3)); + = + assertEquals(value2, attachments.removeAttachment(key1)); + assertNull(attachments.getAttachment(key1)); + = + attachments.attach(key1, value1); + assertFalse(attachments.removeAttachment(key1, value2)); + assertEquals(value1, attachments.getAttachment(key1)); + assertTrue(attachments.removeAttachment(key1, value1)); + assertNull(attachments.getAttachment(key1)); + = + assertFalse(attachments.removeAttachment(key3, value3)); + assertEquals(value4, attachments.getAttachment(key3)); + assertTrue(attachments.removeAttachment(key3, new ComparableObjec= t(7))); + assertNull(attachments.getAttachment(key3)); = + = + log.info(getName() + " PASSES"); + } finally { + exit(); + } + } + = + static class ComparableObject { + private final int secret; + = + public ComparableObject(int secret) { + this.secret =3D secret; + } + = + public boolean equals(Object other) { + if (! (other instanceof ComparableObject)) { + return false; + } + return secret =3D=3D ((ComparableObject) other).secret; + } + } +} --===============2508625909879108455==--