[jboss-cvs] JBoss Messaging SVN: r7537 - in branches/Branch_MultiThreaded_Replication: src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 7 16:03:16 EDT 2009
Author: timfox
Date: 2009-07-07 16:03:15 -0400 (Tue, 07 Jul 2009)
New Revision: 7537
Added:
branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/QueuedWriteManager.java
branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication/UnregisterQueueReplicationChannelMessage.java
branches/Branch_MultiThreaded_Replication/tests/src/org/jboss/messaging/tests/unit/core/server/replication/impl/QueuedWriteManagerTest.java
Modified:
branches/Branch_MultiThreaded_Replication/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadFailoverSupport.java
Log:
MT replication
Added: branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/QueuedWriteManager.java
===================================================================
--- branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/QueuedWriteManager.java (rev 0)
+++ branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/QueuedWriteManager.java 2009-07-07 20:03:15 UTC (rev 7537)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.core.remoting.impl;
+
+import java.util.Iterator;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.Channel;
+import org.jboss.messaging.core.remoting.Packet;
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
+import org.jboss.messaging.core.server.replication.Replicator;
+import org.jboss.messaging.core.server.replication.impl.JBMThread;
+import org.jboss.messaging.tests.unit.core.server.replication.impl.QueuedWriteManagerTest.MyPacket;
+
+/**
+ * A QueuedWriteManager
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class QueuedWriteManager
+{
+ private static final Logger log = Logger.getLogger(QueuedWriteManager.class);
+
+ private final java.util.Queue<QueuedWrite> queuedWrites = new ConcurrentLinkedQueue<QueuedWrite>();
+
+ private final Channel channel;
+
+ public QueuedWriteManager(final Channel channel)
+ {
+ this.channel = channel;
+ }
+
+ public boolean tryQueue(final Packet packet)
+ {
+ // TODO - this is a bit ugly
+ Thread t = Thread.currentThread();
+
+ if (t instanceof JBMThread)
+ {
+ JBMThread thread = (JBMThread)t;
+
+ if (thread.isRecording() && packet.getType() != PacketImpl.PING)
+ {
+ thread.getReplicator().registerWaitingChannel(this);
+
+ QueuedWrite qw = new QueuedWrite();
+ qw.replicator = thread.getReplicator();
+ qw.packet = packet;
+
+ queuedWrites.add(qw);
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void queueWrite(final Replicator replicator, final Packet packet)
+ {
+ QueuedWrite qw = new QueuedWrite();
+ qw.replicator = replicator;
+ qw.packet = packet;
+
+ queuedWrites.add(qw);
+ }
+
+// private void dumpQueuedWrites()
+// {
+// Iterator<QueuedWrite> iter = this.queuedWrites.iterator();
+//
+// log.info("dumping queued writes");
+//
+// while (iter.hasNext())
+// {
+// QueuedWrite qw = (QueuedWrite)iter.next();
+//
+// log.info("repl:" + qw.replicator + " packet: " + ((MyPacket)qw.packet).getSeq() + " done:" + qw.done);
+// }
+// }
+
+ public synchronized void replicationResponseReceived(final Replicator replicator, final int num)
+ {
+ // TODO this can be optimised
+ Iterator<QueuedWrite> iter = null;
+
+ int count = 0;
+
+ while (true)
+ {
+ QueuedWrite qw;
+
+ if (iter == null)
+ {
+ qw = queuedWrites.peek();
+ }
+ else
+ {
+ qw = iter.next();
+ }
+
+ boolean send = false;
+
+ if (qw.replicator == replicator)
+ {
+ if (iter == null)
+ {
+ send = true;
+
+ count++;
+ }
+ else
+ {
+ if (!qw.done)
+ {
+ qw.done = true;
+
+ count++;
+ }
+ }
+
+ }
+ else if (qw.done && iter == null)
+ {
+ send = true;
+ }
+
+ if (send)
+ {
+ queuedWrites.remove();
+
+ channel.send(qw.packet);
+ }
+ else
+ {
+ if (iter == null)
+ {
+ iter = queuedWrites.iterator();
+
+ iter.next();
+ }
+ }
+
+ if (count == num)
+ {
+ qw = queuedWrites.peek();
+
+ if (qw != null && qw.done)
+ {
+ continue;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ private static class QueuedWrite
+ {
+ Replicator replicator;
+
+ Packet packet;
+
+ boolean done;
+ }
+}
Added: branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication/UnregisterQueueReplicationChannelMessage.java
===================================================================
--- branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication/UnregisterQueueReplicationChannelMessage.java (rev 0)
+++ branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication/UnregisterQueueReplicationChannelMessage.java 2009-07-07 20:03:15 UTC (rev 7537)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors 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.messaging.core.remoting.impl.wireformat.replication;
+
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.utils.DataConstants;
+
+/**
+ *
+ * A RegisterQueueReplicationChannelMessage
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class UnregisterQueueReplicationChannelMessage extends PacketImpl
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private long bindingID;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public UnregisterQueueReplicationChannelMessage(final long bindingID)
+ {
+ super(UNREGISTER_QUEUE_REPLICATION_CHANNEL);
+
+ this.bindingID = bindingID;
+ }
+
+ // Public --------------------------------------------------------
+
+ public UnregisterQueueReplicationChannelMessage()
+ {
+ super(UNREGISTER_QUEUE_REPLICATION_CHANNEL);
+ }
+
+ public int getRequiredBufferSize()
+ {
+ return BASIC_PACKET_SIZE + DataConstants.SIZE_LONG;
+ }
+
+ @Override
+ public void encodeBody(final MessagingBuffer buffer)
+ {
+ buffer.writeLong(bindingID);
+ }
+
+ @Override
+ public void decodeBody(final MessagingBuffer buffer)
+ {
+ bindingID = buffer.readLong();
+ }
+
+ public long getBindingID()
+ {
+ return bindingID;
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Modified: branches/Branch_MultiThreaded_Replication/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadFailoverSupport.java
===================================================================
--- branches/Branch_MultiThreaded_Replication/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadFailoverSupport.java 2009-07-07 19:45:08 UTC (rev 7536)
+++ branches/Branch_MultiThreaded_Replication/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadFailoverSupport.java 2009-07-07 20:03:15 UTC (rev 7537)
@@ -256,25 +256,25 @@
@Override
public synchronized void run()
{
-// log.info("** Failing connection");
-//
-// RemotingConnectionImpl conn = (RemotingConnectionImpl)((ClientSessionImpl)session).getConnection();
-//
-// if (failOnCreateConnection)
-// {
-// InVMConnector.numberOfFailures = 1;
-// InVMConnector.failOnCreateConnection = true;
-// }
-// else
-// {
-// conn.fail(new MessagingException(MessagingException.NOT_CONNECTED, "blah"));
-// }
-//
-// log.info("** Fail complete");
-//
-// cancel();
-//
-// executed = true;
+ log.info("** Failing connection");
+
+ RemotingConnectionImpl conn = (RemotingConnectionImpl)((ClientSessionImpl)session).getConnection();
+
+ if (failOnCreateConnection)
+ {
+ InVMConnector.numberOfFailures = 1;
+ InVMConnector.failOnCreateConnection = true;
+ }
+ else
+ {
+ conn.fail(new MessagingException(MessagingException.NOT_CONNECTED, "blah"));
+ }
+
+ log.info("** Fail complete");
+
+ cancel();
+
+ executed = true;
}
public synchronized boolean isExecuted()
Added: branches/Branch_MultiThreaded_Replication/tests/src/org/jboss/messaging/tests/unit/core/server/replication/impl/QueuedWriteManagerTest.java
===================================================================
--- branches/Branch_MultiThreaded_Replication/tests/src/org/jboss/messaging/tests/unit/core/server/replication/impl/QueuedWriteManagerTest.java (rev 0)
+++ branches/Branch_MultiThreaded_Replication/tests/src/org/jboss/messaging/tests/unit/core/server/replication/impl/QueuedWriteManagerTest.java 2009-07-07 20:03:15 UTC (rev 7537)
@@ -0,0 +1,818 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.unit.core.server.replication.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.locks.Lock;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.Channel;
+import org.jboss.messaging.core.remoting.ChannelHandler;
+import org.jboss.messaging.core.remoting.CommandConfirmationHandler;
+import org.jboss.messaging.core.remoting.Packet;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.QueuedWriteManager;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.core.server.replication.ReplicableAction;
+import org.jboss.messaging.core.server.replication.Replicator;
+import org.jboss.messaging.core.server.replication.impl.JBMThread;
+
+/**
+ * A QueuedWriteManagerTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class QueuedWriteManagerTest extends TestCase
+{
+ private final static int MAX_REPLICATORS = 10;
+
+ private Replicator[] replicators;
+
+ private QueuedWriteManager mgr;
+
+ private DummyChannel channel;
+
+ private int packetSequence;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ packetSequence = 0;
+
+ replicators = new Replicator[MAX_REPLICATORS];
+
+ for (int i = 0; i < replicators.length; i++)
+ {
+ replicators[i] = new DummyReplicator(i);
+ }
+
+ channel = new DummyChannel();
+
+ mgr = new QueuedWriteManager(channel);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ public void test1() throws Exception
+ {
+ queuePackets(1, 1);
+ responseReceived(1, 1);
+ checkSent(1);
+ }
+
+ public void test2() throws Exception
+ {
+ queuePackets(1, 3);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ checkSent(3);
+ }
+
+ public void test3() throws Exception
+ {
+ queuePackets(1, 3);
+ responseReceived(1, 1);
+ responseReceived(1, 2);
+ checkSent(3);
+ }
+
+ public void test4() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 2);
+ responseReceived(2, 1);
+ checkSent(4);
+ }
+
+ public void test5() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ responseReceived(1, 1);
+ responseReceived(1, 2);
+ responseReceived(2, 3);
+ checkSent(6);
+ }
+
+ public void test6() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ responseReceived(1, 1);
+ responseReceived(1, 2);
+ responseReceived(2, 1);
+ responseReceived(2, 2);
+ checkSent(6);
+ }
+
+ public void test7() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ responseReceived(1, 1);
+ responseReceived(1, 2);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ checkSent(6);
+ }
+
+ public void test8() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+ responseReceived(1, 1);
+ responseReceived(1, 2);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+ checkSent(9);
+ }
+
+ public void test9() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(1, 3);
+ responseReceived(1, 1);
+ responseReceived(1, 2);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ checkSent(9);
+ }
+
+ public void test10() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(1, 3);
+ responseReceived(1, 3);
+ responseReceived(2, 3);
+ responseReceived(1, 3);
+ checkSent(9);
+ }
+
+ public void test11() throws Exception
+ {
+ queuePackets(1, 1);
+ queuePackets(2, 1);
+ responseReceived(2, 1);
+ responseReceived(1, 1);
+ checkSent(2);
+ }
+
+ public void test12() throws Exception
+ {
+ queuePackets(1, 2);
+ queuePackets(2, 2);
+ responseReceived(2, 2);
+ responseReceived(1, 2);
+ checkSent(4);
+ }
+
+ public void test13() throws Exception
+ {
+ queuePackets(1, 2);
+ queuePackets(2, 2);
+ responseReceived(2, 1);
+ responseReceived(1, 2);
+ responseReceived(2, 1);
+ checkSent(4);
+ }
+
+ public void test14() throws Exception
+ {
+ queuePackets(1, 2);
+ queuePackets(2, 2);
+ responseReceived(2, 1);
+ responseReceived(1, 1);
+ responseReceived(2, 1);
+ responseReceived(1, 1);
+ checkSent(4);
+ }
+
+ public void test15() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+
+ checkSent(9);
+ }
+
+ public void test16() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+
+ checkSent(9);
+ }
+
+ public void test17() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+
+ checkSent(9);
+ }
+
+ public void test18() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+
+ checkSent(9);
+ }
+
+ public void test19() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+ responseReceived(3, 1);
+
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+ responseReceived(2, 1);
+
+ checkSent(9);
+ }
+
+ public void test20() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(3, 1);
+
+ checkSent(9);
+ }
+
+ public void test21() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(3, 1);
+
+ checkSent(9);
+ }
+
+ public void test22() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+
+ checkSent(9);
+ }
+
+ public void test23() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+
+ checkSent(9);
+ }
+
+ public void test24() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+
+ checkSent(9);
+ }
+
+ public void test25() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 2);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+
+ checkSent(9);
+ }
+
+ public void test26() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 2);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+
+ checkSent(9);
+ }
+
+ public void test27() throws Exception
+ {
+ queuePackets(1, 3);
+ queuePackets(2, 3);
+ queuePackets(3, 3);
+
+ responseReceived(2, 2);
+
+ responseReceived(3, 1);
+
+ responseReceived(2, 1);
+
+ responseReceived(1, 1);
+
+ responseReceived(3, 1);
+
+ responseReceived(1, 2);
+
+ responseReceived(3, 1);
+
+ checkSent(9);
+ }
+
+
+
+
+ private void responseReceived(final int repNum, int num)
+ {
+ mgr.replicationResponseReceived(replicators[repNum], num);
+ }
+
+ private void checkSent(final int num)
+ {
+ channel.assertSent(num);
+ }
+
+ private void queuePackets(int repNum, int num)
+ {
+ for (int i = 0; i < num; i++)
+ {
+ int seq = packetSequence++;
+
+ Packet packet = new MyPacket(seq);
+
+ mgr.queueWrite(replicators[repNum], packet);
+ }
+ }
+
+ public class MyPacket implements Packet
+ {
+ private final int seq;
+
+ public MyPacket(final int seq)
+ {
+ this.seq = seq;
+ }
+
+ public int getSeq()
+ {
+ return seq;
+ }
+
+ public void decode(MessagingBuffer buffer)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public int encode(MessagingBuffer buffer)
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getChannelID()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getPacketSize()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getRequiredBufferSize()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public byte getType()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public boolean isRequiresConfirmations()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isResponse()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isWriteAlways()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setChannelID(long channelID)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+ private class DummyReplicator implements Replicator
+ {
+ private int num;
+
+ DummyReplicator(int num)
+ {
+ this.num = num;
+ }
+
+ public String toString()
+ {
+ return "R" + num;
+ }
+
+ public void execute(ReplicableAction action, Runnable postReplicateAction)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void registerWaitingChannel(QueuedWriteManager manager)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void replicationResponseReceived()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+ private class DummyChannel implements Channel
+ {
+ public void close()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void confirm(Packet packet)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void flushConfirmations()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public RemotingConnection getConnection()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ChannelHandler getHandler()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public long getID()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getLastConfirmedCommandID()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Lock getLock()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void handlePacket(Packet packet)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void lock()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void replayCommands(int lastConfirmedCommandID)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void returnBlocking()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ private List<MyPacket> sent = new ArrayList<MyPacket>();
+
+ public void send(Packet packet)
+ {
+ sent.add((MyPacket)packet);
+ }
+
+ public void assertSent(final int num)
+ {
+ assertEquals(num, sent.size());
+
+ int count = 0;
+
+ for (MyPacket packet: sent)
+ {
+ assertEquals(count++, packet.getSeq());
+ }
+ }
+
+ public void sendAndFlush(Packet packet)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Packet sendBlocking(Packet packet) throws MessagingException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setCommandConfirmationHandler(CommandConfirmationHandler handler)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setHandler(ChannelHandler handler)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void transferConnection(RemotingConnection newConnection)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unlock()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+}
More information about the jboss-cvs-commits
mailing list