[Jboss-cvs] JBoss Messaging SVN: r1340 - in trunk: src/etc/server/default/deploy src/etc/xmdesc src/main/org/jboss/jms/server/endpoint src/main/org/jboss/jms/server/remoting src/main/org/jboss/messaging/core src/main/org/jboss/messaging/core/plugin src/main/org/jboss/messaging/core/plugin/contract src/main/org/jboss/messaging/core/plugin/postoffice/cluster tests/src/org/jboss/test/messaging/core tests/src/org/jboss/test/messaging/core/paging tests/src/org/jboss/test/messaging/core/plugin tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster tests/src/org/jboss/test/messaging/jms
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Sep 21 18:03:25 EDT 2006
Author: timfox
Date: 2006-09-21 18:02:48 -0400 (Thu, 21 Sep 2006)
New Revision: 1340
Added:
trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/DefaultClusteredPostOfficeTest.java
Removed:
trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java
Modified:
trunk/src/etc/server/default/deploy/hsqldb-persistence-service.xml
trunk/src/etc/xmdesc/ClusteredPostOffice-xmbean.xml
trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectInputStream.java
trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectOutputStream.java
trunk/src/main/org/jboss/messaging/core/ChannelSupport.java
trunk/src/main/org/jboss/messaging/core/PagingChannelSupport.java
trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java
trunk/src/main/org/jboss/messaging/core/plugin/contract/PersistenceManager.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/DefaultClusteredPostOffice.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/LocalClusteredQueue.java
trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java
trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_2PCTest.java
trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_NTTest.java
trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_TTest.java
trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_2PCTest.java
trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_NTTest.java
trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_TTest.java
trunk/tests/src/org/jboss/test/messaging/core/paging/PagingStateTestBase.java
trunk/tests/src/org/jboss/test/messaging/core/paging/SingleChannel_ReloadTest.java
trunk/tests/src/org/jboss/test/messaging/core/plugin/JDBCPersistenceManagerTest.java
trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java
Log:
More clustering distributed destinations work
Modified: trunk/src/etc/server/default/deploy/hsqldb-persistence-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/hsqldb-persistence-service.xml 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/etc/server/default/deploy/hsqldb-persistence-service.xml 2006-09-21 22:02:48 UTC (rev 1340)
@@ -59,9 +59,7 @@
<attribute name="GroupName">cluster1</attribute>
<attribute name="StateTimeout">5000</attribute>
<attribute name="CastTimeout">5000</attribute>
- <attribute name="RedistributionPeriod">5000</attribute>
- <attribute name="SyncPullSize">1</attribute>
- <attribute name="AsyncPullSize">50</attribute>
+ <attribute name="PullSize">1</attribute>
<attribute name="SyncChannelConfig">
<UDP mcast_addr="228.8.8.8" mcast_port="45568"
ip_ttl="8" ip_mcast="true"
Modified: trunk/src/etc/xmdesc/ClusteredPostOffice-xmbean.xml
===================================================================
--- trunk/src/etc/xmdesc/ClusteredPostOffice-xmbean.xml 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/etc/xmdesc/ClusteredPostOffice-xmbean.xml 2006-09-21 22:02:48 UTC (rev 1340)
@@ -59,24 +59,12 @@
<type>long</type>
</attribute>
- <attribute access="read-write" getMethod="getRedistributionPeriod" setMethod="setRedistributionPeriod">
- <description>The period between which successive message redistribution calculations will be performed</description>
- <name>RedistributionPeriod</name>
- <type>long</type>
- </attribute>
-
- <attribute access="read-write" getMethod="getSyncPullSize" setMethod="setSyncPullSize">
- <description>The maximum number of message to pull synchronously in one go from a remote queue when the local queue consumers are starving</description>
+ <attribute access="read-write" getMethod="getPullSize" setMethod="setPullSize">
+ <description>The maximum number of message to pull in one go from a remote queue when the local queue consumers are starving</description>
<name>SyncPullSize</name>
<type>int</type>
</attribute>
- <attribute access="read-write" getMethod="getAsyncPullSize" setMethod="setAsyncPullSize">
- <description>The maximum number of message to pull aysynchronously in one go from a remote queue when the local queue consumers are starving</description>
- <name>AsyncPullSize</name>
- <type>int</type>
- </attribute>
-
<attribute access="read-write" getMethod="getSyncChannelConfig" setMethod="setSyncChannelConfig">
<description>The JGroups stack configuration for the synchronous channel</description>
<name>SyncChannelConfig</name>
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -206,8 +206,6 @@
{
if (trace) { log.trace(this + " receives " + ref + " for delivery"); }
- log.info("BEING OFFERED -------- " + ref);
-
// This is ok to have outside lock - is volatile
if (bufferFull)
{
Modified: trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectInputStream.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectInputStream.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectInputStream.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -45,10 +45,7 @@
public MessagingObjectInputStream(InputStream in) throws IOException, SecurityException
{
- super(in);
-
- this.in = in;
-
+ this.in = in;
}
public InputStream getUnderlyingStream()
Modified: trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectOutputStream.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectOutputStream.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectOutputStream.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -42,7 +42,6 @@
public MessagingObjectOutputStream(OutputStream out) throws IOException
{
- super(out);
this.out = out;
}
Modified: trunk/src/main/org/jboss/messaging/core/ChannelSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/ChannelSupport.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/messaging/core/ChannelSupport.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -226,6 +226,11 @@
public boolean remove(Receiver r)
{
boolean removed = router.remove(r);
+
+ if (removed && !router.iterator().hasNext())
+ {
+ receiversReady = false;
+ }
if (trace) { log.trace(this + (removed ? " removed " : " did NOT remove ") + r); }
Modified: trunk/src/main/org/jboss/messaging/core/PagingChannelSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/PagingChannelSupport.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/messaging/core/PagingChannelSupport.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -235,6 +235,7 @@
unload();
+ //Load the unpaged references
InitialLoadInfo ili = pm.getInitialReferenceInfos(channelID, fullSize);
if (ili.getMaxPageOrdering() != null)
@@ -250,18 +251,27 @@
firstPagingOrder = nextPagingOrder = 0;
}
- Map refMap = processReferences(ili.getRefInfos());
+ log.info("Loading channel");
+ log.info("Got " + ili.getRefInfos().size() + " intial refs");
+
+ Map refMap = processReferences(ili.getRefInfos());
+
Iterator iter = ili.getRefInfos().iterator();
while (iter.hasNext())
{
ReferenceInfo info = (ReferenceInfo)iter.next();
addFromRefInfo(info, refMap);
- }
+ }
+
+ //Maybe we need to load some paged refs
+
+ while (checkLoad()) {}
}
}
-
+
+
public void unload() throws Exception
{
synchronized (refLock)
@@ -296,6 +306,74 @@
// Protected -------------------------------------------------------
+ protected void loadPagedReferences(long number) throws Exception
+ {
+ if (trace) { log.trace(this + " Loading " + number + " paged references from storage"); }
+
+ // Must flush the down cache first
+ flushDownCache();
+
+ List refInfos = pm.getPagedReferenceInfos(channelID, firstPagingOrder, number);
+
+ Map refMap = processReferences(refInfos);
+
+ boolean loadedReliable = false;
+
+ List toRemove = new ArrayList();
+
+ int unreliableNumber = 0;
+
+ Iterator iter = refInfos.iterator();
+ while (iter.hasNext())
+ {
+ ReferenceInfo info = (ReferenceInfo)iter.next();
+
+ MessageReference ref = addFromRefInfo(info, refMap);
+
+ if (recoverable && ref.isReliable())
+ {
+ loadedReliable = true;
+ }
+ else
+ {
+ // We put the non reliable refs (or reliable in a non-recoverable store)
+ // in a list to be removed
+ toRemove.add(ref);
+
+ unreliableNumber++;
+ }
+ }
+
+ if (!toRemove.isEmpty())
+ {
+ // Now we remove the references we loaded (only the non persistent or persistent in a non-recoverable store)
+
+ pm.removeReferences(channelID, toRemove);
+ }
+
+ if (loadedReliable)
+ {
+ // If we loaded any reliable refs then we must set the page ordering to null in
+ // the store otherwise they may get loaded again, the next time we do a load
+ // We can't delete them since they're reliable and haven't been acked yet
+
+ pm.updateReliableReferencesNotPagedInRange(channelID, firstPagingOrder, firstPagingOrder + number - 1, number - unreliableNumber);
+ }
+
+ firstPagingOrder += number;
+
+ if (firstPagingOrder == nextPagingOrder)
+ {
+ //No more refs in storage
+ firstPagingOrder = nextPagingOrder = 0;
+
+ if (messageRefs.size() != fullSize)
+ {
+ paging = false;
+ }
+ }
+ }
+
protected boolean cancelInternal(Delivery del) throws Exception
{
if (trace) { log.trace(this + " cancelling " + del + " in memory"); }
@@ -345,25 +423,39 @@
{
MessageReference result = (MessageReference) messageRefs.removeFirst();
- long refNum = downCache.size() + nextPagingOrder - firstPagingOrder ;
-
- if (refNum > 0)
+ checkLoad();
+
+ return (MessageReference) result;
+ }
+ }
+
+ private boolean checkLoad() throws Exception
+ {
+ long refNum = downCache.size() + nextPagingOrder - firstPagingOrder;
+
+ if (refNum > 0)
+ {
+ long numberLoadable = Math.min(refNum, pageSize);
+
+ if (messageRefs.size() <= fullSize - numberLoadable)
{
- long numberLoadable = Math.min(refNum, pageSize);
-
- if (messageRefs.size() <= fullSize - numberLoadable)
- {
- //This will flush the down cache too
- loadPagedReferences(numberLoadable);
- }
+ //This will flush the down cache too
+ log.info("Loading " + numberLoadable + " refs");
+ loadPagedReferences(numberLoadable);
+
+ return true;
}
else
{
- paging = false;
+ return false;
}
-
- return (MessageReference) result;
}
+ else
+ {
+ paging = false;
+
+ return false;
+ }
}
protected void addReferenceInMemory(MessageReference ref) throws Exception
@@ -468,7 +560,7 @@
if (!toAdd.isEmpty())
{
- pm.addReferences(channelID, toAdd);
+ pm.addReferences(channelID, toAdd, true);
}
if (!toUpdate.isEmpty())
{
@@ -494,70 +586,6 @@
- protected void loadPagedReferences(long number) throws Exception
- {
- if (trace) { log.trace(this + " Loading " + number + " paged references from storage"); }
-
- // Must flush the down cache first
- flushDownCache();
-
- List refInfos = pm.getPagedReferenceInfos(channelID, firstPagingOrder, number);
-
- Map refMap = processReferences(refInfos);
-
- boolean loadedReliable = false;
-
- List toRemove = new ArrayList();
-
- Iterator iter = refInfos.iterator();
- while (iter.hasNext())
- {
- ReferenceInfo info = (ReferenceInfo)iter.next();
-
- MessageReference ref = addFromRefInfo(info, refMap);
-
- if (recoverable && ref.isReliable())
- {
- loadedReliable = true;
- }
- else
- {
- // We put the non reliable refs (or reliable in a non-recoverable store)
- // in a list to be removed
- toRemove.add(ref);
- }
- }
-
- if (!toRemove.isEmpty())
- {
- // Now we remove the references we loaded (only the non persistent or persistent in a non-recoverable store)
-
- pm.removeReferences(channelID, toRemove);
- }
-
- if (loadedReliable)
- {
- // If we loaded any reliable refs then we must set the page ordering to null in
- // the store otherwise they may get loaded again, the next time we do a load
- // We can't delete them since they're reliable and haven't been acked yet
-
- pm.updateReliableReferencesNotPagedInRange(channelID, firstPagingOrder, number);
- }
-
- firstPagingOrder += number;
-
- if (firstPagingOrder == nextPagingOrder)
- {
- //No more refs in storage
- firstPagingOrder = nextPagingOrder = 0;
-
- if (messageRefs.size() != fullSize)
- {
- paging = false;
- }
- }
- }
-
// Private ------------------------------------------------------------------------------
private MessageReference addFromRefInfo(ReferenceInfo info, Map refMap)
Modified: trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -139,9 +139,10 @@
{
conn.close();
}
-
- removeUnreliableMessageData();
+ //We can't remnove unreliable data since it might introduce holes into the paging order
+ //removeUnreliableMessageData();
+
log.debug(this + " started");
}
@@ -274,16 +275,16 @@
// Related to paging functionality
// ===============================
- public void updateReliableReferencesNotPagedInRange(long channelID, long orderStart, long number) throws Exception
+ public void updateReliableReferencesNotPagedInRange(long channelID, long orderStart, long orderEnd, long num) throws Exception
{
if (trace)
{
- log.trace("Updating reliable references for channel " + channelID + " between " + orderStart + " number " + number);
+ log.trace("Updating reliable references for channel " + channelID + " between " + orderStart + " and " + orderEnd);
}
Connection conn = null;
PreparedStatement ps = null;
TransactionWrapper wrap = new TransactionWrapper();
-
+
final int MAX_TRIES = 25;
try
@@ -291,10 +292,12 @@
conn = ds.getConnection();
ps = conn.prepareStatement(getSQLStatement("UPDATE_RELIABLE_REFS_NOT_PAGED"));
+
+ log.info(getSQLStatement("UPDATE_RELIABLE_REFS_NOT_PAGED"));
ps.setLong(1, orderStart);
- ps.setLong(2, orderStart + number - 1);
+ ps.setLong(2, orderEnd);
ps.setLong(3, channelID);
@@ -305,11 +308,11 @@
try
{
int rows = ps.executeUpdate();
-
+
if (trace)
{
log.trace(JDBCUtil.statementToString(getSQLStatement("UPDATE_RELIABLE_REFS_NOT_PAGED"), new Long(channelID),
- new Long(orderStart), new Long(orderStart + number - 1))
+ new Long(orderStart), new Long(orderEnd))
+ " updated " + rows + " rows");
}
if (tries > 0)
@@ -318,7 +321,7 @@
}
//Sanity check
- if (rows != number)
+ if (rows != num)
{
throw new IllegalStateException("Did not update correct number of rows");
}
@@ -578,7 +581,7 @@
}
}
- public void addReferences(long channelID, List references) throws Exception
+ public void addReferences(long channelID, List references, boolean paged) throws Exception
{
Connection conn = null;
PreparedStatement psInsertReference = null;
@@ -623,7 +626,7 @@
}
//Now store the reference
- addReference(channelID, ref, psInsertReference, true);
+ addReference(channelID, ref, psInsertReference, paged);
if (usingBatchUpdates)
{
@@ -1145,6 +1148,9 @@
}
}
+ /*
+ * Load the initial, non paged refs
+ */
public InitialLoadInfo getInitialReferenceInfos(long channelID, int fullSize) throws Exception
{
if (trace)
@@ -1175,6 +1181,8 @@
Long minOrdering = new Long(rs.getLong(1));
+ log.info("min ordering is: " + minOrdering);
+
if (rs.wasNull())
{
minOrdering = null;
@@ -1187,9 +1195,8 @@
maxOrdering = null;
}
- //Must cope with the possibility that fullSize has changed for the channel since last
- //restart
-
+ log.info("Min ordering: " + minOrdering + " max Ordering: " + maxOrdering);
+
ps = conn.prepareStatement(getSQLStatement("LOAD_UNPAGED_REFS"));
ps.setLong(1, channelID);
@@ -1208,136 +1215,19 @@
if (count < fullSize)
{
refs.add(ri);
- }
- else
- {
- extraRefs.add(ri);
- }
+ }
count++;
}
- if (count != fullSize)
- {
- rs.close();
- rs = null;
- ps.close();
- ps = null;
+ //No refs paged
- if (count < fullSize)
- {
- if (minOrdering != null)
- {
- //This means that fullSize is now greater and we have some paged refs
- //We need to convert some of the paged refs into non paged refs before loading
-
- //We can do this by setting page_ord = null for the first x paged refs
-
- long numberPaged = 1 + maxOrdering.longValue() - minOrdering.longValue();
-
- long numberToConvert = Math.min(numberPaged, fullSize - count);
-
- ps = conn.prepareStatement(getSQLStatement("UPDATE_RELIABLE_REFS_NOT_PAGED"));
-
- ps.setLong(1, minOrdering.longValue());
- ps.setLong(2, minOrdering.longValue() + numberToConvert - 1);
- ps.setLong(3, channelID);
-
- ps.executeUpdate();
-
- minOrdering = new Long(minOrdering.longValue() + numberToConvert);
- if (minOrdering.longValue() == maxOrdering.longValue() + 1)
- {
- minOrdering = maxOrdering = null;
- }
-
- ps.close();
- ps = null;
-
- //Need to reload
-
- ps = conn.prepareStatement(getSQLStatement("LOAD_UNPAGED_REFS"));
-
- ps.setLong(1, channelID);
-
- rs = ps.executeQuery();
-
- refs.clear();
-
- while (rs.next())
- {
- long msgId = rs.getLong(1);
- int deliveryCount = rs.getInt(2);
- boolean reliable = rs.getString(3).equals("Y");
- ReferenceInfo ri = new ReferenceInfo(msgId, deliveryCount, reliable);
- refs.add(ri);
- }
- }
- else
- {
- //Not a problem nothing to do
- }
- }
- else if (count > fullSize)
- {
- //This means that fullSize is now smaller
- //We need to convert some of the non paged refs into paged refs before loading
-
- int numberToConvert = count - fullSize;
-
- //Shift any pre-existing paged refs up by this
-
- ps = conn.prepareStatement(getSQLStatement("SHIFT_PAGE_ORDER"));
-
- ps.setLong(1, numberToConvert);
-
- ps.setLong(2, channelID);
-
- ps.executeUpdate();
-
- //Now we need to convert the last <numberToConvert> non paged refs to paged refs
- ps.close();
- ps = null;
-
- ps = conn.prepareStatement(getSQLStatement("UPDATE_PAGE_ORDER"));
-
- long c;
- if (minOrdering == null)
- {
- c = 0;
- minOrdering = new Long(0);
- }
- else
- {
- c = minOrdering.longValue();
- }
-
- if (maxOrdering == null)
- {
- maxOrdering = new Long(numberToConvert - 1);
- }
- else
- {
- maxOrdering = new Long(maxOrdering.longValue() + numberToConvert);
- }
-
- Iterator iter = extraRefs.iterator();
- while (iter.hasNext())
- {
- ReferenceInfo ri = (ReferenceInfo)iter.next();
-
- ps.setLong(1, c);
- ps.setLong(2, ri.getMessageId());
- ps.setLong(3, channelID);
-
- //TODO use batch updates
- ps.executeUpdate();
-
- c++;
- }
- }
+ if (count > fullSize)
+ {
+ throw new IllegalStateException("Cannot load channel " + channelID + " since the fullSize parameter is too small to load " +
+ " all the required references, fullSize needs to be at least " + count + " it is currently " + fullSize);
}
-
+
return new InitialLoadInfo(minOrdering, maxOrdering, refs);
}
catch (Exception e)
@@ -1920,134 +1810,136 @@
* was a clean shutdown
*
*/
- protected void removeUnreliableMessageData() throws Exception
- {
- log.trace("Removing all non-persistent data");
-
- Connection conn = null;
- PreparedStatement psRes = null;
- PreparedStatement psUpdate = null;
- PreparedStatement psDeleteMsgs = null;
- PreparedStatement psDeleteRefs = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- ResultSet rs = null;
-
- try
- {
- conn = ds.getConnection();
-
- psRes = conn.prepareStatement(getSQLStatement("SELECT_ALL_CHANNELS"));
-
- psUpdate = conn.prepareStatement(getSQLStatement("UPDATE_UNRELIABLE_CHANNELCOUNT"));
-
- rs = psRes.executeQuery();
-
- while (rs.next())
- {
- long channelID = rs.getLong(1);
-
- psUpdate.setLong(1, channelID);
-
- int rows = psUpdate.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(getSQLStatement("UPDATE_UNRELIABLE_CHANNELCOUNT"))
- + " updated " + rows + " rows");
- }
- }
-
- psDeleteRefs = conn.prepareStatement(getSQLStatement("DELETE_UNRELIABLE_REFS"));
-
- int rows = psDeleteRefs.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(getSQLStatement("DELETE_UNRELIABLE_REFS"))
- + " deleted " + rows + " rows");
- }
-
- psDeleteMsgs = conn.prepareStatement(getSQLStatement("DELETE_UNREFFED_MESSAGES"));
-
- rows = psDeleteMsgs.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(getSQLStatement("DELETE_UNREFFED_MESSAGES"))
- + " deleted " + rows + " rows");
- }
- }
- catch (Exception e)
- {
- wrap.exceptionOccurred();
- throw e;
- }
- finally
- {
- if (rs != null)
- {
- try
- {
- rs.close();
- }
- catch (Throwable e)
- {
- }
- }
- if (psRes != null)
- {
- try
- {
- psRes.close();
- }
- catch (Throwable e)
- {
- }
- }
- if (psUpdate != null)
- {
- try
- {
- psUpdate.close();
- }
- catch (Throwable e)
- {
- }
- }
- if (psDeleteMsgs != null)
- {
- try
- {
- psDeleteMsgs.close();
- }
- catch (Throwable e)
- {
- }
- }
- if (psDeleteRefs != null)
- {
- try
- {
- psDeleteRefs.close();
- }
- catch (Throwable e)
- {
- }
- }
- if (conn != null)
- {
- try
- {
- conn.close();
- }
- catch (Throwable e)
- {
- }
- }
- wrap.end();
- }
- }
+// protected void removeUnreliableMessageData() throws Exception
+// {
+// log.trace("Removing all non-persistent data");
+//
+// Connection conn = null;
+// PreparedStatement psRes = null;
+// PreparedStatement psUpdate = null;
+// PreparedStatement psDeleteMsgs = null;
+// PreparedStatement psDeleteRefs = null;
+// TransactionWrapper wrap = new TransactionWrapper();
+//
+// ResultSet rs = null;
+//
+// try
+// {
+// conn = ds.getConnection();
+//
+// psRes = conn.prepareStatement(getSQLStatement("SELECT_ALL_CHANNELS"));
+//
+// psUpdate = conn.prepareStatement(getSQLStatement("UPDATE_UNRELIABLE_CHANNELCOUNT"));
+//
+// rs = psRes.executeQuery();
+//
+// while (rs.next())
+// {
+// long channelID = rs.getLong(1);
+//
+// psUpdate.setLong(1, channelID);
+//
+// int rows = psUpdate.executeUpdate();
+//
+// if (trace)
+// {
+// log.trace(JDBCUtil.statementToString(getSQLStatement("UPDATE_UNRELIABLE_CHANNELCOUNT"))
+// + " updated " + rows + " rows");
+// }
+// }
+//
+// psDeleteRefs = conn.prepareStatement(getSQLStatement("DELETE_UNRELIABLE_REFS"));
+//
+// int rows = psDeleteRefs.executeUpdate();
+//
+// boolean doReOrder = rows > 0;
+//
+// if (trace)
+// {
+// log.trace(JDBCUtil.statementToString(getSQLStatement("DELETE_UNRELIABLE_REFS"))
+// + " deleted " + rows + " rows");
+// }
+//
+// psDeleteMsgs = conn.prepareStatement(getSQLStatement("DELETE_UNREFFED_MESSAGES"));
+//
+// rows = psDeleteMsgs.executeUpdate();
+//
+// if (trace)
+// {
+// log.trace(JDBCUtil.statementToString(getSQLStatement("DELETE_UNREFFED_MESSAGES"))
+// + " deleted " + rows + " rows");
+// }
+// }
+// catch (Exception e)
+// {
+// wrap.exceptionOccurred();
+// throw e;
+// }
+// finally
+// {
+// if (rs != null)
+// {
+// try
+// {
+// rs.close();
+// }
+// catch (Throwable e)
+// {
+// }
+// }
+// if (psRes != null)
+// {
+// try
+// {
+// psRes.close();
+// }
+// catch (Throwable e)
+// {
+// }
+// }
+// if (psUpdate != null)
+// {
+// try
+// {
+// psUpdate.close();
+// }
+// catch (Throwable e)
+// {
+// }
+// }
+// if (psDeleteMsgs != null)
+// {
+// try
+// {
+// psDeleteMsgs.close();
+// }
+// catch (Throwable e)
+// {
+// }
+// }
+// if (psDeleteRefs != null)
+// {
+// try
+// {
+// psDeleteRefs.close();
+// }
+// catch (Throwable e)
+// {
+// }
+// }
+// if (conn != null)
+// {
+// try
+// {
+// conn.close();
+// }
+// catch (Throwable e)
+// {
+// }
+// }
+// wrap.end();
+// }
+// }
protected void handleBeforeCommit1PC(List refsToAdd, List refsToRemove, Transaction tx)
Modified: trunk/src/main/org/jboss/messaging/core/plugin/contract/PersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/contract/PersistenceManager.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/messaging/core/plugin/contract/PersistenceManager.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -47,13 +47,13 @@
// Paging functionality - TODO we should split this out into its own interface
- void addReferences(long channelID, List references) throws Exception;
+ void addReferences(long channelID, List references, boolean paged) throws Exception;
void removeReferences(long channelID, List refs) throws Exception;
void updatePageOrder(long channelID, List references) throws Exception;
- void updateReliableReferencesNotPagedInRange(long channelID, long orderStart, long orderEnd) throws Exception;
+ void updateReliableReferencesNotPagedInRange(long channelID, long orderStart, long orderEnd, long num) throws Exception;
List getPagedReferenceInfos(long channelID, long orderStart, long number) throws Exception;
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/DefaultClusteredPostOffice.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/DefaultClusteredPostOffice.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/DefaultClusteredPostOffice.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -392,8 +392,6 @@
ClusteredQueue queue = (ClusteredQueue)del.getObserver();
- log.info("sent " + ref.getMessageID() + " to " + queue.getName() + " on node " + queue.getNodeId() + " selector accepted " + del.isSelectorAccepted());
-
if (del.isSelectorAccepted() && !queue.isLocal())
{
//We need to send the message remotely
@@ -427,8 +425,6 @@
//when unicast would do
if (numberRemote > 0)
{
- log.info("Need to send remotely");
-
if (tx == null)
{
if (numberRemote == 1)
@@ -636,8 +632,6 @@
// We route on the condition
DefaultClusteredBindings cb = (DefaultClusteredBindings)conditionMap.get(routingKey);
- log.info("cb is: " + cb);
-
if (cb != null)
{
Collection bindings = cb.getAllBindings();
@@ -647,12 +641,9 @@
while (iter.hasNext())
{
Binding binding = (Binding)iter.next();
-
- log.info("got binding: " + binding.getQueue().getName());
-
+
if (binding.getNodeId().equals(this.nodeId))
{
- log.info("node id matches");
boolean handle = true;
if (queueNameNodeIdMap != null)
@@ -674,13 +665,7 @@
LocalClusteredQueue queue = (LocalClusteredQueue)binding.getQueue();
- log.info("sending " + message.getMessageID() + " to queue: " + queue.getName() + " on node " + this.nodeId);
-
- //TODO instead of adding a new method on the channel
- //we should set a header and use the same method
- Delivery del = queue.handleFromCluster(ref);
-
- log.info("sending " + message.getMessageID() + " to queue: " + queue.getName() + " on node " + this.nodeId + " delivery is " + del + " accepted? " + del.isSelectorAccepted());
+ Delivery del = queue.handleFromCluster(ref);
}
}
}
@@ -703,8 +688,6 @@
{
byte[] bytes = writeRequest(request);
- log.info("async sending " + bytes);
-
asyncChannel.send(new Message(null, null, bytes));
}
@@ -712,9 +695,7 @@
* Unicast a message to one members of the group
*/
public void asyncSendRequest(ClusterRequest request, Address address) throws Exception
- {
- log.info("unicasting to address: " + address);
-
+ {
byte[] bytes = writeRequest(request);
Message m = new Message(address, null, bytes);
@@ -858,8 +839,6 @@
try
{
- log.info("I have a list of stats: " + statsList.size() + " from nodeId: " + nodeId);
-
if (nodeId.equals(this.nodeId))
{
//Sanity check
@@ -875,8 +854,6 @@
}
else
{
- log.info("I do have bindings for " + nodeId);
-
Iterator iter = statsList.iterator();
while (iter.hasNext())
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/LocalClusteredQueue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/LocalClusteredQueue.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/LocalClusteredQueue.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -131,9 +131,8 @@
{
synchronized (deliveryLock)
{
- //We only get the refs if receiversReady = true since
- //we don't
- //TODO is this right?
+ //We only get the refs if receiversReady = false so as not to steal messages that
+ //might be consumed by local receivers
if (!receiversReady)
{
MessageReference ref;
Modified: trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -155,15 +155,11 @@
boolean done = ACKING.equals(state) ? true : false;
log.trace(this + " is " + (done ? "ACKing" : "NACKing") + " message " + ref);
- log.info(this + " got message " + ref.getMessageID());
-
Message m = ref.getMessage();
SimpleDelivery delivery = new SimpleDelivery(observer, ref, done);
messages.add(new Object[] {m, done ? null : delivery});
- log.info("Added it to messages");
-
if (immediateAsynchronousAcknowledgment)
{
log.trace("simulating an asynchronous ACK that arrives before we return the delivery to channel");
Modified: trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_2PCTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_2PCTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_2PCTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -66,7 +66,7 @@
{
PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 1, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 2, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
Message[] msgs = new Message[150];
Modified: trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_NTTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_NTTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_NTTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -65,7 +65,7 @@
{
PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 1, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 2, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
Message[] msgs = new Message[150];
@@ -146,7 +146,7 @@
//Queue1
refIds = getReferenceIdsOrderedByPageOrd(queue1.getChannelID());
- assertEquals(0, refIds.size());
+ assertEquals(0, refIds.size());
assertEquals(75, queue1.memoryRefCount());
Modified: trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_TTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_TTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_NP_TTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -66,7 +66,7 @@
{
PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 1, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 2, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
Message[] msgs = new Message[150];
Modified: trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_2PCTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_2PCTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_2PCTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -61,7 +61,7 @@
{
PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 1, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 2, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
Message[] msgs = new Message[150];
Modified: trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_NTTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_NTTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_NTTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -65,7 +65,7 @@
{
PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 1, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 2, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
Message[] msgs = new Message[150];
Modified: trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_TTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_TTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/paging/ChannelShare_P_TTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -65,7 +65,7 @@
{
PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 1, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", 2, ms, pm, true, true, new QueuedExecutor(), null, 50, 10, 5);
Message[] msgs = new Message[150];
Modified: trunk/tests/src/org/jboss/test/messaging/core/paging/PagingStateTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/paging/PagingStateTestBase.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/paging/PagingStateTestBase.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -462,6 +462,8 @@
List msgIds = new ArrayList();
+ //log.info("channel id:" + channelId);
+
String sql = "SELECT MESSAGEID, ORD, PAGE_ORD FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID=? ORDER BY PAGE_ORD";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setLong(1, channelId);
@@ -470,7 +472,11 @@
while (rs.next())
{
- long msgId = rs.getLong(1);
+ long msgId = rs.getLong(1);
+ long pageOrd = rs.getLong(3);
+
+ //log.info("Exists " + msgId + " with page ord " + pageOrd);
+
msgIds.add(new Long(msgId));
}
rs.close();
Modified: trunk/tests/src/org/jboss/test/messaging/core/paging/SingleChannel_ReloadTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/paging/SingleChannel_ReloadTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/paging/SingleChannel_ReloadTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -108,8 +108,7 @@
assertEquals(0, queue.memoryDeliveryCount());
//Stop and restart the persistence manager
- //Only the persistent messages should survive
- //This is what would happen if the server crashed
+ //All the paged refs will survive
pm.stop();
tr.stop();
@@ -125,13 +124,23 @@
ms = new SimpleMessageStore();
ms.start();
-
+
+ queue = null;
+
PagingFilteredQueue queue2 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
-
- refIds = getReferenceIdsOrderedByPageOrd(queue.getChannelID());
+ queue2.deactivate();
+ queue2.load();
+
+ refIds = getReferenceIdsOrderedByPageOrd(queue2.getChannelID());
assertEquals(50, refIds.size());
+
+ assertEquals(100, queue2.memoryRefCount());
+ assertEquals(0, queue2.downCacheCount());
+ assertFalse(queue2.isPaging());
+
+ assertEquals(0, queue2.memoryDeliveryCount());
- this.consume(queue2, 150, refs, 50);
+ this.consume(queue2, 100, refs, 100);
refIds = getReferenceIdsOrderedByPageOrd(queue2.getChannelID());
assertEquals(0, refIds.size());
@@ -195,7 +204,7 @@
assertEquals(0, queue.memoryDeliveryCount());
//Stop and restart the persistence manager
- //No messages should survive
+ //Only the paged messages will survive
//This is what would happen if the server crashed
pm.stop();
@@ -214,19 +223,23 @@
ms.start();
PagingFilteredQueue queue2 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
+ queue2.deactivate();
+ queue2.load();
refIds = getReferenceIdsOrderedByPageOrd(queue.getChannelID());
- assertEquals(0, refIds.size());
+ assertEquals(50, refIds.size());
List msgIds = getMessageIds();
- assertEquals(0, msgIds.size());
+ assertEquals(50, msgIds.size());
- assertEquals(0, queue2.memoryRefCount());
+ assertEquals(100, queue2.memoryRefCount());
assertEquals(0, queue2.downCacheCount());
assertFalse(queue2.isPaging());
+ this.consume(queue2, 100, refs, 100);
+
assertEquals(0, queue2.memoryDeliveryCount());
assertEquals(0, queue2.messageCount());
@@ -300,196 +313,5 @@
assertEquals(0, LockMap.instance.getSize());
}
- public void testQueueReloadWithSmallerFullSize() throws Throwable
- {
- PagingFilteredQueue queue = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
-
- Message[] msgs = new Message[150];
-
- MessageReference[] refs = new MessageReference[150];
-
- //Send 150 p messages
- for (int i = 0; i < 150; i++)
- {
- msgs[i] = CoreMessageFactory.createCoreMessage(i, true, null);
-
- refs[i] = ms.reference(msgs[i]);
-
- queue.handle(null, refs[i], null);
-
- refs[i].releaseMemoryReference();
- }
- List refIds = getReferenceIdsOrderedByPageOrd(queue.getChannelID());
- assertEquals(150, refIds.size());
-
- assertEquals(100, queue.memoryRefCount());
-
- assertEquals(0, queue.downCacheCount());
-
- assertTrue(queue.isPaging());
-
- assertEquals(0, queue.memoryDeliveryCount());
-
- //Also we cancel some so we make sure that we have some negative page orders
-
- //cancel 10
-
- this.cancelDeliveries(queue, 10);
-
- //Stop and restart the persistence manager
-
- pm.stop();
- tr.stop();
- ms.stop();
-
- pm =
- new JDBCPersistenceManager(sc.getDataSource(), sc.getTransactionManager(), null,
- true, true, true, 100);
- pm.start();
-
- tr = new TransactionRepository(pm, new IdManager("TRANSACTION_ID", 10, pm));
- tr.start();
-
- ms = new SimpleMessageStore();
- ms.start();
-
- //Reload the queue with a smaller fullSize
-
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 50, 20, 10);
-
- refIds = getReferenceIdsOrderedByPageOrd(queue.getChannelID());
- assertEquals(150, refIds.size());
-
- List msgIds = getMessageIds();
- assertEquals(150, msgIds.size());
-
- assertEquals(50, queue2.memoryRefCount());
-
- assertEquals(0, queue2.downCacheCount());
-
- assertTrue(queue2.isPaging());
-
- assertEquals(0, queue2.memoryDeliveryCount());
-
- assertEquals(50, queue2.messageCount());
-
- //Consume all the messages
- this.consume(queue2, 0, refs, 150);
-
- refIds = getReferenceIdsOrderedByPageOrd(queue.getChannelID());
- assertEquals(0, refIds.size());
-
- msgIds = getMessageIds();
- assertEquals(0, msgIds.size());
-
- assertEquals(0, queue2.memoryRefCount());
-
- assertEquals(0, queue2.downCacheCount());
-
- assertFalse(queue2.isPaging());
-
- assertEquals(0, queue2.memoryDeliveryCount());
-
- assertEquals(0, queue2.messageCount());
-
- assertEquals(0, LockMap.instance.getSize());
- }
-
- public void testReloadWithLargerFullSize() throws Throwable
- {
- PagingFilteredQueue queue = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 100, 20, 10);
-
- Message[] msgs = new Message[150];
-
- MessageReference[] refs = new MessageReference[150];
-
- //Send 150 p messages
- for (int i = 0; i < 150; i++)
- {
- msgs[i] = CoreMessageFactory.createCoreMessage(i, true, null);
-
- refs[i] = ms.reference(msgs[i]);
-
- queue.handle(null, refs[i], null);
-
- refs[i].releaseMemoryReference();
- }
-
- List refIds = getReferenceIdsOrderedByPageOrd(queue.getChannelID());
- assertEquals(150, refIds.size());
-
- assertEquals(100, queue.memoryRefCount());
-
- assertEquals(0, queue.downCacheCount());
-
- assertTrue(queue.isPaging());
-
- assertEquals(0, queue.memoryDeliveryCount());
-
- //Also we cancel some so we make sure that we have some negative page orders
-
- //cancel 10
-
- this.cancelDeliveries(queue, 10);
-
- //Stop and restart the persistence manager
-
- pm.stop();
- tr.stop();
- ms.stop();
-
- pm =
- new JDBCPersistenceManager(sc.getDataSource(), sc.getTransactionManager(), null,
- true, true, true, 100);
- pm.start();
-
- tr = new TransactionRepository(pm, new IdManager("TRANSACTION_ID", 10, pm));
- tr.start();
-
- ms = new SimpleMessageStore();
- ms.start();
-
- //Reload the queue with a smaller fullSize
-
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue1", 1, ms, pm, true, true, new QueuedExecutor(), null, 130, 20, 10);
-
- refIds = getReferenceIdsOrderedByPageOrd(queue.getChannelID());
- assertEquals(150, refIds.size());
-
- List msgIds = getMessageIds();
- assertEquals(150, msgIds.size());
-
- assertEquals(130, queue2.memoryRefCount());
-
- assertEquals(0, queue2.downCacheCount());
-
- assertTrue(queue2.isPaging());
-
- assertEquals(0, queue2.memoryDeliveryCount());
-
- assertEquals(130, queue2.messageCount());
-
- //Consume all the messages
- this.consume(queue2, 0, refs, 150);
-
- refIds = getReferenceIdsOrderedByPageOrd(queue.getChannelID());
- assertEquals(0, refIds.size());
-
- msgIds = getMessageIds();
- assertEquals(0, msgIds.size());
-
- assertEquals(0, queue2.memoryRefCount());
-
- assertEquals(0, queue2.downCacheCount());
-
- assertFalse(queue2.isPaging());
-
- assertEquals(0, queue2.memoryDeliveryCount());
-
- assertEquals(0, queue2.messageCount());
-
- assertEquals(0, LockMap.instance.getSize());
- }
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/core/plugin/JDBCPersistenceManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/JDBCPersistenceManagerTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/JDBCPersistenceManagerTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -335,7 +335,7 @@
refs.add(ref9);
refs.add(ref10);
- pm.addReferences(channel1.getChannelID(), refs);
+ pm.addReferences(channel1.getChannelID(), refs, false);
refs = new ArrayList();
refs.add(ref11);
@@ -344,7 +344,7 @@
refs.add(ref14);
refs.add(ref15);
- pm.addReferences(channel2.getChannelID(), refs);
+ pm.addReferences(channel2.getChannelID(), refs, false);
List refIds = getReferenceIds(channel1.getChannelID());
assertNotNull(refIds);
@@ -512,7 +512,7 @@
refs.add(ref9);
refs.add(ref10);
- pm.addReferences(channel.getChannelID(), refs);
+ pm.addReferences(channel.getChannelID(), refs, false);
ref1.setPagingOrder(0);
ref2.setPagingOrder(1);
@@ -556,7 +556,7 @@
assertEquals(ref7.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
assertEquals(ref8.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
- pm.updateReliableReferencesNotPagedInRange(channel.getChannelID(), 0, 4);
+ pm.updateReliableReferencesNotPagedInRange(channel.getChannelID(), 0, 3, 4);
refInfos = pm.getPagedReferenceInfos(channel.getChannelID(), 5, 5);
@@ -680,11 +680,14 @@
refs.add(ref9);
refs.add(ref10);
- pm.addReferences(channel.getChannelID(), refs);
+ pm.addReferences(channel.getChannelID(), refs, false);
//First load exactly 10
PersistenceManager.InitialLoadInfo info = pm.getInitialReferenceInfos(channel.getChannelID(), 10);
+ log.info("min:" + info.getMinPageOrdering());
+ log.info("max:" + info.getMaxPageOrdering());
+
assertNull(info.getMinPageOrdering());
assertNull(info.getMaxPageOrdering());
@@ -702,127 +705,7 @@
assertEquals(ref7.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(6)).getMessageId());
assertEquals(ref8.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(7)).getMessageId());
assertEquals(ref9.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(8)).getMessageId());
- assertEquals(ref10.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(9)).getMessageId());
-
- //fullSize has increased to 15 - only 10 should be loadeed still
- info = pm.getInitialReferenceInfos(channel.getChannelID(), 15);
-
- assertNull(info.getMinPageOrdering());
- assertNull(info.getMaxPageOrdering());
-
- refInfos = info.getRefInfos();
- assertNotNull(refInfos);
- assertEquals(10, refInfos.size());
-
- assertEquals(ref1.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref2.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref3.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref4.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
- assertEquals(ref5.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
- assertEquals(ref6.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(5)).getMessageId());
- assertEquals(ref7.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(6)).getMessageId());
- assertEquals(ref8.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(7)).getMessageId());
- assertEquals(ref9.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(8)).getMessageId());
- assertEquals(ref10.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(9)).getMessageId());
-
- //fullSize has gone down to 7 - 7 should be loaded and the other 3 marked as paged
- info = pm.getInitialReferenceInfos(channel.getChannelID(), 7);
-
- assertEquals(0, info.getMinPageOrdering().longValue());
- assertEquals(2, info.getMaxPageOrdering().longValue());
-
- refInfos = info.getRefInfos();
- assertNotNull(refInfos);
- assertEquals(7, refInfos.size());
-
- assertEquals(ref1.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref2.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref3.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref4.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
- assertEquals(ref5.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
- assertEquals(ref6.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(5)).getMessageId());
- assertEquals(ref7.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(6)).getMessageId());
-
- List pagedInfos = pm.getPagedReferenceInfos(channel.getChannelID(), 0, 3);
- assertNotNull(pagedInfos);
- assertEquals(3, pagedInfos.size());
- assertEquals(ref8.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(0)).getMessageId());
- assertEquals(ref9.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(1)).getMessageId());
- assertEquals(ref10.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(2)).getMessageId());
-
- //fullSize gone down even further to 4 - 4 should be loaded and othe others re-ordered from zero
-
- info = pm.getInitialReferenceInfos(channel.getChannelID(), 4);
-
- assertEquals(0, info.getMinPageOrdering().longValue());
- assertEquals(5, info.getMaxPageOrdering().longValue());
-
- refInfos = info.getRefInfos();
- assertNotNull(refInfos);
- assertEquals(4, refInfos.size());
-
- assertEquals(ref1.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref2.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref3.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref4.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
-
- pagedInfos = pm.getPagedReferenceInfos(channel.getChannelID(), 0, 6);
- assertNotNull(pagedInfos);
- assertEquals(6, pagedInfos.size());
- assertEquals(ref5.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(0)).getMessageId());
- assertEquals(ref6.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(1)).getMessageId());
- assertEquals(ref7.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(2)).getMessageId());
- assertEquals(ref8.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(3)).getMessageId());
- assertEquals(ref9.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(4)).getMessageId());
- assertEquals(ref10.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(5)).getMessageId());
-
- //fullSize back up to 6 - 6 should be loaded and the others shifted
-
- info = pm.getInitialReferenceInfos(channel.getChannelID(), 6);
-
- assertEquals(2, info.getMinPageOrdering().longValue());
- assertEquals(5, info.getMaxPageOrdering().longValue());
-
- refInfos = info.getRefInfos();
- assertNotNull(refInfos);
- assertEquals(6, refInfos.size());
-
- assertEquals(ref1.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref2.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref3.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref4.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
- assertEquals(ref5.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
- assertEquals(ref6.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(5)).getMessageId());
-
- pagedInfos = pm.getPagedReferenceInfos(channel.getChannelID(), 2, 4);
- assertNotNull(pagedInfos);
- assertEquals(4, pagedInfos.size());
- assertEquals(ref7.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(0)).getMessageId());
- assertEquals(ref8.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(1)).getMessageId());
- assertEquals(ref9.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(2)).getMessageId());
- assertEquals(ref10.getMessageID(), ((PersistenceManager.ReferenceInfo)pagedInfos.get(3)).getMessageId());
-
- //fullSize up to 12
-
- info = pm.getInitialReferenceInfos(channel.getChannelID(), 12);
-
- assertNull(info.getMinPageOrdering());
- assertNull(info.getMaxPageOrdering());
-
- refInfos = info.getRefInfos();
- assertNotNull(refInfos);
- assertEquals(10, refInfos.size());
-
- assertEquals(ref1.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref2.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref3.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref4.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
- assertEquals(ref5.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
- assertEquals(ref6.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(5)).getMessageId());
- assertEquals(ref7.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(6)).getMessageId());
- assertEquals(ref8.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(7)).getMessageId());
- assertEquals(ref9.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(8)).getMessageId());
- assertEquals(ref10.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(9)).getMessageId());
+ assertEquals(ref10.getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(9)).getMessageId());
}
Deleted: trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -1,1475 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, 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.test.messaging.core.plugin.postoffice.cluster;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.messaging.core.FilterFactory;
-import org.jboss.messaging.core.Message;
-import org.jboss.messaging.core.MessageReference;
-import org.jboss.messaging.core.local.PagingFilteredQueue;
-import org.jboss.messaging.core.plugin.contract.ClusteredPostOffice;
-import org.jboss.messaging.core.plugin.postoffice.Binding;
-import org.jboss.messaging.core.plugin.postoffice.cluster.ClusterRouterFactory;
-import org.jboss.messaging.core.plugin.postoffice.cluster.DefaultClusteredPostOffice;
-import org.jboss.messaging.core.plugin.postoffice.cluster.FavourLocalRouterFactory;
-import org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue;
-import org.jboss.messaging.core.plugin.postoffice.cluster.MessagePullPolicy;
-import org.jboss.messaging.core.plugin.postoffice.cluster.NullMessagePullPolicy;
-import org.jboss.messaging.core.tx.Transaction;
-import org.jboss.test.messaging.core.SimpleFilter;
-import org.jboss.test.messaging.core.SimpleFilterFactory;
-import org.jboss.test.messaging.core.SimpleReceiver;
-import org.jboss.test.messaging.core.plugin.postoffice.DefaultPostOfficeTest;
-import org.jboss.test.messaging.util.CoreMessageFactory;
-
-import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
-
-/**
- *
- * A ClusteredPostOfficeTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class ClusteredPostOfficeTest extends DefaultPostOfficeTest
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ClusteredPostOfficeTest(String name)
- {
- super(name);
- }
-
- // Public --------------------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public final void testClusteredBindUnbind() throws Throwable
- {
- ClusteredPostOffice office1 = null;
-
- ClusteredPostOffice office2 = null;
-
- ClusteredPostOffice office3 = null;
-
- try
- {
- //Start one office
-
- office1 = createClusteredPostOffice("node1", "testgroup");
-
- //Add a couple of bindings
-
- LocalClusteredQueue queue1 = new LocalClusteredQueue(office1, "node1", "sub1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding1 =
- office1.bindClusteredQueue("topic1", queue1);
- LocalClusteredQueue queue2 = new LocalClusteredQueue(office1, "node1", "sub2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding2 =
- office1.bindClusteredQueue("topic1", queue2);
-
- //Start another office - make sure it picks up the bindings from the first node
-
- office2 = createClusteredPostOffice("node2", "testgroup");
-
- Collection bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(2, bindings.size());
-
- Iterator iter = bindings.iterator();
- assertEquivalent(binding1, (Binding)iter.next());
- assertEquivalent(binding2, (Binding)iter.next());
-
- //Add another binding on node 2
-
- LocalClusteredQueue queue3 = new LocalClusteredQueue(office2, "node2", "sub3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding3 =
- office2.bindClusteredQueue("topic1", queue3);
-
- //Make sure both nodes pick it up
-
- bindings = office1.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(3, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding1, (Binding)iter.next());
- assertEquivalent(binding2, (Binding)iter.next());
- assertEquivalent(binding3, (Binding)iter.next());
-
- bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(3, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding1, (Binding)iter.next());
- assertEquivalent(binding2, (Binding)iter.next());
- assertEquivalent(binding3, (Binding)iter.next());
-
- //Add another binding on node 1
-
- LocalClusteredQueue queue4 = new LocalClusteredQueue(office2, "node2", "sub4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- Binding binding4 =
- office2.bindClusteredQueue("topic1", queue4);
-
- // Make sure both nodes pick it up
-
- bindings = office1.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(4, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding1, (Binding)iter.next());
- assertEquivalent(binding2, (Binding)iter.next());
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
-
- bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(4, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding1, (Binding)iter.next());
- assertEquivalent(binding2, (Binding)iter.next());
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
-
- //Unbind binding 1 and binding 2
- office1.unbindClusteredQueue("sub1");
- office1.unbindClusteredQueue("sub2");
-
- //Make sure bindings are not longer available on either node
-
- bindings = office1.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(2, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
-
- bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(2, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
-
- //Add a third office
-
- office3 = createClusteredPostOffice("node3", "testgroup");
-
- //Maks sure it picks up the bindings
-
- bindings = office3.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(2, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
-
- //Add another binding on node 3
-
- LocalClusteredQueue queue5 = new LocalClusteredQueue(office3, "node3", "sub5", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding5 =
- office3.bindClusteredQueue("topic1", queue5);
-
- // Make sure all nodes pick it up
-
- bindings = office1.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(3, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
- assertEquivalent(binding5, (Binding)iter.next());
-
- bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(3, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
- assertEquivalent(binding5, (Binding)iter.next());
-
- bindings = office3.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(3, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
- assertEquivalent(binding5, (Binding)iter.next());
-
- //Add a durable and a non durable binding on node 1
-
- LocalClusteredQueue queue6 = new LocalClusteredQueue(office1, "node1", "sub6", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
-
- Binding binding6 =
- office1.bindClusteredQueue("topic1", queue6);
-
- LocalClusteredQueue queue7 = new LocalClusteredQueue(office1, "node1", "sub7", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding7 =
- office1.bindClusteredQueue("topic1", queue7);
-
- // Make sure all nodes pick them up
-
- bindings = office1.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(5, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
- assertEquivalent(binding7, (Binding)iter.next());
-
- bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(5, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
- assertEquivalent(binding7, (Binding)iter.next());
-
- bindings = office3.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(5, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
- assertEquivalent(binding7, (Binding)iter.next());
-
- //Stop office 1
- office1.stop();
-
- //Need to sleep since it may take some time for the view changed request to reach the
- //members which causes the bindings to be removed
-
- Thread.sleep(1000);
-
- //All it's non durable bindings should be removed from the other nodes
- //Durable bindings should remain
-
- bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(4, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
-
- bindings = office3.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(4, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding3, (Binding)iter.next());
- assertEquivalent(binding4, (Binding)iter.next());
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
-
- //Stop office 2
- office2.stop();
-
- bindings = office3.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(2, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
-
- //Restart office 1 and office 2
- office1 = createClusteredPostOffice("node1", "testgroup");
-
- office2 = createClusteredPostOffice("node2", "testgroup");
-
- bindings = office1.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(2, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
-
- bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(2, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
-
- bindings = office3.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(2, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding5, (Binding)iter.next());
- assertEquivalent(binding6, (Binding)iter.next());
-
- //Stop all offices
-
- office1.stop();
- office2.stop();
- office3.stop();
-
- //Start them all
- office1 = createClusteredPostOffice("node1", "testgroup");
- office2 = createClusteredPostOffice("node2", "testgroup");
- office3 = createClusteredPostOffice("node3", "testgroup");
-
- //Only the durable queue should survive
-
- bindings = office1.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(1, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding6, (Binding)iter.next());
-
- bindings = office2.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(1, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding6, (Binding)iter.next());
-
- bindings = office3.listBindingsForCondition("topic1");
- assertNotNull(bindings);
- assertEquals(1, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent(binding6, (Binding)iter.next());
-
- }
- finally
- {
- if (office1 != null)
- {
- try
- {
- office1.unbindClusteredQueue("sub6");
- }
- catch (Exception ignore)
- {
-
- }
- office1.stop();
- }
-
- if (office2 != null)
- {
- office2.stop();
- }
-
- if (office3 != null)
- {
- office2.stop();
- }
- }
-
- }
-
- public final void testClusteredRoutePersistent() throws Throwable
- {
- clusteredRoute(true);
- }
-
- public final void testClusteredRouteNonPersistent() throws Throwable
- {
- clusteredRoute(false);
- }
-
- public final void testClusteredTransactionalRoutePersistent() throws Throwable
- {
- clusteredTransactionalRoute(true);
- }
-
- public final void testClusteredTransactionalRouteNonPersistent() throws Throwable
- {
- clusteredTransactionalRoute(false);
- }
-
- public void testClusteredNonPersistentRouteWithFilter() throws Throwable
- {
- this.clusteredRouteWithFilter(false);
- }
-
- public void testClusteredPersistentRouteWithFilter() throws Throwable
- {
- this.clusteredRouteWithFilter(true);
- }
-
-
- /*
- * We should allow the clustered bind of queues with the same queue name on different nodes of the
- * cluster
- */
- public void testClusteredNameUniqueness() throws Throwable
- {
- ClusteredPostOffice office1 = null;
-
- ClusteredPostOffice office2 = null;
-
- try
- {
- office1 = createClusteredPostOffice("node1", "testgroup");
-
- office2 = createClusteredPostOffice("node2", "testgroup");
-
- LocalClusteredQueue queue1 = new LocalClusteredQueue(office1, "node1", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding1 = office1.bindClusteredQueue("queue1", queue1);
-
- LocalClusteredQueue queue2 = new LocalClusteredQueue(office2, "node2", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding2 = office2.bindClusteredQueue("queue1", queue2);
-
- LocalClusteredQueue queue3 = new LocalClusteredQueue(office1, "node1", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- try
- {
- Binding binding3 = office1.bindClusteredQueue("queue1", queue3);
- fail();
- }
- catch (Exception e)
- {
- //Ok
- }
- LocalClusteredQueue queue4 = new LocalClusteredQueue(office2, "node2", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- try
- {
- Binding binding4 = office2.bindClusteredQueue("queue1", queue4);
- fail();
- }
- catch (Exception e)
- {
- //Ok
- }
-
- office1.unbindClusteredQueue("queue1");
-
- office2.unbindClusteredQueue("queue1");
-
- LocalClusteredQueue queue5 = new LocalClusteredQueue(office1, "node1", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding5 = office1.bindClusteredQueue("queue1", queue5);
-
- PagingFilteredQueue queue6 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- try
- {
- Binding binding6 = office1.bindQueue("queue1", queue6);
- fail();
- }
- catch (Exception e)
- {
- //ok
- }
-
- try
- {
- office1.unbindQueue("queue1");
- fail();
- }
- catch (Exception e)
- {
- //ok
- }
-
- office1.unbindClusteredQueue("queue1");
-
- PagingFilteredQueue queue7 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- Binding binding7 = office1.bindQueue("queue1", queue7);
-
- PagingFilteredQueue queue8 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- Binding binding8 = office2.bindQueue("queue1", queue8);
-
- PagingFilteredQueue queue9 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- try
- {
- Binding binding9 = office1.bindQueue("queue1", queue9);
- fail();
- }
- catch (Exception e)
- {
- //Ok
- }
-
- }
- finally
- {
- if (office1 != null)
- {
- office1.stop();
- }
-
- if (office2 != null)
- {
- office2.stop();
- }
- }
- }
-
-
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected void clusteredRouteWithFilter(boolean persistentMessage) throws Throwable
- {
- ClusteredPostOffice office1 = null;
-
- ClusteredPostOffice office2 = null;
-
- try
- {
- office1 = createClusteredPostOffice("node1", "testgroup");
- office2 = createClusteredPostOffice("node2", "testgroup");
-
- SimpleFilter filter1 = new SimpleFilter(2);
- SimpleFilter filter2 = new SimpleFilter(3);
-
- LocalClusteredQueue queue1 = new LocalClusteredQueue(office1, "node1", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), filter1);
- Binding binding1 =
- office1.bindClusteredQueue("topic1", queue1);
-
- LocalClusteredQueue queue2 = new LocalClusteredQueue(office2, "node2", "queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), filter2);
- Binding binding2 =
- office2.bindClusteredQueue("topic1", queue2);
-
- LocalClusteredQueue queue3 = new LocalClusteredQueue(office2, "node2", "queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- Binding binding3 =
- office2.bindClusteredQueue("topic1", queue3);
-
- SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue1.add(receiver1);
- SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue2.add(receiver2);
- SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue3.add(receiver3);
-
- Message msg1 = CoreMessageFactory.createCoreMessage(1);
- MessageReference ref1 = ms.reference(msg1);
- boolean routed = office1.route(ref1, "topic1", null);
- assertTrue(routed);
- Message msg2 = CoreMessageFactory.createCoreMessage(2);
- MessageReference ref2 = ms.reference(msg2);
- routed = office1.route(ref2, "topic1", null);
- assertTrue(routed);
- Message msg3 = CoreMessageFactory.createCoreMessage(3);
- MessageReference ref3 = ms.reference(msg3);
- routed = office1.route(ref3, "topic1", null);
- assertTrue(routed);
-
- Thread.sleep(1000);
-
- List msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- Message msgRec = (Message)msgs.get(0);
- assertTrue(msg2 == msgRec);
- receiver1.acknowledge(msgRec, null);
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- msgRec = (Message)msgs.get(0);
- assertTrue(msg3 == msgRec);
- receiver2.acknowledge(msgRec, null);
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver3.getMessages();
- assertNotNull(msgs);
- assertEquals(3, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertTrue(msg1 == msgRec1);
- Message msgRec2 = (Message)msgs.get(1);
- assertTrue(msg2 == msgRec2);
- Message msgRec3 = (Message)msgs.get(2);
- assertTrue(msg3 == msgRec3);
-
- receiver3.acknowledge(msgRec1, null);
- receiver3.acknowledge(msgRec2, null);
- receiver3.acknowledge(msgRec3, null);
- msgs = queue3.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- }
- finally
- {
- if (office1 != null)
- {
- office1.stop();
- }
-
- if (office2 != null)
- {
- office2.stop();
- }
- }
- }
-
- protected void clusteredRoute(boolean persistentMessage) throws Throwable
- {
- ClusteredPostOffice office1 = null;
-
- ClusteredPostOffice office2 = null;
-
- try
- {
- office1 = createClusteredPostOffice("node1", "testgroup");
- office2 = createClusteredPostOffice("node2", "testgroup");
-
- //Two topics with a mixture of durable and non durable subscriptions
-
- LocalClusteredQueue[] queues = new LocalClusteredQueue[16];
- Binding[] bindings = new Binding[16];
-
- queues[0] = new LocalClusteredQueue(office1, "node1", "sub1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[0] = office1.bindClusteredQueue("topic1", queues[0]);
-
- queues[1] = new LocalClusteredQueue(office1, "node1", "sub2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[1] = office1.bindClusteredQueue("topic1", queues[1]);
-
- queues[2] = new LocalClusteredQueue(office2, "node2", "sub3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[2] = office2.bindClusteredQueue("topic1", queues[2]);
-
- queues[3] = new LocalClusteredQueue(office2, "node2", "sub4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[3] = office2.bindClusteredQueue("topic1", queues[3]);
-
- queues[4] = new LocalClusteredQueue(office2, "node2", "sub5", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[4] = office2.bindClusteredQueue("topic1", queues[4]);
-
- queues[5] = new LocalClusteredQueue(office1, "node1", "sub6", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[5] = office1.bindClusteredQueue("topic1", queues[5]);
-
- queues[6] = new LocalClusteredQueue(office1, "node1", "sub7", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[6] = office1.bindClusteredQueue("topic1", queues[6]);
-
- queues[7] = new LocalClusteredQueue(office1, "node1", "sub8", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[7] = office1.bindClusteredQueue("topic1", queues[7]);
-
- queues[8] = new LocalClusteredQueue(office1, "node1", "sub9", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[8] = office1.bindClusteredQueue("topic2", queues[8]);
-
- queues[9] = new LocalClusteredQueue(office1, "node1", "sub10", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[9] = office1.bindClusteredQueue("topic2", queues[9]);
-
- queues[10] = new LocalClusteredQueue(office2, "node2", "sub11", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[10] = office2.bindClusteredQueue("topic2", queues[10]);
-
- queues[11] = new LocalClusteredQueue(office2, "node2", "sub12", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[11] = office2.bindClusteredQueue("topic2", queues[11]);
-
- queues[12] = new LocalClusteredQueue(office2, "node2", "sub13", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[12] = office2.bindClusteredQueue("topic2", queues[12]);
-
- queues[13] = new LocalClusteredQueue(office1, "node1", "sub14", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[13] = office1.bindClusteredQueue("topic2", queues[13]);
-
- queues[14] = new LocalClusteredQueue(office1, "node1", "sub15", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[14] = office1.bindClusteredQueue("topic2", queues[14]);
-
- queues[15] = new LocalClusteredQueue(office1, "node1", "sub16", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[15] = office1.bindClusteredQueue("topic2", queues[15]);
-
- SimpleReceiver[] receivers = new SimpleReceiver[16];
-
- for (int i = 0; i < 16; i++)
- {
- receivers[i] = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queues[i].add(receivers[i]);
- }
-
- Message msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
- MessageReference ref = ms.reference(msg);
-
- boolean routed = office1.route(ref, "topic1", null);
- assertTrue(routed);
-
- //Messages are sent asych so may take some finite time to arrive
- Thread.sleep(1000);
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- Message msgRec = (Message)msgs.get(0);
- assertEquals(msg.getMessageID(), msgRec.getMessageID());
- receivers[i].acknowledge(msgRec, null);
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- receivers[i].clear();
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- //Now route to topic2
-
- msg = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);;
- ref = ms.reference(msg);
-
- routed = office1.route(ref, "topic2", null);
- assertTrue(routed);
- //Messages are sent asych so may take some finite time to arrive
- Thread.sleep(1000);
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- Message msgRec = (Message)msgs.get(0);
- assertEquals(msg.getMessageID(), msgRec.getMessageID());
- receivers[i].acknowledge(msgRec, null);
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- receivers[i].clear();
- }
-
- }
- finally
- {
- if (office1 != null)
- {
- try
- {
- office2.unbindClusteredQueue("sub5");
- office1.unbindClusteredQueue("sub7");
- office1.unbindClusteredQueue("sub8");
- office2.unbindClusteredQueue("sub13");
- office1.unbindClusteredQueue("sub15");
- office1.unbindClusteredQueue("sub16");
- }
- catch (Exception ignore)
- {
-
- }
-
- office1.stop();
- }
-
- if (office2 != null)
- {
- office2.stop();
- }
- }
- }
-
-
- protected void clusteredTransactionalRoute(boolean persistent) throws Throwable
- {
- ClusteredPostOffice office1 = null;
-
- ClusteredPostOffice office2 = null;
-
- try
- {
- //Start two offices
-
- office1 = createClusteredPostOffice("node1", "testgroup");
- office2 = createClusteredPostOffice("node2", "testgroup");
-
- LocalClusteredQueue[] queues = new LocalClusteredQueue[16];
- Binding[] bindings = new Binding[16];
-
- queues[0] = new LocalClusteredQueue(office1, "node1", "sub1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[0] = office1.bindClusteredQueue("topic1", queues[0]);
-
- queues[1] = new LocalClusteredQueue(office1, "node1", "sub2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[1] = office1.bindClusteredQueue("topic1", queues[1]);
-
- queues[2] = new LocalClusteredQueue(office2, "node2", "sub3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[2] = office2.bindClusteredQueue("topic1", queues[2]);
-
- queues[3] = new LocalClusteredQueue(office2, "node2", "sub4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[3] = office2.bindClusteredQueue("topic1", queues[3]);
-
- queues[4] = new LocalClusteredQueue(office2, "node2", "sub5", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[4] = office2.bindClusteredQueue("topic1", queues[4]);
-
- queues[5] = new LocalClusteredQueue(office1, "node1", "sub6", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[5] = office1.bindClusteredQueue("topic1", queues[5]);
-
- queues[6] = new LocalClusteredQueue(office1, "node1", "sub7", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[6] = office1.bindClusteredQueue("topic1", queues[6]);
-
- queues[7] = new LocalClusteredQueue(office1, "node1", "sub8", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[7] = office1.bindClusteredQueue("topic1", queues[7]);
-
- queues[8] = new LocalClusteredQueue(office1, "node1", "sub9", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[8] = office1.bindClusteredQueue("topic2", queues[8]);
-
- queues[9] = new LocalClusteredQueue(office1, "node1", "sub10", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[9] = office1.bindClusteredQueue("topic2", queues[9]);
-
- queues[10] = new LocalClusteredQueue(office2, "node2", "sub11", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[10] = office2.bindClusteredQueue("topic2", queues[10]);
-
- queues[11] = new LocalClusteredQueue(office2, "node2", "sub12", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[11] = office2.bindClusteredQueue("topic2", queues[11]);
-
- queues[12] = new LocalClusteredQueue(office2, "node2", "sub13", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[12] = office2.bindClusteredQueue("topic2", queues[12]);
-
- queues[13] = new LocalClusteredQueue(office1, "node1", "sub14", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
- bindings[13] = office1.bindClusteredQueue("topic2", queues[13]);
-
- queues[14] = new LocalClusteredQueue(office1, "node1", "sub15", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[14] = office1.bindClusteredQueue("topic2", queues[14]);
-
- queues[15] = new LocalClusteredQueue(office1, "node1", "sub16", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
- bindings[15] = office1.bindClusteredQueue("topic2", queues[15]);
-
- SimpleReceiver[] receivers = new SimpleReceiver[16];
-
- for (int i = 0; i < 16; i++)
- {
- receivers[i] = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queues[i].add(receivers[i]);
- }
-
- //First for topic 1
-
- Message msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
- MessageReference ref1 = ms.reference(msg1);
-
- Message msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
- MessageReference ref2 = ms.reference(msg2);
-
- Transaction tx = tr.createTransaction();
-
- boolean routed = office1.route(ref1, "topic1", tx);
- assertTrue(routed);
- routed = office1.route(ref2, "topic1", tx);
- assertTrue(routed);
-
-
- for (int i = 0; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- tx.commit();
-
- //Messages are sent asych so may take some finite time to arrive
- Thread.sleep(1000);
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- Message msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
- receivers[i].acknowledge(msgRec1, null);
- receivers[i].acknowledge(msgRec2, null);
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- receivers[i].clear();
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
- ref1 = ms.reference(msg1);
-
- msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
- ref2 = ms.reference(msg2);
-
- tx = tr.createTransaction();
-
- routed = office1.route(ref1, "topic1", tx);
- assertTrue(routed);
- routed = office1.route(ref2, "topic1", tx);
- assertTrue(routed);
-
- //Messages are sent asych so may take some finite time to arrive
- Thread.sleep(1000);
-
- for (int i = 0; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- tx.rollback();
-
- for (int i = 0; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- //Now send some non transactionally
-
- msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
- ref1 = ms.reference(msg1);
-
- msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
- ref2 = ms.reference(msg2);
-
- routed = office1.route(ref1, "topic1", null);
- assertTrue(routed);
- routed = office1.route(ref2, "topic1", null);
- assertTrue(routed);
-
- //Messages are sent asych so may take some finite time to arrive
- Thread.sleep(1000);
-
- //And acknowledge transactionally
-
- tx = tr.createTransaction();
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- Message msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- receivers[i].acknowledge(msgRec1, tx);
- receivers[i].acknowledge(msgRec2, tx);
-
- msgs = queues[i].browse();
-
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- receivers[i].clear();
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- tx.commit();
-
- for (int i = 0; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
-
- // and the rollback
-
- msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
- ref1 = ms.reference(msg1);
-
- msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
- ref2 = ms.reference(msg2);
-
- routed = office1.route(ref1, "topic1", null);
- assertTrue(routed);
- routed = office1.route(ref2, "topic1", null);
- assertTrue(routed);
-
- Thread.sleep(1000);
-
- tx = tr.createTransaction();
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- Message msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- receivers[i].acknowledge(msgRec1, tx);
- receivers[i].acknowledge(msgRec2, tx);
-
- msgs = queues[i].browse();
-
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- tx.rollback();
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- Message msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- msgs = queues[i].browse();
-
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- receivers[i].acknowledge(msgRec1, null);
- receivers[i].acknowledge(msgRec2, null);
-
- receivers[i].clear();
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
-
- // Now for topic 2
-
- msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
- ref1 = ms.reference(msg1);
-
- msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
- ref2 = ms.reference(msg2);
-
- tx = tr.createTransaction();
-
- routed = office1.route(ref1, "topic2", tx);
- assertTrue(routed);
- routed = office1.route(ref2, "topic2", tx);
- assertTrue(routed);
-
-
-
- for (int i = 0; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- tx.commit();
-
- //Messages are sent asych so may take some finite time to arrive
- Thread.sleep(1000);
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- Message msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
- receivers[i].acknowledge(msgRec1, null);
- receivers[i].acknowledge(msgRec2, null);
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- receivers[i].clear();
- }
-
- msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
- ref1 = ms.reference(msg1);
-
- msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
- ref2 = ms.reference(msg2);
-
- tx = tr.createTransaction();
-
- routed = office1.route(ref1, "topic1", tx);
- assertTrue(routed);
- routed = office1.route(ref2, "topic1", tx);
- assertTrue(routed);
-
- for (int i = 0; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- tx.rollback();
-
- for (int i = 0; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- //Now send some non transactionally
-
- msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
- ref1 = ms.reference(msg1);
-
- msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
- ref2 = ms.reference(msg2);
-
- routed = office1.route(ref1, "topic2", null);
- assertTrue(routed);
- routed = office1.route(ref2, "topic2", null);
- assertTrue(routed);
-
- Thread.sleep(1000);
-
- //And acknowledge transactionally
-
- tx = tr.createTransaction();
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- Message msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- receivers[i].acknowledge(msgRec1, tx);
- receivers[i].acknowledge(msgRec2, tx);
-
- msgs = queues[i].browse();
-
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- receivers[i].clear();
- }
-
-
-
- tx.commit();
-
- for (int i = 0; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
-
- // and the rollback
-
- msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
- ref1 = ms.reference(msg1);
-
- msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
- ref2 = ms.reference(msg2);
-
- routed = office1.route(ref1, "topic2", null);
- assertTrue(routed);
- routed = office1.route(ref2, "topic2", null);
- assertTrue(routed);
-
- Thread.sleep(1000);
-
- tx = tr.createTransaction();
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- Message msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
-
- receivers[i].acknowledge(msgRec1, tx);
- receivers[i].acknowledge(msgRec2, tx);
-
-
- msgs = queues[i].browse();
-
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
- }
-
-
-
- tx.rollback();
-
- for (int i = 0; i < 8; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- msgs = queues[i].browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
-
- for (int i = 8; i < 16; i++)
- {
- List msgs = receivers[i].getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- Message msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- msgs = queues[i].browse();
-
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
- msgRec2 = (Message)msgs.get(1);
- assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
-
- receivers[i].acknowledge(msgRec1, null);
- receivers[i].acknowledge(msgRec2, null);
-
- receivers[i].clear();
- }
- }
- finally
- {
- if (office1 != null)
- {
- office2.unbindClusteredQueue("sub5");
- office1.unbindClusteredQueue("sub7");
- office1.unbindClusteredQueue("sub8");
- office2.unbindClusteredQueue("sub13");
- office1.unbindClusteredQueue("sub15");
- office1.unbindClusteredQueue("sub16");
- office1.stop();
- }
-
- if (office2 != null)
- {
- office2.stop();
- }
- }
- }
-
- protected ClusteredPostOffice createClusteredPostOffice(String nodeId, String groupName) throws Exception
- {
- MessagePullPolicy redistPolicy = new NullMessagePullPolicy();
-
- FilterFactory ff = new SimpleFilterFactory();
-
- ClusterRouterFactory rf = new FavourLocalRouterFactory();
-
- DefaultClusteredPostOffice postOffice =
- new DefaultClusteredPostOffice(sc.getDataSource(), sc.getTransactionManager(),
- null, true, nodeId, "Clustered", ms, pm, tr, ff, pool,
- groupName,
- JGroupsUtil.getControlStackProperties(),
- JGroupsUtil.getDataStackProperties(),
- 5000, 5000, redistPolicy, rf, 1);
-
- postOffice.start();
-
- return postOffice;
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
-
-
-
Copied: trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/DefaultClusteredPostOfficeTest.java (from rev 1336, trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java)
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java 2006-09-21 09:41:24 UTC (rev 1336)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/DefaultClusteredPostOfficeTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -0,0 +1,1475 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.test.messaging.core.plugin.postoffice.cluster;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.messaging.core.FilterFactory;
+import org.jboss.messaging.core.Message;
+import org.jboss.messaging.core.MessageReference;
+import org.jboss.messaging.core.local.PagingFilteredQueue;
+import org.jboss.messaging.core.plugin.contract.ClusteredPostOffice;
+import org.jboss.messaging.core.plugin.postoffice.Binding;
+import org.jboss.messaging.core.plugin.postoffice.cluster.ClusterRouterFactory;
+import org.jboss.messaging.core.plugin.postoffice.cluster.DefaultClusteredPostOffice;
+import org.jboss.messaging.core.plugin.postoffice.cluster.FavourLocalRouterFactory;
+import org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue;
+import org.jboss.messaging.core.plugin.postoffice.cluster.MessagePullPolicy;
+import org.jboss.messaging.core.plugin.postoffice.cluster.NullMessagePullPolicy;
+import org.jboss.messaging.core.tx.Transaction;
+import org.jboss.test.messaging.core.SimpleFilter;
+import org.jboss.test.messaging.core.SimpleFilterFactory;
+import org.jboss.test.messaging.core.SimpleReceiver;
+import org.jboss.test.messaging.core.plugin.postoffice.DefaultPostOfficeTest;
+import org.jboss.test.messaging.util.CoreMessageFactory;
+
+import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
+
+/**
+ *
+ * A DefaultClusteredPostOfficeTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public class DefaultClusteredPostOfficeTest extends DefaultPostOfficeTest
+{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public DefaultClusteredPostOfficeTest(String name)
+ {
+ super(name);
+ }
+
+ // Public --------------------------------------------------------
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public final void testClusteredBindUnbind() throws Throwable
+ {
+ ClusteredPostOffice office1 = null;
+
+ ClusteredPostOffice office2 = null;
+
+ ClusteredPostOffice office3 = null;
+
+ try
+ {
+ //Start one office
+
+ office1 = createClusteredPostOffice("node1", "testgroup");
+
+ //Add a couple of bindings
+
+ LocalClusteredQueue queue1 = new LocalClusteredQueue(office1, "node1", "sub1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding1 =
+ office1.bindClusteredQueue("topic1", queue1);
+ LocalClusteredQueue queue2 = new LocalClusteredQueue(office1, "node1", "sub2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding2 =
+ office1.bindClusteredQueue("topic1", queue2);
+
+ //Start another office - make sure it picks up the bindings from the first node
+
+ office2 = createClusteredPostOffice("node2", "testgroup");
+
+ Collection bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(2, bindings.size());
+
+ Iterator iter = bindings.iterator();
+ assertEquivalent(binding1, (Binding)iter.next());
+ assertEquivalent(binding2, (Binding)iter.next());
+
+ //Add another binding on node 2
+
+ LocalClusteredQueue queue3 = new LocalClusteredQueue(office2, "node2", "sub3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding3 =
+ office2.bindClusteredQueue("topic1", queue3);
+
+ //Make sure both nodes pick it up
+
+ bindings = office1.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(3, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding1, (Binding)iter.next());
+ assertEquivalent(binding2, (Binding)iter.next());
+ assertEquivalent(binding3, (Binding)iter.next());
+
+ bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(3, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding1, (Binding)iter.next());
+ assertEquivalent(binding2, (Binding)iter.next());
+ assertEquivalent(binding3, (Binding)iter.next());
+
+ //Add another binding on node 1
+
+ LocalClusteredQueue queue4 = new LocalClusteredQueue(office2, "node2", "sub4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ Binding binding4 =
+ office2.bindClusteredQueue("topic1", queue4);
+
+ // Make sure both nodes pick it up
+
+ bindings = office1.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(4, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding1, (Binding)iter.next());
+ assertEquivalent(binding2, (Binding)iter.next());
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+
+ bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(4, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding1, (Binding)iter.next());
+ assertEquivalent(binding2, (Binding)iter.next());
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+
+ //Unbind binding 1 and binding 2
+ office1.unbindClusteredQueue("sub1");
+ office1.unbindClusteredQueue("sub2");
+
+ //Make sure bindings are not longer available on either node
+
+ bindings = office1.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(2, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+
+ bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(2, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+
+ //Add a third office
+
+ office3 = createClusteredPostOffice("node3", "testgroup");
+
+ //Maks sure it picks up the bindings
+
+ bindings = office3.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(2, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+
+ //Add another binding on node 3
+
+ LocalClusteredQueue queue5 = new LocalClusteredQueue(office3, "node3", "sub5", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding5 =
+ office3.bindClusteredQueue("topic1", queue5);
+
+ // Make sure all nodes pick it up
+
+ bindings = office1.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(3, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+ assertEquivalent(binding5, (Binding)iter.next());
+
+ bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(3, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+ assertEquivalent(binding5, (Binding)iter.next());
+
+ bindings = office3.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(3, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+ assertEquivalent(binding5, (Binding)iter.next());
+
+ //Add a durable and a non durable binding on node 1
+
+ LocalClusteredQueue queue6 = new LocalClusteredQueue(office1, "node1", "sub6", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+
+ Binding binding6 =
+ office1.bindClusteredQueue("topic1", queue6);
+
+ LocalClusteredQueue queue7 = new LocalClusteredQueue(office1, "node1", "sub7", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding7 =
+ office1.bindClusteredQueue("topic1", queue7);
+
+ // Make sure all nodes pick them up
+
+ bindings = office1.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(5, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+ assertEquivalent(binding7, (Binding)iter.next());
+
+ bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(5, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+ assertEquivalent(binding7, (Binding)iter.next());
+
+ bindings = office3.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(5, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+ assertEquivalent(binding7, (Binding)iter.next());
+
+ //Stop office 1
+ office1.stop();
+
+ //Need to sleep since it may take some time for the view changed request to reach the
+ //members which causes the bindings to be removed
+
+ Thread.sleep(1000);
+
+ //All it's non durable bindings should be removed from the other nodes
+ //Durable bindings should remain
+
+ bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(4, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ bindings = office3.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(4, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding3, (Binding)iter.next());
+ assertEquivalent(binding4, (Binding)iter.next());
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ //Stop office 2
+ office2.stop();
+
+ bindings = office3.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(2, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ //Restart office 1 and office 2
+ office1 = createClusteredPostOffice("node1", "testgroup");
+
+ office2 = createClusteredPostOffice("node2", "testgroup");
+
+ bindings = office1.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(2, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(2, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ bindings = office3.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(2, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding5, (Binding)iter.next());
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ //Stop all offices
+
+ office1.stop();
+ office2.stop();
+ office3.stop();
+
+ //Start them all
+ office1 = createClusteredPostOffice("node1", "testgroup");
+ office2 = createClusteredPostOffice("node2", "testgroup");
+ office3 = createClusteredPostOffice("node3", "testgroup");
+
+ //Only the durable queue should survive
+
+ bindings = office1.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(1, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ bindings = office2.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(1, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ bindings = office3.listBindingsForCondition("topic1");
+ assertNotNull(bindings);
+ assertEquals(1, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent(binding6, (Binding)iter.next());
+
+ }
+ finally
+ {
+ if (office1 != null)
+ {
+ try
+ {
+ office1.unbindClusteredQueue("sub6");
+ }
+ catch (Exception ignore)
+ {
+
+ }
+ office1.stop();
+ }
+
+ if (office2 != null)
+ {
+ office2.stop();
+ }
+
+ if (office3 != null)
+ {
+ office2.stop();
+ }
+ }
+
+ }
+
+ public final void testClusteredRoutePersistent() throws Throwable
+ {
+ clusteredRoute(true);
+ }
+
+ public final void testClusteredRouteNonPersistent() throws Throwable
+ {
+ clusteredRoute(false);
+ }
+
+ public final void testClusteredTransactionalRoutePersistent() throws Throwable
+ {
+ clusteredTransactionalRoute(true);
+ }
+
+ public final void testClusteredTransactionalRouteNonPersistent() throws Throwable
+ {
+ clusteredTransactionalRoute(false);
+ }
+
+ public void testClusteredNonPersistentRouteWithFilter() throws Throwable
+ {
+ this.clusteredRouteWithFilter(false);
+ }
+
+ public void testClusteredPersistentRouteWithFilter() throws Throwable
+ {
+ this.clusteredRouteWithFilter(true);
+ }
+
+
+ /*
+ * We should allow the clustered bind of queues with the same queue name on different nodes of the
+ * cluster
+ */
+ public void testClusteredNameUniqueness() throws Throwable
+ {
+ ClusteredPostOffice office1 = null;
+
+ ClusteredPostOffice office2 = null;
+
+ try
+ {
+ office1 = createClusteredPostOffice("node1", "testgroup");
+
+ office2 = createClusteredPostOffice("node2", "testgroup");
+
+ LocalClusteredQueue queue1 = new LocalClusteredQueue(office1, "node1", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding1 = office1.bindClusteredQueue("queue1", queue1);
+
+ LocalClusteredQueue queue2 = new LocalClusteredQueue(office2, "node2", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding2 = office2.bindClusteredQueue("queue1", queue2);
+
+ LocalClusteredQueue queue3 = new LocalClusteredQueue(office1, "node1", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ try
+ {
+ Binding binding3 = office1.bindClusteredQueue("queue1", queue3);
+ fail();
+ }
+ catch (Exception e)
+ {
+ //Ok
+ }
+ LocalClusteredQueue queue4 = new LocalClusteredQueue(office2, "node2", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ try
+ {
+ Binding binding4 = office2.bindClusteredQueue("queue1", queue4);
+ fail();
+ }
+ catch (Exception e)
+ {
+ //Ok
+ }
+
+ office1.unbindClusteredQueue("queue1");
+
+ office2.unbindClusteredQueue("queue1");
+
+ LocalClusteredQueue queue5 = new LocalClusteredQueue(office1, "node1", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding5 = office1.bindClusteredQueue("queue1", queue5);
+
+ PagingFilteredQueue queue6 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ try
+ {
+ Binding binding6 = office1.bindQueue("queue1", queue6);
+ fail();
+ }
+ catch (Exception e)
+ {
+ //ok
+ }
+
+ try
+ {
+ office1.unbindQueue("queue1");
+ fail();
+ }
+ catch (Exception e)
+ {
+ //ok
+ }
+
+ office1.unbindClusteredQueue("queue1");
+
+ PagingFilteredQueue queue7 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ Binding binding7 = office1.bindQueue("queue1", queue7);
+
+ PagingFilteredQueue queue8 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ Binding binding8 = office2.bindQueue("queue1", queue8);
+
+ PagingFilteredQueue queue9 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ try
+ {
+ Binding binding9 = office1.bindQueue("queue1", queue9);
+ fail();
+ }
+ catch (Exception e)
+ {
+ //Ok
+ }
+
+ }
+ finally
+ {
+ if (office1 != null)
+ {
+ office1.stop();
+ }
+
+ if (office2 != null)
+ {
+ office2.stop();
+ }
+ }
+ }
+
+
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void clusteredRouteWithFilter(boolean persistentMessage) throws Throwable
+ {
+ ClusteredPostOffice office1 = null;
+
+ ClusteredPostOffice office2 = null;
+
+ try
+ {
+ office1 = createClusteredPostOffice("node1", "testgroup");
+ office2 = createClusteredPostOffice("node2", "testgroup");
+
+ SimpleFilter filter1 = new SimpleFilter(2);
+ SimpleFilter filter2 = new SimpleFilter(3);
+
+ LocalClusteredQueue queue1 = new LocalClusteredQueue(office1, "node1", "queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), filter1);
+ Binding binding1 =
+ office1.bindClusteredQueue("topic1", queue1);
+
+ LocalClusteredQueue queue2 = new LocalClusteredQueue(office2, "node2", "queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), filter2);
+ Binding binding2 =
+ office2.bindClusteredQueue("topic1", queue2);
+
+ LocalClusteredQueue queue3 = new LocalClusteredQueue(office2, "node2", "queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ Binding binding3 =
+ office2.bindClusteredQueue("topic1", queue3);
+
+ SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue1.add(receiver1);
+ SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue2.add(receiver2);
+ SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue3.add(receiver3);
+
+ Message msg1 = CoreMessageFactory.createCoreMessage(1);
+ MessageReference ref1 = ms.reference(msg1);
+ boolean routed = office1.route(ref1, "topic1", null);
+ assertTrue(routed);
+ Message msg2 = CoreMessageFactory.createCoreMessage(2);
+ MessageReference ref2 = ms.reference(msg2);
+ routed = office1.route(ref2, "topic1", null);
+ assertTrue(routed);
+ Message msg3 = CoreMessageFactory.createCoreMessage(3);
+ MessageReference ref3 = ms.reference(msg3);
+ routed = office1.route(ref3, "topic1", null);
+ assertTrue(routed);
+
+ Thread.sleep(1000);
+
+ List msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ Message msgRec = (Message)msgs.get(0);
+ assertTrue(msg2 == msgRec);
+ receiver1.acknowledge(msgRec, null);
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ msgRec = (Message)msgs.get(0);
+ assertTrue(msg3 == msgRec);
+ receiver2.acknowledge(msgRec, null);
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver3.getMessages();
+ assertNotNull(msgs);
+ assertEquals(3, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertTrue(msg1 == msgRec1);
+ Message msgRec2 = (Message)msgs.get(1);
+ assertTrue(msg2 == msgRec2);
+ Message msgRec3 = (Message)msgs.get(2);
+ assertTrue(msg3 == msgRec3);
+
+ receiver3.acknowledge(msgRec1, null);
+ receiver3.acknowledge(msgRec2, null);
+ receiver3.acknowledge(msgRec3, null);
+ msgs = queue3.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ }
+ finally
+ {
+ if (office1 != null)
+ {
+ office1.stop();
+ }
+
+ if (office2 != null)
+ {
+ office2.stop();
+ }
+ }
+ }
+
+ protected void clusteredRoute(boolean persistentMessage) throws Throwable
+ {
+ ClusteredPostOffice office1 = null;
+
+ ClusteredPostOffice office2 = null;
+
+ try
+ {
+ office1 = createClusteredPostOffice("node1", "testgroup");
+ office2 = createClusteredPostOffice("node2", "testgroup");
+
+ //Two topics with a mixture of durable and non durable subscriptions
+
+ LocalClusteredQueue[] queues = new LocalClusteredQueue[16];
+ Binding[] bindings = new Binding[16];
+
+ queues[0] = new LocalClusteredQueue(office1, "node1", "sub1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[0] = office1.bindClusteredQueue("topic1", queues[0]);
+
+ queues[1] = new LocalClusteredQueue(office1, "node1", "sub2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[1] = office1.bindClusteredQueue("topic1", queues[1]);
+
+ queues[2] = new LocalClusteredQueue(office2, "node2", "sub3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[2] = office2.bindClusteredQueue("topic1", queues[2]);
+
+ queues[3] = new LocalClusteredQueue(office2, "node2", "sub4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[3] = office2.bindClusteredQueue("topic1", queues[3]);
+
+ queues[4] = new LocalClusteredQueue(office2, "node2", "sub5", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[4] = office2.bindClusteredQueue("topic1", queues[4]);
+
+ queues[5] = new LocalClusteredQueue(office1, "node1", "sub6", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[5] = office1.bindClusteredQueue("topic1", queues[5]);
+
+ queues[6] = new LocalClusteredQueue(office1, "node1", "sub7", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[6] = office1.bindClusteredQueue("topic1", queues[6]);
+
+ queues[7] = new LocalClusteredQueue(office1, "node1", "sub8", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[7] = office1.bindClusteredQueue("topic1", queues[7]);
+
+ queues[8] = new LocalClusteredQueue(office1, "node1", "sub9", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[8] = office1.bindClusteredQueue("topic2", queues[8]);
+
+ queues[9] = new LocalClusteredQueue(office1, "node1", "sub10", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[9] = office1.bindClusteredQueue("topic2", queues[9]);
+
+ queues[10] = new LocalClusteredQueue(office2, "node2", "sub11", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[10] = office2.bindClusteredQueue("topic2", queues[10]);
+
+ queues[11] = new LocalClusteredQueue(office2, "node2", "sub12", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[11] = office2.bindClusteredQueue("topic2", queues[11]);
+
+ queues[12] = new LocalClusteredQueue(office2, "node2", "sub13", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[12] = office2.bindClusteredQueue("topic2", queues[12]);
+
+ queues[13] = new LocalClusteredQueue(office1, "node1", "sub14", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[13] = office1.bindClusteredQueue("topic2", queues[13]);
+
+ queues[14] = new LocalClusteredQueue(office1, "node1", "sub15", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[14] = office1.bindClusteredQueue("topic2", queues[14]);
+
+ queues[15] = new LocalClusteredQueue(office1, "node1", "sub16", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[15] = office1.bindClusteredQueue("topic2", queues[15]);
+
+ SimpleReceiver[] receivers = new SimpleReceiver[16];
+
+ for (int i = 0; i < 16; i++)
+ {
+ receivers[i] = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queues[i].add(receivers[i]);
+ }
+
+ Message msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
+ MessageReference ref = ms.reference(msg);
+
+ boolean routed = office1.route(ref, "topic1", null);
+ assertTrue(routed);
+
+ //Messages are sent asych so may take some finite time to arrive
+ Thread.sleep(1000);
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ Message msgRec = (Message)msgs.get(0);
+ assertEquals(msg.getMessageID(), msgRec.getMessageID());
+ receivers[i].acknowledge(msgRec, null);
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ receivers[i].clear();
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ //Now route to topic2
+
+ msg = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);;
+ ref = ms.reference(msg);
+
+ routed = office1.route(ref, "topic2", null);
+ assertTrue(routed);
+ //Messages are sent asych so may take some finite time to arrive
+ Thread.sleep(1000);
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ Message msgRec = (Message)msgs.get(0);
+ assertEquals(msg.getMessageID(), msgRec.getMessageID());
+ receivers[i].acknowledge(msgRec, null);
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ receivers[i].clear();
+ }
+
+ }
+ finally
+ {
+ if (office1 != null)
+ {
+ try
+ {
+ office2.unbindClusteredQueue("sub5");
+ office1.unbindClusteredQueue("sub7");
+ office1.unbindClusteredQueue("sub8");
+ office2.unbindClusteredQueue("sub13");
+ office1.unbindClusteredQueue("sub15");
+ office1.unbindClusteredQueue("sub16");
+ }
+ catch (Exception ignore)
+ {
+
+ }
+
+ office1.stop();
+ }
+
+ if (office2 != null)
+ {
+ office2.stop();
+ }
+ }
+ }
+
+
+ protected void clusteredTransactionalRoute(boolean persistent) throws Throwable
+ {
+ ClusteredPostOffice office1 = null;
+
+ ClusteredPostOffice office2 = null;
+
+ try
+ {
+ //Start two offices
+
+ office1 = createClusteredPostOffice("node1", "testgroup");
+ office2 = createClusteredPostOffice("node2", "testgroup");
+
+ LocalClusteredQueue[] queues = new LocalClusteredQueue[16];
+ Binding[] bindings = new Binding[16];
+
+ queues[0] = new LocalClusteredQueue(office1, "node1", "sub1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[0] = office1.bindClusteredQueue("topic1", queues[0]);
+
+ queues[1] = new LocalClusteredQueue(office1, "node1", "sub2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[1] = office1.bindClusteredQueue("topic1", queues[1]);
+
+ queues[2] = new LocalClusteredQueue(office2, "node2", "sub3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[2] = office2.bindClusteredQueue("topic1", queues[2]);
+
+ queues[3] = new LocalClusteredQueue(office2, "node2", "sub4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[3] = office2.bindClusteredQueue("topic1", queues[3]);
+
+ queues[4] = new LocalClusteredQueue(office2, "node2", "sub5", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[4] = office2.bindClusteredQueue("topic1", queues[4]);
+
+ queues[5] = new LocalClusteredQueue(office1, "node1", "sub6", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[5] = office1.bindClusteredQueue("topic1", queues[5]);
+
+ queues[6] = new LocalClusteredQueue(office1, "node1", "sub7", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[6] = office1.bindClusteredQueue("topic1", queues[6]);
+
+ queues[7] = new LocalClusteredQueue(office1, "node1", "sub8", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[7] = office1.bindClusteredQueue("topic1", queues[7]);
+
+ queues[8] = new LocalClusteredQueue(office1, "node1", "sub9", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[8] = office1.bindClusteredQueue("topic2", queues[8]);
+
+ queues[9] = new LocalClusteredQueue(office1, "node1", "sub10", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[9] = office1.bindClusteredQueue("topic2", queues[9]);
+
+ queues[10] = new LocalClusteredQueue(office2, "node2", "sub11", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[10] = office2.bindClusteredQueue("topic2", queues[10]);
+
+ queues[11] = new LocalClusteredQueue(office2, "node2", "sub12", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[11] = office2.bindClusteredQueue("topic2", queues[11]);
+
+ queues[12] = new LocalClusteredQueue(office2, "node2", "sub13", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[12] = office2.bindClusteredQueue("topic2", queues[12]);
+
+ queues[13] = new LocalClusteredQueue(office1, "node1", "sub14", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ bindings[13] = office1.bindClusteredQueue("topic2", queues[13]);
+
+ queues[14] = new LocalClusteredQueue(office1, "node1", "sub15", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[14] = office1.bindClusteredQueue("topic2", queues[14]);
+
+ queues[15] = new LocalClusteredQueue(office1, "node1", "sub16", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+ bindings[15] = office1.bindClusteredQueue("topic2", queues[15]);
+
+ SimpleReceiver[] receivers = new SimpleReceiver[16];
+
+ for (int i = 0; i < 16; i++)
+ {
+ receivers[i] = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queues[i].add(receivers[i]);
+ }
+
+ //First for topic 1
+
+ Message msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
+ MessageReference ref1 = ms.reference(msg1);
+
+ Message msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
+ MessageReference ref2 = ms.reference(msg2);
+
+ Transaction tx = tr.createTransaction();
+
+ boolean routed = office1.route(ref1, "topic1", tx);
+ assertTrue(routed);
+ routed = office1.route(ref2, "topic1", tx);
+ assertTrue(routed);
+
+
+ for (int i = 0; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ tx.commit();
+
+ //Messages are sent asych so may take some finite time to arrive
+ Thread.sleep(1000);
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ Message msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+ receivers[i].acknowledge(msgRec1, null);
+ receivers[i].acknowledge(msgRec2, null);
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ receivers[i].clear();
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
+ ref1 = ms.reference(msg1);
+
+ msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
+ ref2 = ms.reference(msg2);
+
+ tx = tr.createTransaction();
+
+ routed = office1.route(ref1, "topic1", tx);
+ assertTrue(routed);
+ routed = office1.route(ref2, "topic1", tx);
+ assertTrue(routed);
+
+ //Messages are sent asych so may take some finite time to arrive
+ Thread.sleep(1000);
+
+ for (int i = 0; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ tx.rollback();
+
+ for (int i = 0; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ //Now send some non transactionally
+
+ msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
+ ref1 = ms.reference(msg1);
+
+ msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
+ ref2 = ms.reference(msg2);
+
+ routed = office1.route(ref1, "topic1", null);
+ assertTrue(routed);
+ routed = office1.route(ref2, "topic1", null);
+ assertTrue(routed);
+
+ //Messages are sent asych so may take some finite time to arrive
+ Thread.sleep(1000);
+
+ //And acknowledge transactionally
+
+ tx = tr.createTransaction();
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ Message msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ receivers[i].acknowledge(msgRec1, tx);
+ receivers[i].acknowledge(msgRec2, tx);
+
+ msgs = queues[i].browse();
+
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ receivers[i].clear();
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ tx.commit();
+
+ for (int i = 0; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+
+ // and the rollback
+
+ msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
+ ref1 = ms.reference(msg1);
+
+ msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
+ ref2 = ms.reference(msg2);
+
+ routed = office1.route(ref1, "topic1", null);
+ assertTrue(routed);
+ routed = office1.route(ref2, "topic1", null);
+ assertTrue(routed);
+
+ Thread.sleep(1000);
+
+ tx = tr.createTransaction();
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ Message msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ receivers[i].acknowledge(msgRec1, tx);
+ receivers[i].acknowledge(msgRec2, tx);
+
+ msgs = queues[i].browse();
+
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ tx.rollback();
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ Message msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ msgs = queues[i].browse();
+
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ receivers[i].acknowledge(msgRec1, null);
+ receivers[i].acknowledge(msgRec2, null);
+
+ receivers[i].clear();
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+
+ // Now for topic 2
+
+ msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
+ ref1 = ms.reference(msg1);
+
+ msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
+ ref2 = ms.reference(msg2);
+
+ tx = tr.createTransaction();
+
+ routed = office1.route(ref1, "topic2", tx);
+ assertTrue(routed);
+ routed = office1.route(ref2, "topic2", tx);
+ assertTrue(routed);
+
+
+
+ for (int i = 0; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ tx.commit();
+
+ //Messages are sent asych so may take some finite time to arrive
+ Thread.sleep(1000);
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ Message msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+ receivers[i].acknowledge(msgRec1, null);
+ receivers[i].acknowledge(msgRec2, null);
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ receivers[i].clear();
+ }
+
+ msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
+ ref1 = ms.reference(msg1);
+
+ msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
+ ref2 = ms.reference(msg2);
+
+ tx = tr.createTransaction();
+
+ routed = office1.route(ref1, "topic1", tx);
+ assertTrue(routed);
+ routed = office1.route(ref2, "topic1", tx);
+ assertTrue(routed);
+
+ for (int i = 0; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ tx.rollback();
+
+ for (int i = 0; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ //Now send some non transactionally
+
+ msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);
+ ref1 = ms.reference(msg1);
+
+ msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);
+ ref2 = ms.reference(msg2);
+
+ routed = office1.route(ref1, "topic2", null);
+ assertTrue(routed);
+ routed = office1.route(ref2, "topic2", null);
+ assertTrue(routed);
+
+ Thread.sleep(1000);
+
+ //And acknowledge transactionally
+
+ tx = tr.createTransaction();
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ Message msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ receivers[i].acknowledge(msgRec1, tx);
+ receivers[i].acknowledge(msgRec2, tx);
+
+ msgs = queues[i].browse();
+
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ receivers[i].clear();
+ }
+
+
+
+ tx.commit();
+
+ for (int i = 0; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+
+ // and the rollback
+
+ msg1 = CoreMessageFactory.createCoreMessage(1, persistent, null);;
+ ref1 = ms.reference(msg1);
+
+ msg2 = CoreMessageFactory.createCoreMessage(2, persistent, null);;
+ ref2 = ms.reference(msg2);
+
+ routed = office1.route(ref1, "topic2", null);
+ assertTrue(routed);
+ routed = office1.route(ref2, "topic2", null);
+ assertTrue(routed);
+
+ Thread.sleep(1000);
+
+ tx = tr.createTransaction();
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ Message msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+
+ receivers[i].acknowledge(msgRec1, tx);
+ receivers[i].acknowledge(msgRec2, tx);
+
+
+ msgs = queues[i].browse();
+
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+ }
+
+
+
+ tx.rollback();
+
+ for (int i = 0; i < 8; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ msgs = queues[i].browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+
+ for (int i = 8; i < 16; i++)
+ {
+ List msgs = receivers[i].getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ Message msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ msgs = queues[i].browse();
+
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ assertEquals(msg1.getMessageID(), msgRec1.getMessageID());
+ msgRec2 = (Message)msgs.get(1);
+ assertEquals(msg2.getMessageID(), msgRec2.getMessageID());
+
+ receivers[i].acknowledge(msgRec1, null);
+ receivers[i].acknowledge(msgRec2, null);
+
+ receivers[i].clear();
+ }
+ }
+ finally
+ {
+ if (office1 != null)
+ {
+ office2.unbindClusteredQueue("sub5");
+ office1.unbindClusteredQueue("sub7");
+ office1.unbindClusteredQueue("sub8");
+ office2.unbindClusteredQueue("sub13");
+ office1.unbindClusteredQueue("sub15");
+ office1.unbindClusteredQueue("sub16");
+ office1.stop();
+ }
+
+ if (office2 != null)
+ {
+ office2.stop();
+ }
+ }
+ }
+
+ protected ClusteredPostOffice createClusteredPostOffice(String nodeId, String groupName) throws Exception
+ {
+ MessagePullPolicy redistPolicy = new NullMessagePullPolicy();
+
+ FilterFactory ff = new SimpleFilterFactory();
+
+ ClusterRouterFactory rf = new FavourLocalRouterFactory();
+
+ DefaultClusteredPostOffice postOffice =
+ new DefaultClusteredPostOffice(sc.getDataSource(), sc.getTransactionManager(),
+ null, true, nodeId, "Clustered", ms, pm, tr, ff, pool,
+ groupName,
+ JGroupsUtil.getControlStackProperties(),
+ JGroupsUtil.getDataStackProperties(),
+ 5000, 5000, redistPolicy, rf, 1);
+
+ postOffice.start();
+
+ return postOffice;
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
+
+
+
Modified: trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java 2006-09-21 21:45:55 UTC (rev 1339)
+++ trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java 2006-09-21 22:02:48 UTC (rev 1340)
@@ -27,6 +27,7 @@
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -372,9 +373,9 @@
InvocationRequest ir = new InvocationRequest(null, null, mm, null, null, null);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+
wf.write(ir, oos);
oos.flush();
@@ -383,43 +384,43 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
//Check the bytes
//First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
//First byte should be ACKNOWLEDGE
- assertEquals(JMSWireFormat.ACKNOWLEDGE_BATCH, ois.readByte());
+ assertEquals(JMSWireFormat.ACKNOWLEDGE_BATCH, dis.readByte());
//Next int should be objectId
- assertEquals(objectId, ois.readInt());
+ assertEquals(objectId, dis.readInt());
//Next long should be methodHash
- assertEquals(methodHash, ois.readLong());
+ assertEquals(methodHash, dis.readLong());
//Next should be number of acks
- assertEquals(3, ois.readInt());
+ assertEquals(3, dis.readInt());
//Now the acks
AckInfo ack = new AckInfo();
- ack.read(ois);
+ ack.read(dis);
assertEquals(ackA.getMessageID(), ack.getMessageID());
assertEquals(ackA.getConsumerID(), ack.getConsumerID());
ack = new AckInfo();
- ack.read(ois);
+ ack.read(dis);
assertEquals(ackB.getMessageID(), ack.getMessageID());
assertEquals(ackB.getConsumerID(), ack.getConsumerID());
ack = new AckInfo();
- ack.read(ois);
+ ack.read(dis);
assertEquals(ackC.getMessageID(), ack.getMessageID());
assertEquals(ackC.getConsumerID(), ack.getConsumerID());
@@ -428,7 +429,7 @@
//Now eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -438,7 +439,7 @@
bis.reset();
- ois = new DataInputStream(bis);
+ ObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
@@ -496,7 +497,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -506,16 +507,16 @@
// Check the bytes
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
// First byte should be version
- byte version = ois.readByte();
+ byte version = dis.readByte();
assertEquals(CURRENT_VERSION, version);
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
@@ -557,7 +558,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -565,16 +566,16 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
// First byte should be version
- byte version = ois.readByte();
+ byte version = dis.readByte();
assertEquals(CURRENT_VERSION, version);
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
@@ -601,7 +602,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -609,16 +610,16 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
// First byte should be version
- byte version = ois.readByte();
+ byte version = dis.readByte();
assertEquals(CURRENT_VERSION, version);
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
@@ -656,7 +657,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -666,37 +667,37 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
//Check the bytes
//First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
//First byte should be SEND
- assertEquals(JMSWireFormat.SEND, ois.readByte());
+ assertEquals(JMSWireFormat.SEND, dis.readByte());
//Next int should be objectId
- assertEquals(objectId, ois.readInt());
+ assertEquals(objectId, dis.readInt());
//Next long should be methodHash
- assertEquals(methodHash, ois.readLong());
+ assertEquals(methodHash, dis.readLong());
//Next should be be type
- byte type = ois.readByte();
+ byte type = dis.readByte();
assertEquals(JBossMessage.TYPE, type);
//Next should come the message
JBossMessage m2 = new JBossMessage();
- m2.read(ois);
+ m2.read(dis);
//should be eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -707,7 +708,7 @@
MessageTest.ensureEquivalent(m, m2);
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
@@ -756,7 +757,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -766,33 +767,33 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
//Check the bytes
//First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
//First byte should be SEND_TRANSACTION
- assertEquals(JMSWireFormat.SEND_TRANSACTION, ois.readByte());
+ assertEquals(JMSWireFormat.SEND_TRANSACTION, dis.readByte());
//Next int should be objectId
- assertEquals(objectId, ois.readInt());
+ assertEquals(objectId, dis.readInt());
//Next long should be methodHash
- assertEquals(methodHash, ois.readLong());
+ assertEquals(methodHash, dis.readLong());
//Next should come the transaction request
TransactionRequest req = new TransactionRequest();
- req.read(ois);
+ req.read(dis);
//should be eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -812,8 +813,9 @@
assertEquals(info.getMessageID(), info2.getMessageID());
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+
InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
mm = (MessagingMarshallable)ir2.getParameter();
@@ -867,7 +869,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -877,25 +879,25 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
//Check the bytes
//First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
//Next byte should be CANCEL_MESSAGES
- assertEquals(JMSWireFormat.CANCEL_DELIVERIES, ois.readByte());
+ assertEquals(JMSWireFormat.CANCEL_DELIVERIES, dis.readByte());
//Next int should be objectId
- assertEquals(objectId, ois.readInt());
+ assertEquals(objectId, dis.readInt());
//Next long should be methodHash
- assertEquals(methodHash, ois.readLong());
+ assertEquals(methodHash, dis.readLong());
//Next should the size of the list
- int size = ois.readInt();
+ int size = dis.readInt();
assertEquals(2, size);
@@ -904,9 +906,9 @@
AckInfo rack2 = new AckInfo();
- rack1.read(ois);
+ rack1.read(dis);
- rack2.read(ois);
+ rack2.read(dis);
assertEquals(ack1.getConsumerID(), rack1.getConsumerID());
@@ -920,7 +922,7 @@
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -930,8 +932,9 @@
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+
InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
mm = (MessagingMarshallable)ir2.getParameter();
@@ -966,27 +969,27 @@
InvocationResponse resp = new InvocationResponse(null, mm, false, null);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(resp, oos);
oos.flush();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
// First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
// Should be 1 byte
- byte b = ois.readByte();
+ byte b = dis.readByte();
assertEquals(JMSWireFormat.NULL_RESPONSE, b);
// Should be eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -996,10 +999,8 @@
bis.reset();
- // END of the invalid section
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
- ois = new DataInputStream(bis);
-
InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
mm = (MessagingMarshallable)ir2.getResult();
@@ -1028,7 +1029,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -1038,26 +1039,26 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
//Check the bytes
//First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
//Second byte should be MORE
- assertEquals(JMSWireFormat.MORE, ois.readByte());
+ assertEquals(JMSWireFormat.MORE, dis.readByte());
//Next int should be objectId
- assertEquals(objectId, ois.readInt());
+ assertEquals(objectId, dis.readInt());
//Next long should be methodHash
- assertEquals(methodHash, ois.readLong());
+ assertEquals(methodHash, dis.readLong());
//Now eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -1066,7 +1067,7 @@
}
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
@@ -1109,7 +1110,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
MessagingMarshallable mm = new MessagingMarshallable((byte)77, dr);
@@ -1121,58 +1122,58 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
//Check the bytes
//First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
//Second byte should be CALLBACK
- assertEquals(JMSWireFormat.CALLBACK, ois.readByte());
+ assertEquals(JMSWireFormat.CALLBACK, dis.readByte());
//Next int should be consumer id
- assertEquals(12345678, ois.readInt());
+ assertEquals(12345678, dis.readInt());
//Next int should be number of messages
- assertEquals(3, ois.readInt());
+ assertEquals(3, dis.readInt());
//Next byte should be type
- assertEquals(JBossMessage.TYPE, ois.readByte());
+ assertEquals(JBossMessage.TYPE, dis.readByte());
//Next int should be delivery count
- assertEquals(7, ois.readInt());
+ assertEquals(7, dis.readInt());
//And now the message itself
JBossMessage r1 = new JBossMessage();
- r1.read(ois);
+ r1.read(dis);
//Next byte should be type
- assertEquals(JBossMessage.TYPE, ois.readByte());
+ assertEquals(JBossMessage.TYPE, dis.readByte());
//Next int should be delivery count
- assertEquals(8, ois.readInt());
+ assertEquals(8, dis.readInt());
//And now the message itself
JBossMessage r2 = new JBossMessage();
- r2.read(ois);
+ r2.read(dis);
//Next byte should be type
- assertEquals(JBossMessage.TYPE, ois.readByte());
+ assertEquals(JBossMessage.TYPE, dis.readByte());
//Next int should be delivery count
- assertEquals(9, ois.readInt());
+ assertEquals(9, dis.readInt());
//And now the message itself
JBossMessage r3 = new JBossMessage();
- r3.read(ois);
+ r3.read(dis);
MessageTest.ensureEquivalent(m1, r1);
MessageTest.ensureEquivalent(m2, r2);
@@ -1181,7 +1182,7 @@
//eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -1191,7 +1192,7 @@
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
@@ -1233,7 +1234,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -1241,18 +1242,18 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
// First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
- int b = ois.readByte();
+ int b = dis.readByte();
assertEquals(JMSWireFormat.ID_BLOCK_RESPONSE, b);
IdBlock block2 = new IdBlock();
- block2.read(ois);
+ block2.read(dis);
assertEquals(block.getLow(), block2.getLow());
assertEquals(block.getHigh(), block2.getHigh());
@@ -1260,7 +1261,7 @@
//eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -1270,7 +1271,7 @@
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
@@ -1294,7 +1295,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -1302,18 +1303,18 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
// First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
- int b = ois.readByte();
+ int b = dis.readByte();
assertEquals(JMSWireFormat.HANDLE_MESSAGE_RESPONSE, b);
HandleMessageResponse h2 = new HandleMessageResponse();
- h2.read(ois);
+ h2.read(dis);
assertEquals(h.clientIsFull(), h2.clientIsFull());
assertEquals(h.getNumberAccepted(), h2.getNumberAccepted());
@@ -1321,7 +1322,7 @@
//eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -1331,7 +1332,7 @@
bis.reset();
- ois = new DataInputStream(bis);
+ MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
More information about the jboss-cvs-commits
mailing list