TestConnection.java
上传用户:xfwatch
上传日期:2020-12-14
资源大小:872k
文件大小:2k
源码类别:

中间件编程

开发平台:

Java

  1. package org.jboss.blacktie.jatmibroker.core.transport.hybrid;
  2. import java.util.Properties;
  3. import junit.framework.TestCase;
  4. import org.apache.log4j.LogManager;
  5. import org.apache.log4j.Logger;
  6. import org.jboss.blacktie.jatmibroker.core.conf.AtmiBrokerClientXML;
  7. import org.jboss.blacktie.jatmibroker.core.conf.ConfigurationException;
  8. import org.jboss.blacktie.jatmibroker.core.transport.Message;
  9. import org.jboss.blacktie.jatmibroker.core.transport.Receiver;
  10. import org.jboss.blacktie.jatmibroker.core.transport.Sender;
  11. import org.jboss.blacktie.jatmibroker.core.transport.Transport;
  12. import org.jboss.blacktie.jatmibroker.core.transport.TransportFactory;
  13. import org.jboss.blacktie.jatmibroker.xatmi.ConnectionException;
  14. public class TestConnection extends TestCase {
  15. private static final Logger log = LogManager
  16. .getLogger(TestConnection.class);
  17. private TransportFactory serviceTransportFactory;
  18. private Transport serviceTransport;
  19. private TransportFactory clientTransportFactory;
  20. private Transport clientTransport;
  21. public void setUp() throws ConnectionException, ConfigurationException {
  22. AtmiBrokerClientXML xml = new AtmiBrokerClientXML();
  23. Properties properties = xml.getProperties();
  24. serviceTransportFactory = TransportFactory.loadTransportFactory(
  25. "JAVA_Converse", properties);
  26. serviceTransport = serviceTransportFactory.createTransport();
  27. clientTransportFactory = TransportFactory.loadTransportFactory(
  28. "JAVA_Converse", properties);
  29. clientTransport = clientTransportFactory.createTransport();
  30. }
  31. public void tearDown() throws ConnectionException {
  32. clientTransport.close();
  33. serviceTransport.close();
  34. }
  35. public void test() throws ConnectionException {
  36. Receiver serviceDispatcher = serviceTransport
  37. .getReceiver("JAVA_Converse");
  38. Sender clientSender = clientTransport.getSender("JAVA_Converse");
  39. Receiver clientReceiver = clientTransport.createReceiver();
  40. clientSender.send(clientReceiver.getReplyTo(), (short) 1, 1, "hi"
  41. .getBytes(), 2, 0, 0, 0, "X_OCTET", null);
  42. Message receive = serviceDispatcher.receive(0);
  43. assertTrue(receive.len == 2);
  44. Sender serviceSender = serviceTransport.createSender(receive.replyTo);
  45. Receiver serviceReceiver = serviceTransport.createReceiver();
  46. log.info("Chatting");
  47. for (int i = 0; i < 100; i++) {
  48. serviceSender.send(serviceReceiver.getReplyTo(), (short) 1, 1,
  49. "chat".getBytes(), 4, 0, 0, 0, "X_OCTET", null);
  50. Message receive2 = clientReceiver.receive(0);
  51. assertTrue(receive2.len == 4);
  52. }
  53. log.info("Chatted");
  54. }
  55. }