javacommons/comms/tsrc/javaapi/javasrc/com/nokia/mj/test/comms/TestCommsServerEndpoint.java
changeset 21 2a9601315dfc
child 87 1627c337e51e
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.mj.test.comms;
       
    20 
       
    21 import j2meunit.framework.Test;
       
    22 import j2meunit.framework.TestCase;
       
    23 import j2meunit.framework.TestSuite;
       
    24 import j2meunit.framework.TestMethod;
       
    25 
       
    26 import com.nokia.mj.impl.comms.CommsMessage;
       
    27 import com.nokia.mj.impl.comms.CommsPermission;
       
    28 import com.nokia.mj.impl.comms.CommsEndpoint;
       
    29 import com.nokia.mj.impl.comms.CommsServerEndpoint;
       
    30 import com.nokia.mj.impl.comms.CommsEndpointBase;
       
    31 import com.nokia.mj.impl.comms.CommsListener;
       
    32 import com.nokia.mj.impl.comms.exception.CommsException;
       
    33 
       
    34 import com.nokia.mj.test.comms.utils.EchoListener;
       
    35 
       
    36 public class TestCommsServerEndpoint extends TestCase
       
    37 {
       
    38 
       
    39     private final int SERVER_ADDRESS = CommsEndpoint.JAVA_CAPTAIN + 1000;
       
    40     private final int MODULE_ID = 100;
       
    41 
       
    42     private final int TIMEOUT = 2;
       
    43 
       
    44     public TestCommsServerEndpoint()
       
    45     {
       
    46     }
       
    47 
       
    48     public TestCommsServerEndpoint(String sTestName, TestMethod rTestMethod)
       
    49     {
       
    50         super(sTestName, rTestMethod);
       
    51     }
       
    52 
       
    53     public Test suite()
       
    54     {
       
    55         TestSuite aSuite = new TestSuite();
       
    56 
       
    57         aSuite.addTest(new TestCommsServerEndpoint("testStartStop", new TestMethod()
       
    58         {
       
    59             public void run(TestCase tc)
       
    60             {
       
    61                 ((TestCommsServerEndpoint) tc).testStartStop();
       
    62             }
       
    63         }));
       
    64 
       
    65         aSuite.addTest(new TestCommsServerEndpoint("testDestroy", new TestMethod()
       
    66         {
       
    67             public void run(TestCase tc)
       
    68             {
       
    69                 ((TestCommsServerEndpoint) tc).testDestroy();
       
    70             }
       
    71         }));
       
    72 
       
    73         aSuite.addTest(new TestCommsServerEndpoint("testFind", new TestMethod()
       
    74         {
       
    75             public void run(TestCase tc)
       
    76             {
       
    77                 ((TestCommsServerEndpoint) tc).testFind();
       
    78             }
       
    79         }));
       
    80 
       
    81         aSuite.addTest(new TestCommsServerEndpoint("testConnect", new TestMethod()
       
    82         {
       
    83             public void run(TestCase tc)
       
    84             {
       
    85                 ((TestCommsServerEndpoint) tc).testConnect();
       
    86             }
       
    87         }));
       
    88 
       
    89         aSuite.addTest(new TestCommsServerEndpoint("testCheckPayload", new TestMethod()
       
    90         {
       
    91             public void run(TestCase tc)
       
    92             {
       
    93                 ((TestCommsServerEndpoint) tc).testCheckPayload();
       
    94             }
       
    95         }));
       
    96 
       
    97         aSuite.addTest(new TestCommsServerEndpoint("testBadListener", new TestMethod()
       
    98         {
       
    99             public void run(TestCase tc)
       
   100             {
       
   101                 ((TestCommsServerEndpoint) tc).testBadListener();
       
   102             }
       
   103         }));
       
   104 
       
   105         aSuite.addTest(new TestCommsServerEndpoint("testHasPermission", new TestMethod()
       
   106         {
       
   107             public void run(TestCase tc)
       
   108             {
       
   109                 ((TestCommsServerEndpoint) tc).testHasPermission();
       
   110             }
       
   111         }));
       
   112 
       
   113 
       
   114         aSuite.addTest(new TestCommsServerEndpoint("testSendInProcessMessage", new TestMethod()
       
   115         {
       
   116             public void run(TestCase tc)
       
   117             {
       
   118                 ((TestCommsServerEndpoint) tc).testSendInProcessMessage();
       
   119             }
       
   120         }));
       
   121 
       
   122         return aSuite;
       
   123     }
       
   124 
       
   125     public void assertEquals(byte[] a, byte[] b)
       
   126     {
       
   127         assertEquals(a.length, b.length);
       
   128         for (int i = 0; i < a.length; i++)
       
   129         {
       
   130             assertEquals(a[i], b[i]);
       
   131         }
       
   132     }
       
   133 
       
   134     public void testStartStop()
       
   135     {
       
   136         System.out.println("TestCommsServerEndpoint.testStartStop()");
       
   137 
       
   138         CommsServerEndpoint comms = null;
       
   139         // simple case
       
   140         try
       
   141         {
       
   142             comms = new CommsServerEndpoint();
       
   143             comms.start(SERVER_ADDRESS);
       
   144         }
       
   145         catch (CommsException e)
       
   146         {
       
   147             fail("ctor failed");
       
   148         }
       
   149         finally
       
   150         {
       
   151             comms.destroy();
       
   152             comms = null;
       
   153         }
       
   154 
       
   155         // multiple endpoints
       
   156         CommsServerEndpoint server1 = null;
       
   157         CommsServerEndpoint server2 = null;
       
   158         CommsServerEndpoint server3 = null;
       
   159         try
       
   160         {
       
   161             server1 = new CommsServerEndpoint();
       
   162             server2 = new CommsServerEndpoint();
       
   163             server3 = new CommsServerEndpoint();
       
   164 
       
   165             server1.start(SERVER_ADDRESS);
       
   166             server2.start(SERVER_ADDRESS+1);
       
   167             server3.start(SERVER_ADDRESS+2);
       
   168 
       
   169             server1.stop();
       
   170             server2.stop();
       
   171             server3.stop();
       
   172         }
       
   173         catch (CommsException e)
       
   174         {
       
   175             fail(" multiple endpoints failed");
       
   176         }
       
   177         finally
       
   178         {
       
   179             server1.destroy();
       
   180             server2.destroy();
       
   181             server3.destroy();
       
   182         }
       
   183 
       
   184         // multiple start/stop calls
       
   185         try
       
   186         {
       
   187             comms = new CommsServerEndpoint();
       
   188             comms.stop();
       
   189 
       
   190             comms.start(SERVER_ADDRESS);
       
   191             comms.start(SERVER_ADDRESS);
       
   192 
       
   193             comms.stop();
       
   194             comms.stop();
       
   195         }
       
   196         catch (CommsException e)
       
   197         {
       
   198             fail("multiple start/stop calls failed");
       
   199         }
       
   200         finally
       
   201         {
       
   202             comms.destroy();
       
   203             comms = null;
       
   204         }
       
   205 
       
   206         // start fails
       
   207         try
       
   208         {
       
   209             server1 = new CommsServerEndpoint();
       
   210             server2 = new CommsServerEndpoint();
       
   211 
       
   212             server1.start(SERVER_ADDRESS);
       
   213             server2.start(SERVER_ADDRESS);
       
   214             fail("start did not fail");
       
   215         }
       
   216         catch (CommsException e)
       
   217         {
       
   218         }
       
   219         finally
       
   220         {
       
   221             server1.destroy();
       
   222             server2.destroy();
       
   223         }
       
   224     }
       
   225 
       
   226 
       
   227     public void testDestroy()
       
   228     {
       
   229         System.out.println("TestCommsServerEndpoint.testDestroy()");
       
   230         class TestListener implements CommsListener
       
   231         {
       
   232             public void processMessage(CommsMessage message) {}
       
   233         }
       
   234         TestListener listener = new TestListener();
       
   235         CommsMessage msg = new CommsMessage();
       
   236 
       
   237         CommsServerEndpoint server = null;
       
   238         // simple case
       
   239         try
       
   240         {
       
   241             server = new CommsServerEndpoint();
       
   242             server.destroy();
       
   243         }
       
   244         catch (CommsException e)
       
   245         {
       
   246             fail("simple case failed");
       
   247         }
       
   248         finally
       
   249         {
       
   250             server.destroy();
       
   251             server = null;
       
   252         }
       
   253 
       
   254         // destroy when started
       
   255         try
       
   256         {
       
   257             server = new CommsServerEndpoint();
       
   258             server.start(SERVER_ADDRESS);
       
   259             server.destroy();
       
   260         }
       
   261         catch (CommsException e)
       
   262         {
       
   263             fail("close when started failed");
       
   264         }
       
   265         finally
       
   266         {
       
   267             server.destroy();
       
   268             server = null;
       
   269         }
       
   270 
       
   271         // calling methods after close
       
   272         try
       
   273         {
       
   274             server = new CommsServerEndpoint();
       
   275             server.destroy();
       
   276             server.destroy();
       
   277             try
       
   278             {
       
   279                 server.start(SERVER_ADDRESS);
       
   280                 fail("start");
       
   281             }
       
   282             catch (CommsException e) {}
       
   283 
       
   284             try
       
   285             {
       
   286                 server.stop();
       
   287                 fail("stop");
       
   288             }
       
   289             catch (CommsException e) {}
       
   290 
       
   291             try
       
   292             {
       
   293                 server.registerListener(MODULE_ID, listener);
       
   294                 fail("registerListener");
       
   295             }
       
   296             catch (Exception e) {}
       
   297 
       
   298             try
       
   299             {
       
   300                 server.unregisterListener(MODULE_ID);
       
   301                 fail("unregisterListener");
       
   302             }
       
   303             catch (Exception e) {}
       
   304 
       
   305             try
       
   306             {
       
   307                 server.registerDefaultListener(listener);
       
   308                 fail("registerDefaultListener");
       
   309             }
       
   310             catch (Exception e) {}
       
   311 
       
   312             try
       
   313             {
       
   314                 server.unregisterDefaultListener();
       
   315                 fail("unregisterDefaultListener");
       
   316             }
       
   317             catch (Exception e) {}
       
   318 
       
   319             try
       
   320             {
       
   321                 server.send(msg);
       
   322                 fail("send");
       
   323             }
       
   324             catch (Exception e) {}
       
   325 
       
   326             try
       
   327             {
       
   328                 CommsMessage m = server.sendReceive(msg, TIMEOUT);
       
   329                 fail("send");
       
   330             }
       
   331             catch (Exception e) {}
       
   332 
       
   333         }
       
   334         catch (CommsException e)
       
   335         {
       
   336             fail(" multiple endpoints failed");
       
   337         }
       
   338         finally
       
   339         {
       
   340             server.destroy();
       
   341             server = null;
       
   342         }
       
   343 
       
   344     }
       
   345 
       
   346     public void testFind()
       
   347     {
       
   348         System.out.println("TestCommsServerEndpoint.testFind()");
       
   349 
       
   350         CommsServerEndpoint comms = null;
       
   351 
       
   352         // not existing
       
   353         comms = CommsServerEndpoint.find("not existing");
       
   354         assertEquals(comms, null);
       
   355         comms = null;
       
   356     }
       
   357 
       
   358     public void testConnect()
       
   359     {
       
   360         System.out.println("TestCommsServerEndpoint.testConnect()");
       
   361         CommsMessage msg = new CommsMessage();
       
   362 
       
   363         CommsServerEndpoint server = null;
       
   364         CommsEndpoint client = null;
       
   365         // One client
       
   366         try
       
   367         {
       
   368             server = new CommsServerEndpoint();
       
   369             EchoListener listener = new EchoListener(server);
       
   370             server.start(SERVER_ADDRESS);
       
   371             server.registerDefaultListener(listener);
       
   372 
       
   373             client = new CommsEndpoint();
       
   374             client.connect(SERVER_ADDRESS);
       
   375             client.sendReceive(msg, TIMEOUT);
       
   376 
       
   377             client.disconnect();
       
   378             server.stop();
       
   379 
       
   380             server.start(SERVER_ADDRESS+1);
       
   381             client.connect(SERVER_ADDRESS+1);
       
   382             client.sendReceive(msg, TIMEOUT);
       
   383 
       
   384             client.disconnect();
       
   385             server.stop();
       
   386         }
       
   387         catch (Exception e)
       
   388         {
       
   389             fail("testConnect one client failed");
       
   390         }
       
   391         finally
       
   392         {
       
   393             server.destroy();
       
   394             server = null;
       
   395             client.destroy();
       
   396         }
       
   397 
       
   398         // multiple clients
       
   399         CommsEndpoint client1 = null;
       
   400         CommsEndpoint client2 = null;
       
   401         CommsEndpoint client3 = null;
       
   402         try
       
   403         {
       
   404             server = new CommsServerEndpoint();
       
   405             server.start(SERVER_ADDRESS);
       
   406             EchoListener listener = new EchoListener(server);
       
   407             server.registerDefaultListener(listener);
       
   408 
       
   409             client1 = new CommsEndpoint();
       
   410             client2 = new CommsEndpoint();
       
   411             client3 = new CommsEndpoint();
       
   412 
       
   413             client1.connect(SERVER_ADDRESS);
       
   414             client2.connect(SERVER_ADDRESS);
       
   415             client3.connect(SERVER_ADDRESS);
       
   416             client1.sendReceive(msg, TIMEOUT);
       
   417             client2.sendReceive(msg, TIMEOUT);
       
   418             client3.sendReceive(msg, TIMEOUT);
       
   419 
       
   420             client1.disconnect();
       
   421             client2.disconnect();
       
   422             client3.disconnect();
       
   423             server.stop();
       
   424         }
       
   425         catch (Exception e)
       
   426         {
       
   427             fail("testConnect multiple clients failed");
       
   428         }
       
   429         finally
       
   430         {
       
   431             server.destroy();
       
   432             server = null;
       
   433             client1.destroy();
       
   434             client2.destroy();
       
   435             client3.destroy();
       
   436         }
       
   437     }
       
   438 
       
   439 
       
   440     public void testCheckPayload()
       
   441     {
       
   442         System.out.println("TestCommsServerEndpoint.testCheckPayload()");
       
   443 
       
   444         CommsServerEndpoint server = null;
       
   445         CommsEndpoint comms = null;
       
   446         try
       
   447         {
       
   448             server = new CommsServerEndpoint();
       
   449             server.start(SERVER_ADDRESS);
       
   450             EchoListener listener = new EchoListener(server);
       
   451             server.registerDefaultListener(listener);
       
   452 
       
   453             comms = new CommsEndpoint();
       
   454             comms.connect(SERVER_ADDRESS);
       
   455 
       
   456             CommsMessage message = new CommsMessage();
       
   457             message.setMessageId(0xDEADBEEF);
       
   458             message.setModuleId(0xFF000000);
       
   459             byte[] bytes = "abcdefghijklmnopqrstyvwxyz".getBytes();
       
   460             message.write(bytes);
       
   461 
       
   462             // normal case
       
   463             CommsMessage msg = comms.sendReceive(message, TIMEOUT);
       
   464             assertEquals(msg.getMessageId(), message.getMessageId());
       
   465             assertEquals(msg.getModuleId(), message.getModuleId());
       
   466             byte[] b = msg.readBytes();
       
   467             assertEquals(b, bytes);
       
   468 
       
   469             // empty message
       
   470             CommsMessage empty = new CommsMessage();
       
   471             CommsMessage msg2 = comms.sendReceive(empty, TIMEOUT);
       
   472             assertNotNull(msg2);
       
   473             assertEquals(msg2.getMessageId(), empty.getMessageId());
       
   474             assertEquals(msg2.getModuleId(), empty.getModuleId());
       
   475 
       
   476             // large message
       
   477             CommsMessage bigOne = new CommsMessage();
       
   478             bigOne.setMessageId(-1);
       
   479             bigOne.setModuleId(-1);
       
   480             byte[] array = new byte [50000];
       
   481             for (int i = 0; i < array.length; i++)
       
   482             {
       
   483                 array[i] = (byte)i;
       
   484             }
       
   485             bigOne.write(array);
       
   486             CommsMessage msg3 = comms.sendReceive(bigOne, TIMEOUT);
       
   487             assertEquals(msg3.getMessageId(), bigOne.getMessageId());
       
   488             assertEquals(msg3.getModuleId(), bigOne.getModuleId());
       
   489             byte[] big = msg3.readBytes();
       
   490             assertEquals(big, array);
       
   491 
       
   492             // Unicode string
       
   493             StringBuffer sb = new StringBuffer();
       
   494             sb.append('\u00a5'); // Japanese Yen symbol
       
   495             sb.append('\u01FC'); // Roman AE with acute accent
       
   496             sb.append('\u0391'); // Greek Capital Alpha
       
   497             sb.append('\u03A9'); // Greek Capital Omega
       
   498             sb.append('\u20ac'); // Euro symbol
       
   499             sb.append('\u20a8'); // Rupee symbol
       
   500             sb.append('\u040F'); // Cyrillic capital letter DZHE
       
   501             sb.append('\u062A'); // Arabic letter TEH
       
   502 
       
   503             String in = sb.toString();
       
   504             message = new CommsMessage();
       
   505             message.write(in);
       
   506             msg = comms.sendReceive(message, TIMEOUT);
       
   507             String out = msg.readString();
       
   508             assertEquals(in, out);
       
   509 
       
   510         }
       
   511         catch (Exception e)
       
   512         {
       
   513             e.printStackTrace();
       
   514             fail("testCheckPayload failed");
       
   515         }
       
   516         finally
       
   517         {
       
   518             comms.destroy();
       
   519             server.destroy();
       
   520         }
       
   521     }
       
   522 
       
   523     public void testBadListener()
       
   524     {
       
   525         System.out.println("TestCommsServerEndpoint.testBadListener()");
       
   526         class BadListener implements CommsListener
       
   527         {
       
   528             public void processMessage(CommsMessage message)
       
   529             {
       
   530                 int[] arr = new int[1];
       
   531                 // throws exception on purpose
       
   532                 int i = arr[arr.length+1];
       
   533             }
       
   534         }
       
   535 
       
   536         CommsServerEndpoint server = null;
       
   537         CommsEndpoint comms = null;
       
   538         try
       
   539         {
       
   540             server = new CommsServerEndpoint();
       
   541             server.registerDefaultListener(new BadListener());
       
   542             server.start(SERVER_ADDRESS);
       
   543 
       
   544             comms = new CommsEndpoint();
       
   545             comms.registerDefaultListener(new BadListener());
       
   546             comms.connect(SERVER_ADDRESS);
       
   547 
       
   548             // exception in server side processMessage
       
   549             comms.send(new CommsMessage());
       
   550             Thread.sleep(100); // give time to receive message
       
   551 
       
   552             server.unregisterDefaultListener();
       
   553             server.registerDefaultListener(new EchoListener(server));
       
   554             comms.sendReceive(new CommsMessage(), TIMEOUT);
       
   555 
       
   556             // exception in client side processMessage
       
   557             comms.send(new CommsMessage());
       
   558             Thread.sleep(100); // give time to receive message
       
   559             comms.sendReceive(new CommsMessage(), TIMEOUT);
       
   560 
       
   561         }
       
   562         catch (Exception e)
       
   563         {
       
   564             e.printStackTrace();
       
   565             fail("testBadListener failed");
       
   566         }
       
   567         finally
       
   568         {
       
   569             comms.destroy();
       
   570             server.destroy();
       
   571         }
       
   572     }
       
   573 
       
   574 
       
   575     public void testHasPermission()
       
   576     {
       
   577         System.out.println("TestCommsServerEndpoint.testHasPermission()");
       
   578         class PermissionListener implements CommsListener
       
   579         {
       
   580             private CommsEndpointBase iComms = null;
       
   581             public CommsMessage receivedMsg;
       
   582 
       
   583             public PermissionListener(CommsEndpointBase aComms)
       
   584             {
       
   585                 iComms = aComms;
       
   586             }
       
   587 
       
   588             public void processMessage(CommsMessage aMessage)
       
   589             {
       
   590                 try
       
   591                 {
       
   592                     receivedMsg = new CommsMessage(aMessage.toByteArray());
       
   593                     CommsMessage msg = new CommsMessage();
       
   594                     msg.replyTo(aMessage);
       
   595                     iComms.send(msg);
       
   596                 }
       
   597                 catch (Exception e)
       
   598                 {
       
   599                     System.out.println(e);
       
   600                 }
       
   601             }
       
   602         }
       
   603 
       
   604         CommsServerEndpoint server = null;
       
   605         CommsEndpoint comms = null;
       
   606         try
       
   607         {
       
   608             server = new CommsServerEndpoint();
       
   609             PermissionListener listener = new PermissionListener(server);
       
   610             server.registerDefaultListener(listener);
       
   611             server.start(SERVER_ADDRESS);
       
   612 
       
   613             comms = new CommsEndpoint();
       
   614             comms.connect(SERVER_ADDRESS);
       
   615 
       
   616             CommsMessage msg = comms.sendReceive(new CommsMessage(), TIMEOUT);
       
   617 
       
   618             assertTrue(msg.hasPermission(CommsPermission.MANAGE_CERTIFICATES));
       
   619             assertTrue(msg.hasPermission(CommsPermission.INSTALL_APPLICATION));
       
   620             assertTrue(msg.hasPermission(CommsPermission.LAUNCH_APPLICATION));
       
   621             assertTrue(msg.hasPermission(CommsPermission.STOP_APPLICATION));
       
   622 
       
   623             assertTrue(listener.receivedMsg.hasPermission(CommsPermission.MANAGE_CERTIFICATES));
       
   624             assertTrue(listener.receivedMsg.hasPermission(CommsPermission.INSTALL_APPLICATION));
       
   625             assertTrue(listener.receivedMsg.hasPermission(CommsPermission.LAUNCH_APPLICATION));
       
   626 
       
   627             // javainstaller does not have STOP_APPLICATION permission in S60
       
   628             String platform = System.getProperty("os.name");
       
   629             if (platform != null && platform.equalsIgnoreCase("linux"))
       
   630             {
       
   631                 assertTrue(listener.receivedMsg.hasPermission(CommsPermission.STOP_APPLICATION));
       
   632             }
       
   633             else
       
   634             {
       
   635                 assertTrue(!listener.receivedMsg.hasPermission(CommsPermission.STOP_APPLICATION));
       
   636             }
       
   637 
       
   638             comms.disconnect();
       
   639             server.stop();
       
   640         }
       
   641         catch (Exception e)
       
   642         {
       
   643             e.printStackTrace();
       
   644             fail("testHasPermission failed");
       
   645         }
       
   646         finally
       
   647         {
       
   648             comms.destroy();
       
   649             server.destroy();
       
   650         }
       
   651     }
       
   652 
       
   653 
       
   654     public void testSendInProcessMessage()
       
   655     {
       
   656         System.out.println("TestCommsServerEndpoint.testSendInProcessMessage()");
       
   657 
       
   658         class TestListener extends EchoListener
       
   659         {
       
   660             int iReplyCount = 30;
       
   661             public TestListener(CommsEndpointBase aComms)
       
   662             {
       
   663                 super(aComms);
       
   664             }
       
   665 
       
   666             public void processMessage(CommsMessage message)
       
   667             {
       
   668                 super.processMessage(message);
       
   669                 if (--iReplyCount<0)
       
   670                 {
       
   671                     synchronized (this)
       
   672                     {
       
   673                         this.notifyAll();
       
   674                     }
       
   675                 }
       
   676             }
       
   677 
       
   678             public void doWait()
       
   679             {
       
   680                 synchronized (this)
       
   681                 {
       
   682                     try
       
   683                     {
       
   684                         this.wait();
       
   685                     }
       
   686                     catch (InterruptedException ie) {}
       
   687                 }
       
   688             }
       
   689         }
       
   690 
       
   691         CommsServerEndpoint server = null;
       
   692         CommsEndpoint comms = null;
       
   693         try
       
   694         {
       
   695             server = new CommsServerEndpoint();
       
   696             EchoListener listener = new EchoListener(server);
       
   697             server.registerDefaultListener(listener);
       
   698             server.start(SERVER_ADDRESS);
       
   699 
       
   700             comms = new CommsEndpoint();
       
   701             TestListener listener2 = new TestListener(comms);
       
   702             comms.registerDefaultListener(listener2);
       
   703             comms.connect(SERVER_ADDRESS);
       
   704 
       
   705             CommsMessage msg = new CommsMessage();
       
   706             msg.write("hello world");
       
   707             comms.send(msg);
       
   708 
       
   709             // message is beeing sent back and forth between listeners
       
   710             listener2.doWait();
       
   711 
       
   712             comms.disconnect();
       
   713             server.stop();
       
   714         }
       
   715         catch (Exception e)
       
   716         {
       
   717             e.printStackTrace();
       
   718             fail("testSendInProcessMessage failed");
       
   719         }
       
   720         finally
       
   721         {
       
   722             comms.destroy();
       
   723             server.destroy();
       
   724         }
       
   725     }
       
   726 
       
   727 
       
   728 
       
   729 }
       
   730