JABClientTestCase.java
上传用户:xfwatch
上传日期:2020-12-14
资源大小:872k
文件大小:8k
- /*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat, Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
- package org.jboss.blacktie.jatmibroker.jab;
- import java.util.Arrays;
- import junit.framework.TestCase;
- import org.apache.log4j.LogManager;
- import org.apache.log4j.Logger;
- import org.jboss.blacktie.jatmibroker.RunServer;
- public class JABClientTestCase extends TestCase {
- private static final Logger log = LogManager
- .getLogger(JABClientTestCase.class);
- private RunServer runServer = new RunServer();
- // clean up any lingering transactions
private void cleanThread() {
- JABTransaction tx = JABTransaction.current();
- if (tx != null) {
- try {
- tx.rollback();
- } catch (Exception e) {
- }
- }
- }
- public void setUp() throws InterruptedException {
- cleanThread();
- runServer.serverinit();
- runServer.tpadvertisetpcallXOctet();
- }
- public void tearDown() {
- cleanThread();
- runServer.serverdone();
- }
- public void test_tpcall_x_octet() throws Exception {
- JABSessionAttributes aJabSessionAttributes = new JABSessionAttributes();
- JABSession aJabSession = new JABSession(aJabSessionAttributes);
- JABTransaction transaction = new JABTransaction(aJabSession, 5000);
- JABRemoteService aJabService = new JABRemoteService("tpcall_x_octet",
- aJabSession, "X_OCTET", null);
- aJabService.getRequest().setByteArray("X_OCTET",
- "test_tpcall_x_octet".getBytes());
- log.debug("calling tpcall_x_octet with tx");
- aJabService.call(transaction);
- log.debug("called tpcall_x_octet with tx, commiting ...");
- transaction.commit();
- log.debug("tpcall_x_octet commit ok");
- byte[] expected = new byte[60];
- System.arraycopy("tpcall_x_octet".getBytes(), 0, expected, 0, 14);
- byte[] received = aJabService.getResponse().getByteArray("X_OCTET");
- assertTrue(Arrays.equals(expected, received));
- aJabSession.closeSession();
- }
- public void test_tpcall_x_octet_commit_tx_rollback_only() throws Exception {
- JABSessionAttributes aJabSessionAttributes = new JABSessionAttributes();
- JABSession aJabSession = new JABSession(aJabSessionAttributes);
- JABTransaction transaction = new JABTransaction(aJabSession, 5000);
- JABRemoteService aJabService = new JABRemoteService("tpcall_x_octet",
- aJabSession, "X_OCTET", null);
- transaction.rollback_only();
- aJabService.getRequest().setByteArray("X_OCTET",
- "test_tpcall_x_octet".getBytes());
- aJabService.call(null);
- try {
- transaction.commit();
- fail("committing a tx marked rollback only succeeded");
- } catch (JABException e) {
- // the exception is expected, but:
// exception should be CORBA::CORBA::TRANSACTION_ROLLEDBACK but
- // JBossTM
// returns CORBA::OBJECT_NOT_EXIST instead in which case we would
- // use presumed abort");
}
- byte[] expected = new byte[60];
- System.arraycopy("tpcall_x_octet".getBytes(), 0, expected, 0, 14);
- byte[] received = aJabService.getResponse().getByteArray("X_OCTET");
- assertTrue(Arrays.equals(expected, received));
- aJabSession.closeSession();
- }
- public void test_tpcall_x_octet_rollback_tx_rollback_only()
- throws Exception {
- JABSessionAttributes aJabSessionAttributes = new JABSessionAttributes();
- JABSession aJabSession = new JABSession(aJabSessionAttributes);
- JABTransaction transaction = new JABTransaction(aJabSession, 5000);
- JABRemoteService aJabService = new JABRemoteService("tpcall_x_octet",
- aJabSession, "X_OCTET", null);
- transaction.rollback_only();
- aJabService.getRequest().setByteArray("X_OCTET",
- "test_tpcall_x_octet".getBytes());
- aJabService.call(null);
- try {
- transaction.rollback();
- } catch (JABException e) {
- fail("rolling back a tx marked rollback through exception: "
- + e.getMessage());
- }
- byte[] expected = new byte[60];
- System.arraycopy("tpcall_x_octet".getBytes(), 0, expected, 0, 14);
- byte[] received = aJabService.getResponse().getByteArray("X_OCTET");
- assertTrue(Arrays.equals(expected, received));
- aJabSession.closeSession();
- }
- public void test_tpcall_x_octet_no_tx() throws Exception {
- JABSessionAttributes aJabSessionAttributes = new JABSessionAttributes();
- JABSession aJabSession = new JABSession(aJabSessionAttributes);
- JABRemoteService aJabService = new JABRemoteService("tpcall_x_octet",
- aJabSession, "X_OCTET", null);
- aJabService.getRequest().setByteArray("X_OCTET",
- "test_tpcall_x_octet".getBytes());
- aJabService.call(null);
- byte[] expected = new byte[60];
- System.arraycopy("tpcall_x_octet".getBytes(), 0, expected, 0, 14);
- byte[] received = aJabService.getResponse().getByteArray("X_OCTET");
- assertTrue(Arrays.equals(expected, received));
- aJabSession.closeSession();
- }
- public void test_tpcall_x_octet_suspend_tx() throws Exception {
- JABSessionAttributes aJabSessionAttributes = new JABSessionAttributes();
- JABSession aJabSession = new JABSession(aJabSessionAttributes);
- JABTransaction transaction = new JABTransaction(aJabSession, 5000);
- JABRemoteService aJabService = new JABRemoteService("tpcall_x_octet",
- aJabSession, "X_OCTET", null);
- aJabService.getRequest().setByteArray("X_OCTET",
- "test_tpcall_x_octet".getBytes());
- aJabService.call(null);
- transaction.commit();
- byte[] expected = new byte[60];
- System.arraycopy("tpcall_x_octet".getBytes(), 0, expected, 0, 14);
- byte[] received = aJabService.getResponse().getByteArray("X_OCTET");
- assertTrue(Arrays.equals(expected, received));
- aJabSession.closeSession();
- }
- // TODO
/*
- * public void xtest_tpcall_x_c_type() throws Exception {
- * JABSessionAttributes aJabSessionAttributes = new JABSessionAttributes(
- * null); JABSession aJabSession = new JABSession(aJabSessionAttributes);
- * JABTransaction transaction = new JABTransaction(aJabSession, 5000);
- * JABRemoteService aJabService = new JABRemoteService(aJabSession,
- * "tpcall_x_c_type");
- *
- * // Assemble the message ByteArrayOutputStream baos = new
- * ByteArrayOutputStream(512); DataOutputStream dos = new
- * DataOutputStream(baos); dos.writeInt(222); dos.writeShort((short) 33);
- * dos.writeLong(11l); dos.writeChar('c'); dos.writeFloat(444.97f);
- * dos.writeDouble(7.7d); dos.writeUTF("tpcall_x_c_type"); byte[] data =
- * baos.toByteArray();
- *
- * aJabService.setBuffer("X_C_TYPE", data, data.length);
- * aJabService.call(transaction); transaction.commit();
- * aJabSession.endSession();
- *
- * byte[] response = aJabService.getResponseData(); ByteArrayInputStream
- * bais = new ByteArrayInputStream(response); DataInputStream dis = new
- * DataInputStream(bais); assertEquals(222, dis.readInt()); assertEquals(33,
- * dis.readShort()); assertEquals(11, dis.readLong()); assertEquals('c',
- * dis.readChar()); assertEquals(444.97, dis.readFloat()); assertEquals(7.7,
- * dis.readDouble()); assertEquals("tpcall_x_c_type", dis.readUTF()); }
- */
- }