xmlBlaster 2.2.0 API

org.xmlBlaster.test.client
Class TestFailSafeAsync

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.xmlBlaster.test.client.TestFailSafeAsync
All Implemented Interfaces:
junit.framework.Test, I_Callback, I_ConnectionStateListener

public class TestFailSafeAsync
extends junit.framework.TestCase
implements I_Callback, I_ConnectionStateListener

Tests the fail save behavior of the I_XmlBlasterAccess client helper class, especially the asynchronous playback of messages.

When the connection to xmlBlaster is lost, and you continue to publish messages they are stored locally with the invocation recorder on harddisk.
On reconnect they are flushed with an adjustable rate in background.
If your client code decides to publish new messages during playback recovery, your new messages will overtake some of the play back messages.

If you want guaranteed sequence, please don't send messages during playback.

Invoke examples:

   java junit.textui.TestRunner -noloading org.xmlBlaster.test.client.TestFailSafeAsync
   java junit.swingui.TestRunner -noloading org.xmlBlaster.test.client.TestFailSafeAsync
 


Field Summary
private  I_XmlBlasterAccess con
           
private  java.lang.String contentMime
           
private  int failMsg
           
private  Global glob
           
private static java.util.logging.Logger log
           
private  int maxEntries
          TEST: Sendin 0-19 directly, sending 20-39 to recorder (no connection), sending 40-100 directly
private static java.lang.String ME
           
private  int numNormalPublishReceived
           
private  int numReceived
           
private  int numTailbackReceived
           
(package private)  PublishKey publishKeyWrapper
           
(package private)  PublishQos publishQosWrapper
           
private  long publishRate
          publish rate msg/sec
private  long pullbackRate
          publish rate of tailback msg/sec
private  boolean reconnected
           
private  int reconnectMsg
           
private  java.lang.String senderName
           
private  int serverPort
           
private  EmbeddedXmlBlaster serverThread
           
private  MsgInterceptor updateInterceptor
           
 
Constructor Summary
TestFailSafeAsync(Global glob, java.lang.String testName)
           
TestFailSafeAsync(java.lang.String testName)
           
 
Method Summary
static void main(java.lang.String[] args)
          Deprecated. Use the TestRunner from the testsuite to run it:

   java -Djava.compiler= junit.textui.TestRunner org.xmlBlaster.test.client.TestFailSafeAsync
 void publish(int counter)
          Construct a message and publish it.
 void reachedAlive(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess notifying the client that a connection has been established and that its status is now ALIVE.
 void reachedAliveSync(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
          Invoked when the dispatcher goes to synch again after having delivered entries which where in the queue when the state changed to ALIVE.
 void reachedDead(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess informing the client that the connection was lost (i.e.
 void reachedPolling(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess informing the client that the connection state has changed to POLLING.
protected  void setUp()
          Sets up the fixture.
 void subscribe()
          TEST: Subscribe to messages with XPATH.
protected  void tearDown()
          Tears down the fixture.
 void testFailSafe()
          TEST: Sendin 0-19 directly, sending 20-39 to recorder (no connection), sending 40-100 directly
 java.lang.String update(java.lang.String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos)
          This is the callback method invoked from xmlBlaster delivering us a new asynchronous message.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ME

private static java.lang.String ME

glob

private Global glob

log

private static java.util.logging.Logger log

serverPort

private int serverPort

serverThread

private EmbeddedXmlBlaster serverThread

updateInterceptor

private MsgInterceptor updateInterceptor

con

private I_XmlBlasterAccess con

senderName

private java.lang.String senderName

numReceived

private int numReceived

numTailbackReceived

private int numTailbackReceived

numNormalPublishReceived

private int numNormalPublishReceived

contentMime

private final java.lang.String contentMime
See Also:
Constant Field Values

reconnected

private boolean reconnected

maxEntries

private final int maxEntries
TEST: Sendin 0-19 directly, sending 20-39 to recorder (no connection), sending 40-100 directly

See Also:
Constant Field Values

failMsg

private final int failMsg
See Also:
Constant Field Values

reconnectMsg

private final int reconnectMsg
See Also:
Constant Field Values

publishRate

private final long publishRate
publish rate msg/sec

See Also:
Constant Field Values

pullbackRate

private final long pullbackRate
publish rate of tailback msg/sec

See Also:
Constant Field Values

publishKeyWrapper

PublishKey publishKeyWrapper

publishQosWrapper

PublishQos publishQosWrapper
Constructor Detail

TestFailSafeAsync

public TestFailSafeAsync(java.lang.String testName)

TestFailSafeAsync

public TestFailSafeAsync(Global glob,
                         java.lang.String testName)
Method Detail

setUp

protected void setUp()
Sets up the fixture.

Connect to xmlBlaster and login

Overrides:
setUp in class junit.framework.TestCase

tearDown

protected void tearDown()
Tears down the fixture.

cleaning up .... erase() the previous message OID and logout

Overrides:
tearDown in class junit.framework.TestCase

subscribe

public void subscribe()
TEST: Subscribe to messages with XPATH.


publish

public void publish(int counter)
Construct a message and publish it.


testFailSafe

public void testFailSafe()
TEST: Sendin 0-19 directly, sending 20-39 to recorder (no connection), sending 40-100 directly


reachedAlive

public void reachedAlive(ConnectionStateEnum oldState,
                         I_XmlBlasterAccess connection)
Description copied from interface: I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess notifying the client that a connection has been established and that its status is now ALIVE.

Note that this method is invoked also when the connection has been established the first time. In this case the connection is fully operational but your connect() call has not yet returned. You can access the returned connect QoS in this case with connect.getConnectReturnQos().

You can erase all entries of the queue manually or add others before you return and in this way control the behavior. During you have control in reachedAlive() the client side queue is blocked and does not accept publish or request messages from other threads. So you can do peacefully your work (your thread is allowed to modify the queue exclusively).

If you send messages during this method invocation they are queued only and are sent as soon as this method returns.

This method is invoked by the login polling thread from I_XmlBlasterAccess in which case it is a physical Alive, and by the connect method on successful login in which case it is a logical Alive.

Specified by:
reachedAlive in interface I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.

reachedAliveSync

public void reachedAliveSync(ConnectionStateEnum oldState,
                             I_XmlBlasterAccess connection)
Description copied from interface: I_ConnectionStateListener
Invoked when the dispatcher goes to synch again after having delivered entries which where in the queue when the state changed to ALIVE. Note that this could take some time or in the worst case it could never been invoked if the queue is never completely processed.

Specified by:
reachedAliveSync in interface I_ConnectionStateListener
Parameters:
oldState - is always ALIVE.

reachedPolling

public void reachedPolling(ConnectionStateEnum oldState,
                           I_XmlBlasterAccess connection)
Description copied from interface: I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess informing the client that the connection state has changed to POLLING.

Specified by:
reachedPolling in interface I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.

reachedDead

public void reachedDead(ConnectionStateEnum oldState,
                        I_XmlBlasterAccess connection)
Description copied from interface: I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess informing the client that the connection was lost (i.e. when the state of the connection has gone to DEAD).

Specified by:
reachedDead in interface I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.

update

public java.lang.String update(java.lang.String cbSessionId,
                               UpdateKey updateKey,
                               byte[] content,
                               UpdateQos updateQos)
This is the callback method invoked from xmlBlaster delivering us a new asynchronous message.

Specified by:
update in interface I_Callback
Parameters:
cbSessionId - The session ID specified by the client which registered the callback. You can specify a cbSessionId during connection (with ConnectQos) and this is bounced back here so you can authenticate the message.
updateKey - The arrived key containing the topic name
content - The arrived message content. This is your payload.
See Also:
I_Callback.update(String, UpdateKey, byte[], UpdateQos)

main

public static void main(java.lang.String[] args)
Deprecated. Use the TestRunner from the testsuite to run it:

   java -Djava.compiler= junit.textui.TestRunner org.xmlBlaster.test.client.TestFailSafeAsync

Invoke: java org.xmlBlaster.test.client.TestFailSafeAsync


xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.