[jboss-cvs] JBoss Messaging SVN: r6429 - in trunk: src/main/org/jboss/messaging/core/client and 25 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 15 00:55:00 EDT 2009
Author: clebert.suconic at jboss.com
Date: 2009-04-15 00:54:59 -0400 (Wed, 15 Apr 2009)
New Revision: 6429
Added:
trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/client/
trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/
trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java
Removed:
trunk/src/main/org/jboss/messaging/core/client/ClientFileMessage.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageImpl.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageInternal.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientFileMessageTest.java
Modified:
trunk/src/main/org/jboss/messaging/core/buffers/AbstractChannelBuffer.java
trunk/src/main/org/jboss/messaging/core/client/ClientMessage.java
trunk/src/main/org/jboss/messaging/core/client/ClientSession.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java
trunk/src/main/org/jboss/messaging/core/exception/MessagingException.java
trunk/src/main/org/jboss/messaging/core/message/Message.java
trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendContinuationMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendLargeMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/spi/MessagingBuffer.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
trunk/src/main/org/jboss/messaging/integration/transports/netty/ChannelBufferWrapper.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
trunk/tests/joram-tests/src/org/jboss/test/jms/AbstractAdmin.java
trunk/tests/src/org/jboss/messaging/tests/integration/String64KLimitTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkCleanupTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCreateConsumerTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/ConsumerWindowSizeTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/DurableQueueTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageExpirationTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/client/TemporaryQueueTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/ClusterTestBase.java
trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/LargeMessageMultiThreadFailoverTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/paging/PageCrashTest.java
trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
trunk/tests/src/org/jboss/messaging/tests/soak/chunk/MessageChunkSoakTest.java
trunk/tests/src/org/jboss/messaging/tests/stress/chunk/MessageChunkStressTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeConsumer.java
Log:
LargeMessage streaming
Modified: trunk/src/main/org/jboss/messaging/core/buffers/AbstractChannelBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/buffers/AbstractChannelBuffer.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/buffers/AbstractChannelBuffer.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -29,6 +29,7 @@
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
import org.jboss.messaging.utils.DataConstants;
import org.jboss.messaging.utils.SimpleString;
import org.jboss.messaging.utils.UTF8Util;
@@ -449,6 +450,12 @@
writerIndex += length;
}
+
+ public void writeBytes(final MessagingBuffer src, final int srcIndex, final int length)
+ {
+ writeBytes((ChannelBuffer)src, srcIndex, length);
+ }
+
public void writeBytes(final ByteBuffer src)
{
int length = src.remaining();
Deleted: trunk/src/main/org/jboss/messaging/core/client/ClientFileMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientFileMessage.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientFileMessage.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -1,41 +0,0 @@
-/*
- * 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.client;
-
-import java.io.File;
-
-/**
- * A ClientFileMessage
- *
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- *
- * Created Oct 14, 2008 3:21:15 PM
- *
- *
- */
-public interface ClientFileMessage extends ClientMessage
-{
- File getFile();
-
- void setFile(File file);
-}
Modified: trunk/src/main/org/jboss/messaging/core/client/ClientMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientMessage.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientMessage.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -22,6 +22,8 @@
package org.jboss.messaging.core.client;
+import java.io.OutputStream;
+
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.message.Message;
@@ -30,6 +32,7 @@
* A ClientMessage
*
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
*
*/
public interface ClientMessage extends Message
@@ -37,6 +40,21 @@
int getDeliveryCount();
void setDeliveryCount(int deliveryCount);
+
+ /** Sets the outputStream of large messages. It doesn't block on waiting the large-message to complete
+ * @throws MessagingException */
+ void setOutputStream(OutputStream out) throws MessagingException;
+
+ /** Save the content of the message to the outputStream. It blocks until the entire data was received */
+ void saveToOutputStream(OutputStream out) throws MessagingException;
+ /**
+ * Wait the outputStream completion of the message.
+ * @param timeMilliseconds - 0 means wait forever
+ * @return true if it reached the end
+ * @throws MessagingException
+ */
+ boolean waitOutputStreamCompletion(long timeMilliseconds) throws MessagingException;
+
void acknowledge() throws MessagingException;
}
Modified: trunk/src/main/org/jboss/messaging/core/client/ClientSession.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientSession.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientSession.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -22,8 +22,6 @@
package org.jboss.messaging.core.client;
-import java.io.File;
-
import javax.transaction.xa.XAResource;
import org.jboss.messaging.core.exception.MessagingException;
@@ -90,35 +88,6 @@
ClientConsumer createConsumer(String queueName, String filterString, int windowSize, int maxRate, boolean browseOnly) throws MessagingException;
- ClientConsumer createFileConsumer(File directory, SimpleString queueName) throws MessagingException;
-
- ClientConsumer createFileConsumer(File directory, SimpleString queueName, SimpleString filterString) throws MessagingException;
-
- ClientConsumer createFileConsumer(File directory,
- SimpleString queueName,
- SimpleString filterString,
- boolean browseOnly) throws MessagingException;
-
- ClientConsumer createFileConsumer(File directory,
- SimpleString queueName,
- SimpleString filterString,
- int windowSize,
- int maxRate,
- boolean browseOnly) throws MessagingException;
-
- ClientConsumer createFileConsumer(File directory, String queueName) throws MessagingException;
-
- ClientConsumer createFileConsumer(File directory, String queueName, String filterString) throws MessagingException;
-
- ClientConsumer createFileConsumer(File directory, String queueName, String filterString, boolean browseOnly) throws MessagingException;
-
- ClientConsumer createFileConsumer(File directory,
- String queueName,
- String filterString,
- int windowSize,
- int maxRate,
- boolean browseOnly) throws MessagingException;
-
/**
* Create a producer with no default address.
* Address must be specified every time a message is sent
@@ -183,8 +152,6 @@
ClientMessage createClientMessage(final boolean durable);
- ClientFileMessage createFileMessage(final boolean durable);
-
void start() throws MessagingException;
void stop() throws MessagingException;
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -13,13 +13,9 @@
package org.jboss.messaging.core.client.impl;
import java.io.File;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
import java.util.concurrent.Executor;
import org.jboss.messaging.core.buffers.ChannelBuffers;
-import org.jboss.messaging.core.client.ClientFileMessage;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.MessageHandler;
import org.jboss.messaging.core.exception.MessagingException;
@@ -31,7 +27,6 @@
import org.jboss.messaging.core.remoting.impl.wireformat.SessionConsumerFlowCreditMessage;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveMessage;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
import org.jboss.messaging.utils.Future;
import org.jboss.messaging.utils.TokenBucketLimiter;
@@ -79,6 +74,11 @@
private ClientMessageInternal currentChunkMessage;
+ private LargeMessageBuffer currentLargeMessageBuffer;
+
+ // When receiving LargeMessages, the user may choose to not read the body, on this case we need to discard te body before moving to the next message.
+ private ClientMessageInternal largeMessageReceived;
+
private final TokenBucketLimiter rateLimiter;
private volatile Thread receiverThread;
@@ -118,7 +118,7 @@
this.channel = channel;
this.session = session;
-
+
this.rateLimiter = rateLimiter;
sessionExecutor = executor;
@@ -137,12 +137,18 @@
{
checkClosed();
+ if (largeMessageReceived != null)
+ {
+ // Check if there are pending packets to be received
+ largeMessageReceived.discardLargeBody();
+ largeMessageReceived = null;
+ }
+
if (rateLimiter != null)
{
rateLimiter.limit();
}
-
if (handler != null)
{
throw new MessagingException(MessagingException.ILLEGAL_STATE,
@@ -171,11 +177,10 @@
while (true)
{
ClientMessageInternal m = null;
-
+
synchronized (this)
{
- while ((stopped || (m = buffer.removeFirst()) == null) &&
- !closed && toWait > 0)
+ while ((stopped || (m = buffer.removeFirst()) == null) && !closed && toWait > 0)
{
if (start == -1)
@@ -190,7 +195,7 @@
catch (InterruptedException e)
{
}
-
+
if (m != null || closed)
{
break;
@@ -212,6 +217,8 @@
if (expired)
{
+ m.discardLargeBody();
+
session.expire(id, m.getMessageID());
if (toWait > 0)
@@ -224,6 +231,11 @@
}
}
+ if (m.isLargeMessage())
+ {
+ this.largeMessageReceived = m;
+ }
+
return m;
}
else
@@ -268,7 +280,7 @@
}
boolean noPreviousHandler = handler == null;
-
+
if (handler != theHandler && clientWindowSize == 0)
{
sendCredits(1);
@@ -323,14 +335,14 @@
public void stop() throws MessagingException
{
waitForOnMessageToComplete();
-
+
synchronized (this)
{
if (stopped)
{
return;
}
-
+
stopped = true;
}
}
@@ -365,18 +377,14 @@
ClientMessageInternal messageToHandle = message;
- if (isFileConsumer())
- {
- messageToHandle = cloneAsFileMessage(message);
- }
-
messageToHandle.onReceipt(this);
+ // Add it to the buffer
+ buffer.addLast(messageToHandle, messageToHandle.getPriority());
+
if (handler != null)
{
// Execute using executor
-
- buffer.addLast(messageToHandle, messageToHandle.getPriority());
if (!stopped)
{
queueExecutor();
@@ -384,9 +392,6 @@
}
else
{
- // Add it to the buffer
- buffer.addLast(messageToHandle, messageToHandle.getPriority());
-
notify();
}
}
@@ -398,11 +403,23 @@
// This is ok - we just ignore the message
return;
}
-
+
// Flow control for the first packet, we will have others
flowControl(packet.getPacketSize(), true);
- currentChunkMessage = createFileMessage(packet.getLargeMessageHeader());
+ currentChunkMessage = new ClientMessageImpl();
+
+ currentChunkMessage.decodeProperties(ChannelBuffers.wrappedBuffer(packet.getLargeMessageHeader()));
+
+ currentChunkMessage.setLargeMessage(true);
+
+ currentLargeMessageBuffer = new LargeMessageBuffer(this, packet.getLargeMessageSize(), 60);
+
+ currentChunkMessage.setBody(currentLargeMessageBuffer);
+
+ currentChunkMessage.setFlowControlSize(0);
+
+ handleMessage(currentChunkMessage);
}
public synchronized void handleLargeMessageContinuation(final SessionReceiveContinuationMessage chunk) throws Exception
@@ -411,45 +428,8 @@
{
return;
}
-
- if (chunk.isContinues())
- {
- flowControl(chunk.getPacketSize(), true);
- }
-
- if (isFileConsumer())
- {
- ClientFileMessageInternal fileMessage = (ClientFileMessageInternal)currentChunkMessage;
- addBytesBody(fileMessage, chunk.getBody());
- }
- else
- {
- if (currentChunkMessage.getBody() == null)
- {
- currentChunkMessage.setBody(ChannelBuffers.dynamicBuffer(chunk.getBody()));
- }
- else
- {
- currentChunkMessage.getBody().writeBytes(chunk.getBody());
- }
- }
-
- if (!chunk.isContinues())
- {
- // Close the file that was being generated
- if (isFileConsumer())
- {
- ((ClientFileMessageInternal)currentChunkMessage).closeChannel();
- }
-
- currentChunkMessage.setFlowControlSize(chunk.getPacketSize());
-
- ClientMessageInternal msgToSend = currentChunkMessage;
-
- currentChunkMessage = null;
-
- handleMessage(msgToSend);
- }
+
+ currentLargeMessageBuffer.addPacket(chunk);
}
public void clear()
@@ -499,40 +479,15 @@
}
}
- // Public7
- // ---------------------------------------------------------------------------------------
-
- // Package protected
- // ---------------------------------------------------------------------------------------
-
- // Protected
- // ---------------------------------------------------------------------------------------
-
- // Private
- // ---------------------------------------------------------------------------------------
-
- private void requeueExecutors()
+ public void flowControl(final int messageBytes, final boolean isLargeMessage) throws MessagingException
{
- for (int i = 0; i < buffer.size(); i++)
- {
- queueExecutor();
- }
- }
-
- private void queueExecutor()
- {
- sessionExecutor.execute(runner);
- }
-
- private void flowControl(final int messageBytes, final boolean isLargeMessage) throws MessagingException
- {
if (clientWindowSize >= 0)
{
creditsToSend += messageBytes;
-
+
if (creditsToSend >= clientWindowSize)
{
-
+
if (isLargeMessage)
{
// Flowcontrol on largeMessages continuations needs to be done in a separate thread or failover would
@@ -540,21 +495,23 @@
final int credits = creditsToSend;
creditsToSend = 0;
- sessionExecutor.execute(new Runnable()
- {
- public void run()
- {
- sendCredits(credits);
- }
+ sendCredits(credits);
- });
+ // sessionExecutor.execute(new Runnable()
+ // {
+ // public void run()
+ // {
+ // sendCredits(credits);
+ // }
+ // });
}
else
{
if (clientWindowSize == 0)
{
- // sending the credits - 1 initially send to fire the slow consumer, or the slow consumer would be always buffering one after received the first message
+ // sending the credits - 1 initially send to fire the slow consumer, or the slow consumer would be
+ // always buffering one after received the first message
sendCredits(creditsToSend - 1);
}
else
@@ -567,6 +524,31 @@
}
}
+ // Public
+ // ---------------------------------------------------------------------------------------
+
+ // Package protected
+ // ---------------------------------------------------------------------------------------
+
+ // Protected
+ // ---------------------------------------------------------------------------------------
+
+ // Private
+ // ---------------------------------------------------------------------------------------
+
+ private void requeueExecutors()
+ {
+ for (int i = 0; i < buffer.size(); i++)
+ {
+ queueExecutor();
+ }
+ }
+
+ private void queueExecutor()
+ {
+ sessionExecutor.execute(runner);
+ }
+
/**
* @param credits
*/
@@ -625,7 +607,7 @@
MessageHandler theHandler = handler;
if (theHandler != null)
- {
+ {
if (rateLimiter != null)
{
rateLimiter.limit();
@@ -647,12 +629,17 @@
onMessageThread = Thread.currentThread();
theHandler.onMessage(message);
+
+ if (message.isLargeMessage())
+ {
+ message.discardLargeBody();
+ }
}
else
{
session.expire(id, message.getMessageID());
}
-
+
// If slow consumer, we need to send 1 credit to make sure we get another message
if (clientWindowSize == 0)
{
@@ -669,7 +656,10 @@
private void flowControlBeforeConsumption(final ClientMessageInternal message) throws MessagingException
{
// Chunk messages will execute the flow control while receiving the chunks
- flowControl(message.getFlowControlSize(), false);
+ if (message.getFlowControlSize() != 0)
+ {
+ flowControl(message.getFlowControlSize(), false);
+ }
}
private void doCleanUp(final boolean sendCloseMessage) throws MessagingException
@@ -688,6 +678,13 @@
// Now we wait for any current handler runners to run.
waitForOnMessageToComplete();
+
+ if (currentLargeMessageBuffer != null)
+ {
+ currentLargeMessageBuffer.close();
+ currentLargeMessageBuffer = null;
+ }
+
closed = true;
@@ -721,16 +718,6 @@
private void clearBuffer()
{
- if (isFileConsumer())
- {
- for (ClientMessage message : buffer)
- {
- if (message instanceof ClientFileMessage)
- {
- ((ClientFileMessage)message).getFile().delete();
- }
- }
- }
buffer.clear();
}
@@ -743,89 +730,6 @@
session.acknowledge(id, message.getMessageID());
}
- private ClientMessageInternal cloneAsFileMessage(final ClientMessageInternal message) throws Exception
- {
- if (message instanceof ClientFileMessageImpl)
- {
- // nothing to be done
- return message;
- }
- else
- {
- int propertiesSize = message.getPropertiesEncodeSize();
-
- MessagingBuffer bufferProperties = session.createBuffer(propertiesSize);
-
- // FIXME: Find a better way to clone this ClientMessageImpl as ClientFileMessageImpl without using the
- // MessagingBuffer.
- // There is no direct access into the Properties, and I couldn't add a direct cast to this method without loose
- // abstraction
- message.encodeProperties(bufferProperties);
-
- bufferProperties.resetReaderIndex();
-
- ClientFileMessageImpl cloneMessage = new ClientFileMessageImpl();
-
- cloneMessage.decodeProperties(bufferProperties);
-
- cloneMessage.setDeliveryCount(message.getDeliveryCount());
-
- cloneMessage.setLargeMessage(message.isLargeMessage());
-
- cloneMessage.setFile(new File(directory, cloneMessage.getMessageID() + "-" +
- session.getName() +
- "-" +
- getID() +
- ".jbm"));
-
- cloneMessage.setFlowControlSize(message.getFlowControlSize());
-
- addBytesBody(cloneMessage, message.getBody().array());
-
- cloneMessage.closeChannel();
-
- return cloneMessage;
- }
- }
-
- private ClientMessageInternal createFileMessage(final byte[] header) throws Exception
- {
-
- MessagingBuffer headerBuffer = ChannelBuffers.wrappedBuffer(header);
-
- if (isFileConsumer())
- {
- if (!directory.exists())
- {
- boolean ok = directory.mkdirs();
-
- if (!ok)
- {
- throw new IOException("Failed to create directory " + directory.getCanonicalPath());
- }
- }
-
- ClientFileMessageImpl message = new ClientFileMessageImpl();
- message.decodeProperties(headerBuffer);
- message.setFile(new File(directory, message.getMessageID() + "-" + session.getName() + "-" + getID() + ".jbm"));
- message.setLargeMessage(true);
- return message;
- }
- else
- {
- ClientMessageImpl message = new ClientMessageImpl();
- message.decodeProperties(headerBuffer);
- message.setLargeMessage(true);
- return message;
- }
- }
-
- private void addBytesBody(final ClientFileMessageInternal fileMessage, final byte[] body) throws Exception
- {
- FileChannel channel = fileMessage.getChannel();
- channel.write(ByteBuffer.wrap(body));
- }
-
// Inner classes
// --------------------------------------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -44,6 +44,8 @@
void handleLargeMessage(SessionReceiveMessage largeMessageHeader) throws Exception;
void handleLargeMessageContinuation(SessionReceiveContinuationMessage continuation) throws Exception;
+
+ void flowControl(final int messageBytes, final boolean isLargeMessage) throws MessagingException;
void clear();
Deleted: trunk/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -1,246 +0,0 @@
-/*
- * 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.client.impl;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
-
-/**
- * A ClientFileMessageImpl
- *
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- *
- * Created Oct 13, 2008 4:33:56 PM
- *
- *
- */
-public class ClientFileMessageImpl extends ClientMessageImpl implements ClientFileMessageInternal
-{
- private File file;
-
- private FileChannel currentChannel;
-
- public ClientFileMessageImpl()
- {
- }
-
- public ClientFileMessageImpl(final boolean durable)
- {
- super(durable, null);
- }
-
- /**
- * @param type
- * @param durable
- * @param expiration
- * @param timestamp
- * @param priority
- * @param body
- */
- public ClientFileMessageImpl(final byte type,
- final boolean durable,
- final long expiration,
- final long timestamp,
- final byte priority,
- final MessagingBuffer body)
- {
- super(type, durable, expiration, timestamp, priority, body);
- }
-
- /**
- * @param type
- * @param durable
- * @param body
- */
- public ClientFileMessageImpl(final byte type, final boolean durable, final MessagingBuffer body)
- {
- super(type, durable, body);
- }
-
- /**
- * @param deliveryCount
- */
- public ClientFileMessageImpl(final int deliveryCount)
- {
- super(deliveryCount);
- }
-
- /**
- * @return the file
- */
- public File getFile()
- {
- return file;
- }
-
- /**
- * @param file the file to set
- */
- public void setFile(final File file)
- {
- this.file = file;
- }
-
- @Override
- public MessagingBuffer getBody()
- {
- throw new UnsupportedOperationException("getBody is not supported on FileMessages.");
- }
-
- /**
- * If a ClientFileMessage is Smaller then the MinLargeMessage configured on the SessionFactory (or JMSConnectionFactory), it will still be sent as any other message,
- * and for that the file body (which should be small) will be read from the file an populated on the output buffer
- *
- * */
- public void encodeBody(MessagingBuffer buffer)
- {
- FileChannel channel = null;
- try
- {
- // We open a new channel on getBody.
- // for a better performance, users should be using the channels when using file
- channel = newChannel();
-
- ByteBuffer fileBuffer = ByteBuffer.allocate((int)channel.size());
-
- channel.position(0);
- channel.read(fileBuffer);
-
- buffer.writeBytes(fileBuffer.array(), 0, fileBuffer.limit());
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- finally
- {
- try
- {
- channel.close();
- }
- catch (Throwable ignored)
- {
-
- }
- }
- }
-
- /**
- * Read the file content from start to size.
- */
- @Override
- public synchronized void encodeBody(final MessagingBuffer buffer, final long start, final int size)
- {
- try
- {
- FileChannel channel = getChannel();
-
- ByteBuffer bufferRead = ByteBuffer.allocate(size);
-
- channel.position(start);
- channel.read(bufferRead);
-
- buffer.writeBytes(bufferRead.array());
- }
- catch (Exception e)
- {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- @Override
- public void setBody(final MessagingBuffer body)
- {
- throw new RuntimeException("Not supported");
- }
-
- public synchronized FileChannel getChannel() throws MessagingException
- {
- if (currentChannel == null)
- {
- currentChannel = newChannel();
- }
-
- return currentChannel;
- }
-
- public synchronized void closeChannel() throws MessagingException
- {
- if (currentChannel != null)
- {
- try
- {
- currentChannel.close();
- }
- catch (IOException e)
- {
- throw new MessagingException(MessagingException.INTERNAL_ERROR, e.getMessage(), e);
- }
- currentChannel = null;
- }
-
- }
-
- @Override
- public synchronized int getBodySize()
- {
- return (int)file.length();
- }
-
- public boolean isFileMessage()
- {
- return true;
- }
-
-
- /**
- * @return
- * @throws FileNotFoundException
- * @throws IOException
- */
- private FileChannel newChannel() throws MessagingException
- {
- try
- {
- RandomAccessFile randomFile = new RandomAccessFile(getFile(), "rw");
-
- randomFile.seek(0);
-
- FileChannel channel = randomFile.getChannel();
-
- return channel;
- }
- catch (IOException e)
- {
- throw new MessagingException(MessagingException.INTERNAL_ERROR, e.getMessage(), e);
- }
- }
-
-}
Deleted: trunk/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageInternal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageInternal.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageInternal.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -1,47 +0,0 @@
-/*
- * 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.client.impl;
-
-import java.nio.channels.FileChannel;
-
-import org.jboss.messaging.core.client.ClientFileMessage;
-import org.jboss.messaging.core.exception.MessagingException;
-
-/**
- * A ClientFileMessageInternal
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * Created 10 Dec 2008 19:02:06
- *
- *
- */
-public interface ClientFileMessageInternal extends ClientFileMessage
-{
- void setLargeMessage(boolean largeMessage);
-
- FileChannel getChannel() throws MessagingException;
-
- void closeChannel() throws MessagingException;
-}
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -22,6 +22,9 @@
package org.jboss.messaging.core.client.impl;
+import java.io.IOException;
+import java.io.OutputStream;
+
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.message.impl.MessageImpl;
import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
@@ -138,6 +141,7 @@
{
this.largeMessage = largeMessage;
}
+
/* (non-Javadoc)
* @see org.jboss.messaging.core.client.impl.ClientMessageInternal#isFileMessage()
@@ -147,4 +151,70 @@
return false;
}
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientMessageInternal#discardLargeBody()
+ */
+ public void discardLargeBody()
+ {
+ if (largeMessage)
+ {
+ ((LargeMessageBuffer)getBody()).discardUnusedPackets();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientMessage#saveToOutputStream(java.io.OutputStream)
+ */
+ public void saveToOutputStream(OutputStream out) throws MessagingException
+ {
+ if (largeMessage)
+ {
+ ((LargeMessageBuffer)this.getBody()).saveBuffer(out);
+ }
+ else
+ {
+ try
+ {
+ out.write(this.getBody().array());
+ }
+ catch (IOException e)
+ {
+ throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY, "Error saving the message body", e);
+ }
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientMessage#setOutputStream(java.io.OutputStream)
+ */
+ public void setOutputStream(OutputStream out) throws MessagingException
+ {
+ if (largeMessage)
+ {
+ ((LargeMessageBuffer)this.getBody()).setOutputStream(out);
+ }
+ else
+ {
+ saveToOutputStream(out);
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientMessage#waitOutputStreamCompletion()
+ */
+ public boolean waitOutputStreamCompletion(long timeMilliseconds) throws MessagingException
+ {
+ if (largeMessage)
+ {
+ return ((LargeMessageBuffer)this.getBody()).waitCompletion(timeMilliseconds);
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+
}
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -45,5 +45,12 @@
boolean isLargeMessage();
- boolean isFileMessage();
+ void setLargeMessage(boolean largeMessage);
+
+ boolean isFileMessage();
+
+ /**
+ * Discard unused packets (used on large-message)
+ */
+ void discardLargeBody();
}
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -24,7 +24,11 @@
import static org.jboss.messaging.utils.SimpleString.toSimpleString;
+import java.io.IOException;
+import java.io.InputStream;
+
import org.jboss.messaging.core.buffers.ChannelBuffers;
+import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.Message;
@@ -220,8 +224,8 @@
boolean sendBlocking = msg.isDurable() ? blockOnPersistentSend : blockOnNonPersistentSend;
SessionSendMessage message = new SessionSendMessage(msg, sendBlocking);
-
- if (msg.getEncodeSize() >= minLargeMessageSize)
+
+ if (msg.getBodyInputStream() != null || msg.getEncodeSize() >= minLargeMessageSize || msg.getBody() instanceof LargeMessageBuffer)
{
sendMessageInChunks(sendBlocking, (ClientMessageInternal)msg);
}
@@ -248,55 +252,97 @@
throw new MessagingException(MessagingException.ILLEGAL_STATE,
"Header size (" + headerSize + ") is too big, use the messageBody for large data, or increase minLargeMessageSize");
}
+
+ if (msg.getBodyInputStream() == null)
+ {
+ msg.getBody().readerIndex(0);
+ }
MessagingBuffer headerBuffer = ChannelBuffers.buffer(headerSize);
msg.encodeProperties(headerBuffer);
- final int bodySize = msg.getBodySize();
+ SessionSendLargeMessage initialChunk = new SessionSendLargeMessage(headerBuffer.array());
- SessionSendLargeMessage initialChunk = new SessionSendLargeMessage(headerBuffer.array(), false);
-
channel.send(initialChunk);
- for (int pos = 0; pos < bodySize;)
+
+ if (msg.getBodyInputStream() != null)
{
- final boolean lastChunk;
-
- final int chunkLength = Math.min(bodySize - pos, minLargeMessageSize);
- final MessagingBuffer bodyBuffer = ChannelBuffers.buffer(chunkLength);
+ boolean lastChunk = false;
+ InputStream input = msg.getBodyInputStream();
+ while (!lastChunk)
+ {
+ byte[] bytesRead = new byte[minLargeMessageSize];
+ int numberOfBytesRead;
+
+ try
+ {
+ numberOfBytesRead = input.read(bytesRead);
+ }
+ catch (IOException e)
+ {
+ throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY, "Error reading the LargeMessageBody", e);
+ }
+
+ if (numberOfBytesRead < 0)
+ {
+ numberOfBytesRead = 0;
+ lastChunk = true;
+ }
+
+ final SessionSendContinuationMessage chunk = new SessionSendContinuationMessage(bytesRead, numberOfBytesRead, !lastChunk, lastChunk && sendBlocking);
- msg.encodeBody(bodyBuffer, pos, chunkLength);
-
- pos += chunkLength;
+ if (sendBlocking && lastChunk)
+ {
+ // When sending it blocking, only the last chunk will be blocking.
+ channel.sendBlocking(chunk);
+ }
+ else
+ {
+ channel.send(chunk);
+ }
+ }
- lastChunk = pos >= bodySize;
-
- final SessionSendContinuationMessage chunk = new SessionSendContinuationMessage(bodyBuffer.array(), !lastChunk, lastChunk && sendBlocking);
-
- if (sendBlocking && lastChunk)
+ try
{
- // When sending it blocking, only the last chunk will be blocking.
- channel.sendBlocking(chunk);
+ input.close();
}
- else
+ catch (IOException e)
{
- channel.send(chunk);
- }
+ throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY, "Error closing stream from LargeMessageBody", e);
+ }
}
-
- // Note: This could be either a regular message, with a huge body,
- // or a ClientFileMessage.
- if (msg.isFileMessage())
+ else
{
- try
+ final int bodySize = msg.getBodySize();
+
+ for (int pos = 0; pos < bodySize;)
{
- ((ClientFileMessageInternal)msg).closeChannel();
+ final boolean lastChunk;
+
+ final int chunkLength = Math.min(bodySize - pos, minLargeMessageSize);
+
+ final MessagingBuffer bodyBuffer = ChannelBuffers.buffer(chunkLength);
+
+ msg.encodeBody(bodyBuffer, pos, chunkLength);
+
+ pos += chunkLength;
+
+ lastChunk = pos >= bodySize;
+
+ final SessionSendContinuationMessage chunk = new SessionSendContinuationMessage(bodyBuffer.array(), chunkLength, !lastChunk, lastChunk && sendBlocking);
+
+ if (sendBlocking && lastChunk)
+ {
+ // When sending it blocking, only the last chunk will be blocking.
+ channel.sendBlocking(chunk);
+ }
+ else
+ {
+ channel.send(chunk);
+ }
}
- catch (Exception e)
- {
- log.warn(e.getMessage(), e);
- }
}
}
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -38,7 +38,6 @@
import org.jboss.messaging.core.buffers.ChannelBuffers;
import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.SendAcknowledgementHandler;
@@ -369,77 +368,6 @@
return createConsumer(toSimpleString(queueName), toSimpleString(filterString), windowSize, maxRate, browseOnly);
}
- public ClientConsumer createFileConsumer(final File directory, final SimpleString queueName) throws MessagingException
- {
- return createFileConsumer(directory, queueName, null, false);
- }
-
- public ClientConsumer createFileConsumer(final File directory, final String queueName) throws MessagingException
- {
- return createFileConsumer(directory, toSimpleString(queueName));
- }
-
- public ClientConsumer createFileConsumer(final File directory,
- final SimpleString queueName,
- final SimpleString filterString) throws MessagingException
- {
- return createFileConsumer(directory, queueName, filterString, consumerWindowSize, consumerMaxRate, false);
- }
-
- public ClientConsumer createFileConsumer(final File directory, final String queueName, final String filterString) throws MessagingException
- {
- return createFileConsumer(directory, toSimpleString(queueName), toSimpleString(filterString));
- }
-
- public ClientConsumer createFileConsumer(final File directory,
- final SimpleString queueName,
- final SimpleString filterString,
- final boolean browseOnly) throws MessagingException
- {
- return createFileConsumer(directory, queueName, filterString, consumerWindowSize, consumerMaxRate, browseOnly);
- }
-
- public ClientConsumer createFileConsumer(final File directory,
- final String queueName,
- final String filterString,
- final boolean browseOnly) throws MessagingException
- {
- return createFileConsumer(directory, toSimpleString(queueName), toSimpleString(filterString), browseOnly);
- }
-
- /*
- * Note, we DO NOT currently support direct consumers (i.e. consumers we're delivery occurs on the remoting thread.
- * Direct consumers have issues with blocking and failover.
- * E.g. if direct then inside MessageHandler call a blocking method like rollback or acknowledge (blocking)
- * This can block until failove completes, which disallows the thread to be used to deliver any responses to the client
- * during that period, so failover won't occur.
- * If we want direct consumers we need to rethink how they work
- */
- public ClientConsumer createFileConsumer(final File directory,
- final SimpleString queueName,
- final SimpleString filterString,
- final int windowSize,
- final int maxRate,
- final boolean browseOnly) throws MessagingException
- {
- return internalCreateConsumer(queueName, filterString, windowSize, maxRate, browseOnly, directory);
- }
-
- public ClientConsumer createFileConsumer(final File directory,
- final String queueName,
- final String filterString,
- final int windowSize,
- final int maxRate,
- final boolean browseOnly) throws MessagingException
- {
- return createFileConsumer(directory,
- toSimpleString(queueName),
- toSimpleString(filterString),
- windowSize,
- maxRate,
- browseOnly);
- }
-
public ClientProducer createProducer() throws MessagingException
{
return createProducer((SimpleString)null);
@@ -566,11 +494,6 @@
return ChannelBuffers.dynamicBuffer(size);
}
- public ClientFileMessage createFileMessage(final boolean durable)
- {
- return new ClientFileMessageImpl(durable);
- }
-
public boolean isClosed()
{
return closed;
@@ -1295,7 +1218,7 @@
final boolean temp) throws MessagingException
{
checkClosed();
-
+
if (durable && temp)
{
throw new MessagingException(MessagingException.INTERNAL_ERROR, "Queue can not be both durable and temporay");
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -110,10 +110,26 @@
private final Object failoverLock = new Object();
- // TODO - allow this to be configurable
- private static final ScheduledThreadPoolExecutor pingExecutor = new ScheduledThreadPoolExecutor(5,
- new org.jboss.messaging.utils.JBMThreadFactory("jbm-pinger-threads"));
+ private static ScheduledThreadPoolExecutor pingExecutor;
+ static
+ {
+ recreatePingExecutor();
+ }
+
+ public static void recreatePingExecutor()
+ {
+ if (pingExecutor != null)
+ {
+ pingExecutor.shutdown();
+ }
+
+ // TODO - allow this to be configurable
+ pingExecutor = new ScheduledThreadPoolExecutor(5,
+ new org.jboss.messaging.utils.JBMThreadFactory("jbm-pinger-threads"));
+
+ }
+
private final Map<Object, ConnectionEntry> connections = Collections.synchronizedMap(new LinkedHashMap<Object, ConnectionEntry>());
private int refCount;
@@ -165,7 +181,7 @@
final long retryInterval,
final double retryIntervalMultiplier,
final int reconnectAttempts)
- {
+ {
this.connectorConfig = connectorConfig;
this.backupConfig = backupConfig;
@@ -259,17 +275,17 @@
synchronized (failoverLock)
{
connection = getConnectionWithRetry(1, reconnectAttempts);
-
+
if (connection == null)
- {
+ {
if (!failureSignalled)
{
// This can happen if the connection manager gets closed - e.g. the server gets shut down
-
+
throw new MessagingException(MessagingException.NOT_CONNECTED, "Unable to connect to server");
}
else
- {
+ {
// This means an async failure came in while getConnectionForCreateSession was executing, we
// need
// to allow the failover/reconnection to occur and let the create session retry after
@@ -465,7 +481,7 @@
{
return false;
}
-
+
if (connectionID != null && !connections.containsKey(connectionID))
{
// We already failed over/reconnected - probably the first failure came in, all the connections were failed
@@ -508,9 +524,9 @@
// It should then return its connections, with channel 1 lock still held
// It can then release the channel 1 lock, and retry (which will cause locking on failoverLock
// until failover is complete
-
+
boolean attemptFailover = (backupConnectorFactory) != null && (failoverOnServerShutdown || me.getCode() != MessagingException.SERVER_DISCONNECTED);
-
+
boolean done = false;
if (attemptFailover || reconnectAttempts != 0)
@@ -571,7 +587,7 @@
if (attemptFailover)
{
// Now try failing over to backup
-
+
connectorFactory = backupConnectorFactory;
transportParams = backupTransportParams;
@@ -579,11 +595,11 @@
backupConnectorFactory = null;
backupTransportParams = null;
-
+
done = reattachSessions(reconnectAttempts == -1 ? -1 : reconnectAttempts + 1);
}
else if (reconnectAttempts != 0)
- {
+ {
done = reattachSessions(reconnectAttempts);
}
@@ -709,7 +725,7 @@
long interval = retryInterval;
int count = 0;
-
+
while (true)
{
if (closed || failureSignalled)
@@ -718,7 +734,7 @@
}
RemotingConnection connection = getConnection(initialRefCount);
-
+
if (connection == null)
{
// Failed to get connection
@@ -733,7 +749,7 @@
return null;
}
-
+
try
{
Thread.sleep(interval);
@@ -765,12 +781,12 @@
Set<ConnectionEntry> copy = new HashSet<ConnectionEntry>(connections.values());
- connections.clear();
+ connections.clear();
for (ConnectionEntry entry : copy)
{
try
- {
+ {
entry.connection.destroy();
}
catch (Throwable ignore)
@@ -908,7 +924,7 @@
{
refCount--;
}
-
+
if (entry != null)
{
checkCloseConnections();
@@ -981,19 +997,19 @@
channel1.returnBlocking();
}
}
-
+
private void failConnection(final Object connectionID, final MessagingException me)
{
ConnectionEntry entry = connections.get(connectionID);
-
+
if (entry != null)
{
RemotingConnection conn = entry.connection;
-
+
conn.fail(me);
- }
+ }
}
-
+
private static class ConnectionEntry
{
ConnectionEntry(final RemotingConnection connection, final Connector connector)
Added: trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -0,0 +1,1064 @@
+/*
+ * 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.client.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.GatheringByteChannel;
+import java.nio.channels.ScatteringByteChannel;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.messaging.core.buffers.ChannelBuffer;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.utils.DataConstants;
+import org.jboss.messaging.utils.SimpleString;
+import org.jboss.messaging.utils.UTF8Util;
+
+/**
+ * This class aggregates several SessionReceiveContinuationMessages as it was being handled by a single buffer.
+ * This buffer can be consumed as messages are arriving, and it will hold the packets until they are read using the ChannelBuffer interface, or the setOutputStream or saveStream are called.
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class LargeMessageBuffer implements ChannelBuffer
+{
+ // Constants -----------------------------------------------------
+
+ private final String READ_ONLY_ERROR_MESSAGE = "This is a read-only buffer, setOperations are not supported";
+
+ // Attributes ----------------------------------------------------
+
+ private final ClientConsumerInternal consumerInternal;
+
+ private final LinkedBlockingQueue<SessionReceiveContinuationMessage> packets = new LinkedBlockingQueue<SessionReceiveContinuationMessage>();
+
+ private SessionReceiveContinuationMessage currentPacket = null;
+
+ private final int totalSize;
+
+ private boolean streamEnded = false;
+
+ private final int readTimeout;
+
+ private int readerIndex = 0;
+
+ private int packetPosition = -1;
+
+ private int lastIndex = 0;
+
+ private int packetLastPosition = -1;
+
+ private OutputStream outStream;
+
+ private Exception handledException;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public LargeMessageBuffer(final ClientConsumerInternal consumerInternal, final int totalSize, final int readTimeout)
+ {
+ this.consumerInternal = consumerInternal;
+ this.readTimeout = readTimeout;
+ this.totalSize = totalSize;
+ }
+
+ // Public --------------------------------------------------------
+
+ public synchronized Exception getHandledException()
+ {
+ return handledException;
+ }
+
+ /**
+ *
+ */
+ public void discardUnusedPackets()
+ {
+ if (outStream == null)
+ {
+ try
+ {
+ checkForPacket(this.totalSize - 1);
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+ }
+
+ /**
+ * Add a buff to the List, or save it to the OutputStream if set
+ * @param packet
+ */
+ public synchronized void addPacket(final SessionReceiveContinuationMessage packet)
+ {
+ if (outStream != null)
+ {
+ try
+ {
+ if (!packet.isContinues())
+ {
+ streamEnded = true;
+ }
+
+ outStream.write(packet.getBody());
+
+ consumerInternal.flowControl(packet.getPacketSize(), true);
+
+ if (streamEnded)
+ {
+ outStream.close();
+ }
+
+ notifyAll();
+ }
+ catch (Exception e)
+ {
+ handledException = e;
+
+ }
+ }
+ else
+ {
+ packets.offer(packet);
+ }
+ }
+
+ public synchronized void close()
+ {
+ this.packets.offer(new SessionReceiveContinuationMessage());
+ this.streamEnded = true;
+ notifyAll();
+ }
+
+ public synchronized void setOutputStream(final OutputStream output) throws MessagingException
+ {
+ while (true)
+ {
+ SessionReceiveContinuationMessage packet = this.packets.poll();
+ if (packet == null)
+ {
+ break;
+ }
+ try
+ {
+ output.write(packet.getBody());
+ }
+ catch (IOException e)
+ {
+ throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
+ "Error writing body of message",
+ e);
+ }
+ }
+
+ this.outStream = output;
+ }
+
+ public synchronized void saveBuffer(final OutputStream output) throws MessagingException
+ {
+ setOutputStream(output);
+ waitCompletion(0);
+ }
+
+ /**
+ *
+ * @param timeWait Milliseconds to Wait. 0 means forever
+ * @throws Exception
+ */
+ public synchronized boolean waitCompletion(long timeWait) throws MessagingException
+ {
+
+ if (outStream == null)
+ {
+ // There is no stream.. it will never achieve the end of streaming
+ return false;
+ }
+
+ long timeOut = System.currentTimeMillis() + timeWait;
+ while (!streamEnded && handledException == null)
+ {
+ try
+ {
+ this.wait(readTimeout == 0 ? 1 : (readTimeout * 1000));
+ }
+ catch (InterruptedException e)
+ {
+ throw new MessagingException(MessagingException.INTERNAL_ERROR, e.getMessage(), e);
+ }
+
+ if (timeWait > 0 && System.currentTimeMillis() > timeOut)
+ {
+ throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
+ "Timeout waiting for LargeMessage Body");
+ }
+ }
+
+ if (this.handledException != null)
+ {
+ throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
+ "Error on saving LargeMessageBuffer",
+ this.handledException);
+ }
+
+ return this.streamEnded;
+
+ }
+
+ // Channel Buffer Implementation ---------------------------------
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#array()
+ */
+ public byte[] array()
+ {
+ throw new IllegalAccessError("array not supported on LargeMessageBuffer");
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#capacity()
+ */
+ public int capacity()
+ {
+ return -1;
+ }
+
+ public byte readByte()
+ {
+ return getByte(readerIndex++);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getByte(int)
+ */
+ public byte getByte(final int index)
+ {
+ checkForPacket(index);
+ return currentPacket.getBody()[index - packetPosition];
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, org.jboss.messaging.core.buffers.ChannelBuffer, int, int)
+ */
+ public void getBytes(final int index, final ChannelBuffer dst, final int dstIndex, final int length)
+ {
+ byte[] destBytes = new byte[length];
+ getBytes(index, destBytes);
+ dst.setBytes(dstIndex, destBytes);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, byte[], int, int)
+ */
+ public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
+ {
+ byte bytesToGet[] = new byte[length];
+
+ getBytes(index, bytesToGet);
+
+ System.arraycopy(bytesToGet, 0, dst, dstIndex, length);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.nio.ByteBuffer)
+ */
+ public void getBytes(final int index, final ByteBuffer dst)
+ {
+ byte bytesToGet[] = new byte[dst.remaining()];
+ getBytes(index, bytesToGet);
+ dst.put(bytesToGet);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.io.OutputStream, int)
+ */
+ public void getBytes(final int index, final OutputStream out, final int length) throws IOException
+ {
+ byte bytesToGet[] = new byte[length];
+ getBytes(index, bytesToGet);
+ out.write(bytesToGet);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.nio.channels.GatheringByteChannel, int)
+ */
+ public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
+ {
+ byte bytesToGet[] = new byte[length];
+ getBytes(index, bytesToGet);
+ return out.write(ByteBuffer.wrap(bytesToGet));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getInt(int)
+ */
+ public int getInt(final int index)
+ {
+ return (getByte(index) & 0xff) << 24 | (getByte(index + 1) & 0xff) << 16 |
+ (getByte(index + 2) & 0xff) << 8 |
+ (getByte(index + 3) & 0xff) << 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getLong(int)
+ */
+ public long getLong(final int index)
+ {
+ return ((long)getByte(index) & 0xff) << 56 | ((long)getByte(index + 1) & 0xff) << 48 |
+ ((long)getByte(index + 2) & 0xff) << 40 |
+ ((long)getByte(index + 3) & 0xff) << 32 |
+ ((long)getByte(index + 4) & 0xff) << 24 |
+ ((long)getByte(index + 5) & 0xff) << 16 |
+ ((long)getByte(index + 6) & 0xff) << 8 |
+ ((long)getByte(index + 7) & 0xff) << 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getShort(int)
+ */
+ public short getShort(final int index)
+ {
+ return (short)(getByte(index) << 8 | getByte(index + 1) & 0xFF);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#getUnsignedMedium(int)
+ */
+ public int getUnsignedMedium(final int index)
+ {
+ return (getByte(index) & 0xff) << 16 | (getByte(index + 1) & 0xff) << 8 | (getByte(index + 2) & 0xff) << 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setByte(int, byte)
+ */
+ public void setByte(final int index, final byte value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, org.jboss.messaging.core.buffers.ChannelBuffer, int, int)
+ */
+ public void setBytes(final int index, final ChannelBuffer src, final int srcIndex, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, byte[], int, int)
+ */
+ public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.nio.ByteBuffer)
+ */
+ public void setBytes(final int index, final ByteBuffer src)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.io.InputStream, int)
+ */
+ public int setBytes(final int index, final InputStream in, final int length) throws IOException
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.nio.channels.ScatteringByteChannel, int)
+ */
+ public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setInt(int, int)
+ */
+ public void setInt(final int index, final int value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setLong(int, long)
+ */
+ public void setLong(final int index, final long value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setMedium(int, int)
+ */
+ public void setMedium(final int index, final int value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#setShort(int, short)
+ */
+ public void setShort(final int index, final short value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#toByteBuffer(int, int)
+ */
+ public ByteBuffer toByteBuffer(final int index, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#toString(int, int, java.lang.String)
+ */
+ public String toString(final int index, final int length, final String charsetName)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public int readerIndex()
+ {
+ return readerIndex;
+ }
+
+ public void readerIndex(final int readerIndex)
+ {
+ checkForPacket(readerIndex);
+ this.readerIndex = readerIndex;
+ }
+
+ public int writerIndex()
+ {
+ return totalSize;
+ }
+
+ public void writerIndex(final int writerIndex)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void setIndex(final int readerIndex, final int writerIndex)
+ {
+ checkForPacket(readerIndex);
+ this.readerIndex = readerIndex;
+ }
+
+ public void clear()
+ {
+ }
+
+ public boolean readable()
+ {
+ return true;
+ }
+
+ public boolean writable()
+ {
+ return false;
+ }
+
+ public int readableBytes()
+ {
+ return this.totalSize - this.readerIndex;
+ }
+
+ public int writableBytes()
+ {
+ return 0;
+ }
+
+ public void markReaderIndex()
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void resetReaderIndex()
+ {
+ checkForPacket(0);
+ }
+
+ public void markWriterIndex()
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void resetWriterIndex()
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void discardReadBytes()
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public short getUnsignedByte(final int index)
+ {
+ return (short)(getByte(index) & 0xFF);
+ }
+
+ public int getUnsignedShort(final int index)
+ {
+ return getShort(index) & 0xFFFF;
+ }
+
+ public int getMedium(final int index)
+ {
+ int value = getUnsignedMedium(index);
+ if ((value & 0x800000) != 0)
+ {
+ value |= 0xff000000;
+ }
+ return value;
+ }
+
+ public long getUnsignedInt(final int index)
+ {
+ return getInt(index) & 0xFFFFFFFFL;
+ }
+
+ public void getBytes(int index, final byte[] dst)
+ {
+ // TODO: optimize this by using System.arraycopy
+ for (int i = 0; i < dst.length; i++)
+ {
+ dst[i] = getByte(index++);
+ }
+ }
+
+ public void getBytes(final int index, final ChannelBuffer dst)
+ {
+ getBytes(index, dst, dst.writableBytes());
+ }
+
+ public void getBytes(final int index, final ChannelBuffer dst, final int length)
+ {
+ if (length > dst.writableBytes())
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ getBytes(index, dst, dst.writerIndex(), length);
+ dst.writerIndex(dst.writerIndex() + length);
+ }
+
+ public void setBytes(final int index, final byte[] src)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void setBytes(final int index, final ChannelBuffer src)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void setBytes(final int index, final ChannelBuffer src, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void setZero(final int index, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public short readUnsignedByte()
+ {
+ return (short)(readByte() & 0xFF);
+ }
+
+ public short readShort()
+ {
+ short v = getShort(readerIndex);
+ readerIndex += 2;
+ return v;
+ }
+
+ public int readUnsignedShort()
+ {
+ return readShort() & 0xFFFF;
+ }
+
+ public int readMedium()
+ {
+ int value = readUnsignedMedium();
+ if ((value & 0x800000) != 0)
+ {
+ value |= 0xff000000;
+ }
+ return value;
+ }
+
+ public int readUnsignedMedium()
+ {
+ int v = getUnsignedMedium(readerIndex);
+ readerIndex += 3;
+ return v;
+ }
+
+ public int readInt()
+ {
+ int v = getInt(readerIndex);
+ readerIndex += 4;
+ return v;
+ }
+
+ public long readUnsignedInt()
+ {
+ return readInt() & 0xFFFFFFFFL;
+ }
+
+ public long readLong()
+ {
+ long v = getLong(readerIndex);
+ readerIndex += 8;
+ return v;
+ }
+
+ public void readBytes(final byte[] dst, final int dstIndex, final int length)
+ {
+ getBytes(readerIndex, dst, dstIndex, length);
+ readerIndex += length;
+ }
+
+ public void readBytes(final byte[] dst)
+ {
+ readBytes(dst, 0, dst.length);
+ }
+
+ public void readBytes(final ChannelBuffer dst)
+ {
+ readBytes(dst, dst.writableBytes());
+ }
+
+ public void readBytes(final ChannelBuffer dst, final int length)
+ {
+ if (length > dst.writableBytes())
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ readBytes(dst, dst.writerIndex(), length);
+ dst.writerIndex(dst.writerIndex() + length);
+ }
+
+ public void readBytes(final ChannelBuffer dst, final int dstIndex, final int length)
+ {
+ getBytes(readerIndex, dst, dstIndex, length);
+ readerIndex += length;
+ }
+
+ public void readBytes(final ByteBuffer dst)
+ {
+ int length = dst.remaining();
+ getBytes(readerIndex, dst);
+ readerIndex += length;
+ }
+
+ public int readBytes(final GatheringByteChannel out, final int length) throws IOException
+ {
+ int readBytes = getBytes(readerIndex, out, length);
+ readerIndex += readBytes;
+ return readBytes;
+ }
+
+ public void readBytes(final OutputStream out, final int length) throws IOException
+ {
+ getBytes(readerIndex, out, length);
+ readerIndex += length;
+ }
+
+ public void skipBytes(final int length)
+ {
+
+ int newReaderIndex = readerIndex + length;
+ checkForPacket(newReaderIndex);
+ readerIndex = newReaderIndex;
+ }
+
+ public void writeByte(final byte value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeShort(final short value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeMedium(final int value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeInt(final int value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeLong(final long value)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeBytes(final byte[] src, final int srcIndex, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeBytes(final byte[] src)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeBytes(final ChannelBuffer src)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeBytes(final ChannelBuffer src, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeBytes(MessagingBuffer src, int srcIndex, int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeBytes(final ChannelBuffer src, final int srcIndex, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeBytes(final ByteBuffer src)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeBytes(final InputStream in, final int length) throws IOException
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public int writeBytes(final ScatteringByteChannel in, final int length) throws IOException
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public void writeZero(final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public ByteBuffer toByteBuffer()
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public ByteBuffer[] toByteBuffers()
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public ByteBuffer[] toByteBuffers(final int index, final int length)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public String toString(final String charsetName)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ public Object getUnderlyingBuffer()
+ {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readBoolean()
+ */
+ public boolean readBoolean()
+ {
+ return readByte() != 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readChar()
+ */
+ public char readChar()
+ {
+ return (char)readShort();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readDouble()
+ */
+ public double readDouble()
+ {
+ return Double.longBitsToDouble(readLong());
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readFloat()
+ */
+ public float readFloat()
+ {
+ return Float.intBitsToFloat(readInt());
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readNullableSimpleString()
+ */
+ public SimpleString readNullableSimpleString()
+ {
+ int b = readByte();
+ if (b == DataConstants.NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return readSimpleString();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readNullableString()
+ */
+ public String readNullableString()
+ {
+ int b = readByte();
+ if (b == DataConstants.NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return readString();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readSimpleString()
+ */
+ public SimpleString readSimpleString()
+ {
+ int len = readInt();
+ byte[] data = new byte[len];
+ readBytes(data);
+ return new SimpleString(data);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readString()
+ */
+ public String readString()
+ {
+ int len = readInt();
+ char[] chars = new char[len];
+ for (int i = 0; i < len; i++)
+ {
+ chars[i] = readChar();
+ }
+ return new String(chars);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readUTF()
+ */
+ public String readUTF() throws Exception
+ {
+ return UTF8Util.readUTF(this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeBoolean(boolean)
+ */
+ public void writeBoolean(final boolean val)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeChar(char)
+ */
+ public void writeChar(final char val)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeDouble(double)
+ */
+ public void writeDouble(final double val)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeFloat(float)
+ */
+ public void writeFloat(final float val)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeNullableSimpleString(org.jboss.messaging.util.SimpleString)
+ */
+ public void writeNullableSimpleString(final SimpleString val)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeNullableString(java.lang.String)
+ */
+ public void writeNullableString(final String val)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeSimpleString(org.jboss.messaging.util.SimpleString)
+ */
+ public void writeSimpleString(final SimpleString val)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeString(java.lang.String)
+ */
+ public void writeString(final String val)
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeUTF(java.lang.String)
+ */
+ public void writeUTF(final String utf) throws Exception
+ {
+ throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.buffers.ChannelBuffer#compareTo(org.jboss.messaging.core.buffers.ChannelBuffer)
+ */
+ public int compareTo(final ChannelBuffer buffer)
+ {
+ return -1;
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private void popPacket()
+ {
+ try
+ {
+
+ if (streamEnded)
+ {
+ // no more packets, we are over the last one already
+ throw new IndexOutOfBoundsException();
+ }
+
+ int sizeToAdd = currentPacket != null ? currentPacket.getBody().length : 1;
+ currentPacket = packets.poll(readTimeout, TimeUnit.SECONDS);
+ if (currentPacket == null)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (currentPacket.getBody() == null) // Empty packet as a signal to interruption
+ {
+ currentPacket = null;
+ streamEnded = true;
+ throw new IndexOutOfBoundsException();
+ }
+
+ consumerInternal.flowControl(currentPacket.getPacketSize(), true);
+
+ packetPosition += sizeToAdd;
+
+ packetLastPosition = packetPosition + currentPacket.getBody().length;
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void checkForPacket(final int index)
+ {
+ if (this.outStream != null)
+ {
+ throw new IllegalAccessError("Can't read the messageBody after setting outputStream");
+ }
+ if (index >= totalSize)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ if (index < lastIndex)
+ {
+ throw new IllegalAccessError("LargeMessage have read-only and one-way buffers");
+ }
+ lastIndex = index;
+
+ while (index >= packetLastPosition && !streamEnded)
+ {
+ popPacket();
+ }
+ }
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: trunk/src/main/org/jboss/messaging/core/exception/MessagingException.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/exception/MessagingException.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/exception/MessagingException.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -66,6 +66,8 @@
public static final int INCOMPATIBLE_CLIENT_SERVER_VERSIONS = 108;
public static final int SESSION_EXISTS = 109;
+
+ public static final int LARGE_MESSAGE_ERROR_BODY = 110;
// Native Error codes ----------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/message/Message.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/Message.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/message/Message.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -22,6 +22,7 @@
package org.jboss.messaging.core.message;
+import java.io.InputStream;
import java.util.Set;
import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
@@ -86,6 +87,13 @@
// Used on Message chunk
void encodeBody(MessagingBuffer buffer, long start, int size);
+ /** Used to set the MessageBody out of a File or any other Streaming you choose */
+ void setBodyInputStream(InputStream stream);
+
+ /** Used to set the MessageBody out of a File or any other Streaming you choose */
+ InputStream getBodyInputStream();
+
+
void encodeBody(MessagingBuffer buffer);
void decodeBody(MessagingBuffer buffer);
Modified: trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -27,6 +27,7 @@
import static org.jboss.messaging.utils.DataConstants.SIZE_INT;
import static org.jboss.messaging.utils.DataConstants.SIZE_LONG;
+import java.io.InputStream;
import java.util.Set;
import org.jboss.messaging.core.buffers.ChannelBuffers;
@@ -96,6 +97,10 @@
private byte priority;
private MessagingBuffer body;
+
+ /** Used on LargeMessages */
+ private InputStream bodyInputStream;
+
// Constructors --------------------------------------------------
@@ -221,7 +226,7 @@
// Used on Message chunk
public void encodeBody(MessagingBuffer buffer, long start, int size)
{
- buffer.writeBytes(body.array(), (int)start, size);
+ buffer.writeBytes(body, (int)start, size);
}
public void decode(final MessagingBuffer buffer)
@@ -323,6 +328,24 @@
return System.currentTimeMillis() - expiration >= 0;
}
+ /**
+ * @return the bodyInputStream
+ */
+ public InputStream getBodyInputStream()
+ {
+ return bodyInputStream;
+ }
+
+ /**
+ * @param bodyInputStream the bodyInputStream to set
+ */
+ public void setBodyInputStream(InputStream bodyInputStream)
+ {
+ this.bodyInputStream = bodyInputStream;
+ }
+
+
+
// Properties
// ---------------------------------------------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -42,6 +42,7 @@
public static final int SESSION_RECEIVE_MESSAGE_LARGE_MESSAGE_SIZE = BASIC_PACKET_SIZE + DataConstants.SIZE_LONG +
DataConstants.SIZE_INT +
+ DataConstants.SIZE_INT +
DataConstants.SIZE_BOOLEAN +
DataConstants.SIZE_INT;
@@ -60,12 +61,15 @@
private ServerMessage serverMessage;
private int deliveryCount;
+
+ /** Since we receive the message before the entire message was received, */
+ private int largeMessageSize;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- public SessionReceiveMessage(final long consumerID, final byte[] largeMessageHeader, final int deliveryCount)
+ public SessionReceiveMessage(final long consumerID, final byte[] largeMessageHeader, final int largeMessageSize, final int deliveryCount)
{
super(SESS_RECEIVE_MSG);
@@ -76,6 +80,8 @@
this.deliveryCount = deliveryCount;
this.largeMessage = true;
+
+ this.largeMessageSize = largeMessageSize;
}
public SessionReceiveMessage(final long consumerID, final ServerMessage message, final int deliveryCount)
@@ -133,6 +139,14 @@
return deliveryCount;
}
+ /**
+ * @return the largeMessageSize
+ */
+ public int getLargeMessageSize()
+ {
+ return largeMessageSize;
+ }
+
public int getRequiredBufferSize()
{
if (largeMessage)
@@ -154,6 +168,7 @@
buffer.writeBoolean(largeMessage);
if (largeMessage)
{
+ buffer.writeInt(largeMessageSize);
buffer.writeInt(largeMessageHeader.length);
buffer.writeBytes(largeMessageHeader);
}
@@ -175,6 +190,7 @@
if (largeMessage)
{
+ largeMessageSize = buffer.readInt();
int size = buffer.readInt();
largeMessageHeader = new byte[size];
buffer.readBytes(largeMessageHeader);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendContinuationMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendContinuationMessage.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendContinuationMessage.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -44,6 +44,9 @@
private boolean requiresResponse;
+ // Not sent through the wire. Just to define how many bytes to send of body
+ private transient int bodyLength;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -63,11 +66,13 @@
* @param requiresResponse
*/
public SessionSendContinuationMessage(final byte[] body,
+ final int bodyLength,
final boolean continues,
final boolean requiresResponse)
{
super(SESS_SEND_CONTINUATION, body, continues);
this.requiresResponse = requiresResponse;
+ this.bodyLength = bodyLength;
}
@@ -84,20 +89,25 @@
@Override
public int getRequiredBufferSize()
{
- return super.getRequiredBufferSize() + DataConstants.SIZE_BOOLEAN;
+ return SESSION_CONTINUATION_BASE_SIZE + bodyLength + DataConstants.SIZE_BOOLEAN;
}
@Override
public void encodeBody(final MessagingBuffer buffer)
{
- super.encodeBody(buffer);
+ buffer.writeInt(bodyLength);
+ buffer.writeBytes(body, 0, bodyLength);
+ buffer.writeBoolean(continues);
buffer.writeBoolean(requiresResponse);
}
@Override
public void decodeBody(final MessagingBuffer buffer)
{
- super.decodeBody(buffer);
+ bodyLength = buffer.readInt();
+ body = new byte[bodyLength];
+ buffer.readBytes(body);
+ continues = buffer.readBoolean();
requiresResponse = buffer.readBoolean();
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendLargeMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendLargeMessage.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendLargeMessage.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -44,19 +44,15 @@
/** We need to set the MessageID when replicating this on the server */
private long largeMessageId = -1;
- private boolean requiresResponse;
-
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- public SessionSendLargeMessage(final byte[] largeMessageHeader, final boolean requiresResponse)
+ public SessionSendLargeMessage(final byte[] largeMessageHeader)
{
super(SESS_SEND_LARGE);
this.largeMessageHeader = largeMessageHeader;
-
- this.requiresResponse = requiresResponse;
}
public SessionSendLargeMessage()
@@ -71,11 +67,6 @@
return largeMessageHeader;
}
- public boolean isRequiresResponse()
- {
- return requiresResponse;
- }
-
/**
* @return the largeMessageId
*/
@@ -98,7 +89,6 @@
buffer.writeInt(largeMessageHeader.length);
buffer.writeBytes(largeMessageHeader);
buffer.writeLong(largeMessageId);
- buffer.writeBoolean(requiresResponse);
}
@Override
@@ -111,16 +101,13 @@
buffer.readBytes(largeMessageHeader);
largeMessageId = buffer.readLong();
-
- requiresResponse = buffer.readBoolean();
}
public int getRequiredBufferSize()
{
int size = BASIC_PACKET_SIZE + DataConstants.SIZE_INT +
largeMessageHeader.length +
- DataConstants.SIZE_LONG +
- DataConstants.SIZE_BOOLEAN;
+ DataConstants.SIZE_LONG;
return size;
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/spi/MessagingBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/spi/MessagingBuffer.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/remoting/spi/MessagingBuffer.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -22,6 +22,7 @@
package org.jboss.messaging.core.remoting.spi;
+import org.jboss.messaging.core.buffers.ChannelBuffer;
import org.jboss.messaging.utils.SimpleString;
/**
@@ -38,6 +39,8 @@
void writeBytes(byte[] bytes);
void writeBytes(byte[] bytes, int offset, int length);
+
+ void writeBytes(MessagingBuffer src, int srcIndex, int length);
void writeInt(int val);
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -137,13 +137,13 @@
private final ManagementService managementService;
private final Binding binding;
-
-
+
private MessagingServer server;
// Constructors ---------------------------------------------------------------------------------
- public ServerConsumerImpl(final MessagingServer server, final long id,
+ public ServerConsumerImpl(final MessagingServer server,
+ final long id,
final long replicatedSessionID,
final ServerSession session,
final QueueBinding binding,
@@ -160,7 +160,7 @@
final ManagementService managementService) throws Exception
{
this.server = server;
-
+
this.id = id;
this.replicatedSessionID = replicatedSessionID;
@@ -217,9 +217,14 @@
}
public void close() throws Exception
- {
+ {
setStarted(false);
+ if (largeMessageDeliverer != null)
+ {
+ largeMessageDeliverer.close();
+ }
+
messageQueue.removeConsumer(this);
session.removeConsumer(this);
@@ -414,23 +419,27 @@
}
public void deliverReplicated(final long messageID) throws Exception
- {
+ {
MessageReference ref = messageQueue.removeFirstReference(messageID);
if (ref == null)
{
// The order is correct, but it hasn't been depaged yet, so we need to force a depage
PagingStore store = pagingManager.getPageStore(binding.getAddress());
-
+
// force a depage
if (!store.readPage()) // This returns false if there are no pages
{
- throw new IllegalStateException("Cannot find ref " + messageID + " server " + System.identityHashCode(server) + " queue " + this.messageQueue.getName());
+ throw new IllegalStateException("Cannot find ref " + messageID +
+ " server " +
+ System.identityHashCode(server) +
+ " queue " +
+ this.messageQueue.getName());
}
else
{
ref = messageQueue.removeFirstReference(messageID);
-
+
if (ref == null)
{
throw new IllegalStateException("Cannot find ref after depaging");
@@ -451,7 +460,7 @@
handled);
}
}
-
+
public void failedOver()
{
if (messageQueue.consumerFailedOver())
@@ -732,6 +741,9 @@
{
pendingLargeMessage = message;
+ // we must hold one reference, or the file will be deleted before it could be delivered
+ pendingLargeMessage.incrementRefCount();
+
sizePendingLargeMessage = pendingLargeMessage.getBodySize();
this.ref = ref;
@@ -766,7 +778,10 @@
pendingLargeMessage.encodeProperties(headerBuffer);
- initialMessage = new SessionReceiveMessage(id, headerBuffer.array(), ref.getDeliveryCount());
+ initialMessage = new SessionReceiveMessage(id,
+ headerBuffer.array(),
+ pendingLargeMessage.getBodySize(),
+ ref.getDeliveryCount());
}
int precalculateAvailableCredits;
@@ -838,32 +853,8 @@
trace("Finished deliverLargeMessage isBackup = " + messageQueue.isBackup());
}
- pendingLargeMessage.releaseResources();
+ close();
- if (preAcknowledge && !browseOnly)
- {
- // We added a reference for pre-ack, to avoid deleting the file before it was delivered
- if (pendingLargeMessage.decrementRefCount() == 0)
- {
- // On pre-acks for Large messages, the decrement was deferred to large-message, hence we need to
- // subtract the size inside largeMessage
- try
- {
- PagingStore store = pagingManager.getPageStore(binding.getAddress());
- store.addSize(-pendingLargeMessage.getMemoryEstimate());
- }
- catch (Exception e)
- {
- // This shouldn't happen on getPageStore
- log.error("Error getting pageStore", e);
- }
- }
- }
-
- largeMessageDeliverer = null;
-
- pendingLargeMessagesCounter.decrementAndGet();
-
return true;
}
finally
@@ -873,6 +864,47 @@
}
/**
+ *
+ */
+ public void close()
+ {
+ pendingLargeMessage.releaseResources();
+
+ int counter = pendingLargeMessage.decrementRefCount();
+
+ if (preAcknowledge && !browseOnly)
+ {
+ // PreAck will have an extra reference
+ counter = pendingLargeMessage.decrementRefCount();
+ }
+
+ if (!browseOnly)
+ {
+ // We added a reference to avoid deleting the file before it was delivered
+ // if (pendingLargeMessage.decrementRefCount() == 0)
+ if (counter == 0)
+ {
+ // The decrement was deferred to large-message, hence we need to
+ // subtract the size inside largeMessage
+ try
+ {
+ PagingStore store = pagingManager.getPageStore(binding.getAddress());
+ store.addSize(-pendingLargeMessage.getMemoryEstimate());
+ }
+ catch (Exception e)
+ {
+ // This shouldn't happen as the pageStore should have been initialized already.
+ log.error("Error getting pageStore", e);
+ }
+ }
+ }
+
+ largeMessageDeliverer = null;
+
+ pendingLargeMessagesCounter.decrementAndGet();
+ }
+
+ /**
* Credits flow control are calculated in advance.
* @return
*/
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -2201,17 +2201,8 @@
{
log.error("Failed to create large message", e);
Packet response = null;
- if (packet.isRequiresResponse())
- {
- if (e instanceof MessagingException)
- {
- response = new MessagingExceptionMessage((MessagingException)e);
- }
- else
- {
- response = new MessagingExceptionMessage(new MessagingException(MessagingException.INTERNAL_ERROR));
- }
- }
+
+
channel.confirm(packet);
if (response != null)
{
@@ -2236,15 +2227,8 @@
private void doSendLargeMessage(final SessionSendLargeMessage packet)
{
- Packet response = null;
-
try
{
- if (packet.isRequiresResponse())
- {
- response = new NullResponseMessage();
- }
-
long id = storageManager.generateUniqueID();
currentLargeMessage.setMessageID(id);
@@ -2252,26 +2236,9 @@
catch (Exception e)
{
log.error("Failed to send message", e);
-
- if (packet.isRequiresResponse())
- {
- if (e instanceof MessagingException)
- {
- response = new MessagingExceptionMessage((MessagingException)e);
- }
- else
- {
- response = new MessagingExceptionMessage(new MessagingException(MessagingException.INTERNAL_ERROR));
- }
- }
}
channel.confirm(packet);
-
- if (response != null)
- {
- channel.send(response);
- }
}
private void doSend(final SessionSendMessage packet)
Modified: trunk/src/main/org/jboss/messaging/integration/transports/netty/ChannelBufferWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/integration/transports/netty/ChannelBufferWrapper.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/src/main/org/jboss/messaging/integration/transports/netty/ChannelBufferWrapper.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -165,6 +165,13 @@
{
buffer.writeBytes(src, srcIndex, length);
}
+
+ public void writeBytes(MessagingBuffer src, int srcIndex, int length)
+ {
+ byte bytes[] = new byte[length];
+ src.readBytes(bytes, srcIndex, length);
+ this.writeBytes(bytes);
+ }
public void writeBytes(final byte[] src)
{
Added: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java (rev 0)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -0,0 +1,251 @@
+/*
+ * 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.test.messaging.jms.message;
+
+import java.io.BufferedOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.concurrent.CountDownLatch;
+
+import javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.jboss.messaging.jms.client.JBossMessage;
+import org.jboss.test.messaging.jms.JMSTestCase;
+
+/**
+ *
+ * @author <a href="mailto:clebert.suconic at feodorov.com">Clebert Suconic</a>
+ * @version <tt>$Revision: 6220 $</tt>
+ *
+ * $Id: MessageHeaderTest.java 6220 2009-03-30 19:38:11Z timfox $
+ */
+public class LargeMessageTest extends JMSTestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testSimpleLargeMessage() throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ BytesMessage m = session.createBytesMessage();
+
+ ((JBossMessage)m).getCoreMessage().setBodyInputStream(createFakeLargeStream((byte)'j', 1024 * 1024));
+
+ prod.send(m);
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ BytesMessage rm = (BytesMessage)cons.receive(10000);
+
+ byte data[] = new byte[1024];
+
+ System.out.println("Message = " + rm);
+
+ for (int i = 0; i < 1024 * 1024; i += 1024)
+ {
+ System.out.println("Read message chunk " + i);
+ int numberOfBytes = rm.readBytes(data);
+ assertEquals(1024, numberOfBytes);
+ for (int j = 0 ; j < 1024; j++)
+ {
+ assertEquals((byte)'j', data[j]);
+ }
+ }
+
+ assertNotNull(rm);
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+
+ }
+
+
+ public void testSimpleLargeMessage2() throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = cf.createConnection();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ BytesMessage m = session.createBytesMessage();
+
+ ((JBossMessage)m).getCoreMessage().setBodyInputStream(createFakeLargeStream((byte)'j', 10));
+
+ prod.send(m);
+
+ conn.close();
+
+ conn = cf.createConnection();
+
+ session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer cons = session.createConsumer(queue1);
+
+ conn.start();
+
+ BytesMessage rm = (BytesMessage)cons.receive(10000);
+
+ byte data[] = new byte[1024];
+
+ System.out.println("Message = " + rm);
+
+ int numberOfBytes = rm.readBytes(data);
+ assertEquals(10, numberOfBytes);
+ for (int j = 0 ; j < numberOfBytes; j++)
+ {
+ assertEquals((byte)'j', data[j]);
+ }
+
+ assertNotNull(rm);
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+
+ }
+
+
+ public void testReceiveAfterACK() throws Exception
+ {
+ // Make sure ACK will not delete the file while deliver is done
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+
+ private InputStream createFakeLargeStream(final byte byteToWrite, final long size) throws Exception
+ {
+
+ final PipedInputStream pipedInput = new PipedInputStream();
+ final PipedOutputStream pipedOut = new PipedOutputStream(pipedInput);
+ final OutputStream out = new BufferedOutputStream(pipedOut);
+
+
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ for (long i = 0; i < size; i++)
+ {
+ out.write(byteToWrite);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ out.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ }
+ }
+
+ }.start();
+
+
+ return pipedInput;
+
+ }
+
+
+
+
+ // Inner classes -------------------------------------------------
+
+
+ class ThreadReader extends Thread
+ {
+ CountDownLatch latch;
+
+ ThreadReader(CountDownLatch latch)
+ {
+ this.latch = latch;
+ }
+
+ public void run()
+ {
+ }
+ }
+
+
+}
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -43,7 +43,6 @@
import org.jboss.messaging.core.buffers.ChannelBuffers;
import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
@@ -1071,11 +1070,6 @@
return message;
}
- public ClientFileMessage createFileMessage(boolean durable)
- {
- return null;
- }
-
public void start() throws MessagingException
{
}
Modified: trunk/tests/joram-tests/src/org/jboss/test/jms/AbstractAdmin.java
===================================================================
--- trunk/tests/joram-tests/src/org/jboss/test/jms/AbstractAdmin.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/joram-tests/src/org/jboss/test/jms/AbstractAdmin.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -46,7 +46,7 @@
public void stop() throws Exception
{
- // TODO Auto-generated method stub
+
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/String64KLimitTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/String64KLimitTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/String64KLimitTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -121,25 +121,25 @@
assertNotNull(rm1);
+ assertEquals(s1, rm1.getBody().readString());
+
ClientMessage rm2 = consumer.receive(1000);
assertNotNull(rm2);
+ assertEquals(s2, rm2.getBody().readString());
+
ClientMessage rm3 = consumer.receive(1000);
+ assertEquals(s3, rm3.getBody().readString());
+
assertNotNull(rm3);
ClientMessage rm4 = consumer.receive(1000);
+ assertEquals(s4, rm4.getBody().readString());
+
assertNotNull(rm4);
-
- assertEquals(s1, rm1.getBody().readString());
-
- assertEquals(s2, rm2.getBody().readString());
-
- assertEquals(s3, rm3.getBody().readString());
-
- assertEquals(s4, rm4.getBody().readString());
}
public void test64KLimitWithWriteUTF() throws Exception
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkCleanupTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkCleanupTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkCleanupTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -23,11 +23,10 @@
package org.jboss.messaging.tests.integration.chunkmessage;
import java.io.File;
+import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
@@ -44,7 +43,6 @@
import org.jboss.messaging.core.settings.impl.AddressSettings;
import org.jboss.messaging.tests.integration.chunkmessage.mock.MockConnector;
import org.jboss.messaging.tests.integration.chunkmessage.mock.MockConnectorFactory;
-import org.jboss.messaging.utils.SimpleString;
/**
* A ChunkCleanupTest
@@ -67,12 +65,18 @@
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+
+
public void testCleanup() throws Exception
{
clearData();
+
+ FileOutputStream fileOut = new FileOutputStream(new File(getLargeMessagesDir(), "1234.tmp"));
+
+ fileOut.write(new byte[1024]); // anything
+
+ fileOut.close();
- createLargeFile(getLargeMessagesDir(), "1234.tmp", 13333);
-
Configuration config = createDefaultConfig();
server = createServer(true, config, new HashMap<String, AddressSettings>());
@@ -84,7 +88,7 @@
File directoryLarge = new File(getLargeMessagesDir());
- assertEquals(0, directoryLarge.list().length);
+ assertEquals("The startup should have been deleted 1234.tmp", 0, directoryLarge.list().length);
}
finally
{
@@ -105,7 +109,7 @@
server.start();
- final int numberOfIntegersBigMessage = 150000;
+ final int numberOfBytes = 2 * 1024 * 1024;
ClientSession session = null;
@@ -154,7 +158,7 @@
ClientProducer producer = session.createProducer(ADDRESS);
- ClientFileMessage clientLarge = createLargeClientMessage(session, numberOfIntegersBigMessage);
+ ClientMessage clientLarge = createLargeClientMessage(session, numberOfBytes);
try
{
@@ -182,94 +186,6 @@
}
}
-
- // Validate the functions to create and verify files
- public void testFiles() throws Exception
- {
- clearData();
-
- File file = createLargeFile(getTemporaryDir(), "test.tst", 13333);
-
- checkFileRead(file, 13333);
- }
-
- public void testClearOnClientBuffer() throws Exception
- {
- clearData();
-
- server = createServer(true);
- server.start();
-
- final int numberOfIntegers = 10;
- final int numberOfMessages = 100;
-
- try
- {
- ClientSessionFactory sf = createInVMFactory();
-
- sf.setBlockOnNonPersistentSend(true);
- sf.setBlockOnPersistentSend(true);
- sf.setBlockOnAcknowledge(true);
-
- ClientSession session = sf.createSession(null, null, false, true, false, false, 0);
-
- session.createQueue(ADDRESS, ADDRESS, null, true);
-
- server.getPostOffice().getPagingManager().getGlobalSize();
-
- ClientProducer producer = session.createProducer(ADDRESS);
-
- File tmpData = createLargeFile(getTemporaryDir(), "someFile.dat", numberOfIntegers);
-
- for (int i = 0; i < numberOfMessages; i++)
- {
- ClientMessage message = session.createFileMessage(true);
- ((ClientFileMessage)message).setFile(tmpData);
- message.putIntProperty(new SimpleString("counter-message"), i);
- System.currentTimeMillis();
- producer.send(message);
- }
-
- ClientConsumer consumer = session.createFileConsumer(new File(getClientLargeMessagesDir()), ADDRESS);;
-
- File clientfiles = new File(getClientLargeMessagesDir());
-
- session.start();
-
- ClientMessage msg = consumer.receive(1000);
- msg.acknowledge();
-
- for (int i = 0; i < 100; i++)
- {
- if (clientfiles.listFiles().length > 0)
- {
- break;
- }
- Thread.sleep(100);
- }
-
- assertTrue(clientfiles.listFiles().length > 0);
-
- session.close();
-
- assertEquals(1, clientfiles.list().length); // 1 message was received, that should be kept
-
- validateNoFilesOnLargeDir();
-
- }
- finally
- {
- try
- {
- server.stop();
- }
- catch (Throwable ignored)
- {
- }
- }
-
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -25,20 +25,22 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.jboss.messaging.core.buffers.ChannelBuffers;
import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.MessageHandler;
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.impl.MessageImpl;
@@ -82,45 +84,41 @@
protected void testChunks(final boolean isXA,
final boolean realFiles,
- final boolean useFile,
final boolean preAck,
final boolean sendingBlocking,
final boolean testBrowser,
+ final boolean useMessageConsumer,
final int numberOfMessages,
- final int numberOfIntegers,
+ final int numberOfBytes,
final int waitOnConsumer,
final long delayDelivery) throws Exception
{
testChunks(isXA,
realFiles,
- useFile,
preAck,
sendingBlocking,
testBrowser,
+ useMessageConsumer,
numberOfMessages,
- numberOfIntegers,
+ numberOfBytes,
waitOnConsumer,
delayDelivery,
-1,
- 100 * 1024,
- 10 * 1024,
- false);
+ 10 * 1024);
}
protected void testChunks(final boolean isXA,
final boolean realFiles,
- final boolean useFile,
final boolean preAck,
final boolean sendingBlocking,
final boolean testBrowser,
+ final boolean useMessageConsumer,
final int numberOfMessages,
- final int numberOfIntegers,
+ final int numberOfBytes,
final int waitOnConsumer,
final long delayDelivery,
final int producerWindow,
- final int minSizeProducer,
- final int minSizeConsumer,
- final boolean testTime) throws Exception
+ final int minSize) throws Exception
{
clearData();
@@ -143,7 +141,7 @@
sf.setSendWindowSize(producerWindow);
}
- sf.setMinLargeMessageSize(minSizeProducer);
+ sf.setMinLargeMessageSize(minSize);
ClientSession session;
@@ -160,7 +158,7 @@
ClientProducer producer = session.createProducer(ADDRESS);
- sendMessages(useFile, numberOfMessages, numberOfIntegers, delayDelivery, testTime, session, producer);
+ sendMessages(numberOfMessages, numberOfBytes, delayDelivery, session, producer);
if (isXA)
{
@@ -176,7 +174,7 @@
validateNoFilesOnLargeDir();
- sendMessages(useFile, numberOfMessages, numberOfIntegers, delayDelivery, testTime, session, producer);
+ sendMessages(numberOfMessages, numberOfBytes, delayDelivery, session, producer);
if (isXA)
{
@@ -202,8 +200,6 @@
sf = createInVMFactory();
}
- sf.setMinLargeMessageSize(minSizeConsumer);
-
session = sf.createSession(null, null, isXA, false, false, preAck, 0);
if (isXA)
@@ -214,99 +210,139 @@
ClientConsumer consumer = null;
- // If delayed deliveries... it doesn't make sense with Browsing
- for (int iteration = (testBrowser ? 0 : 1); iteration < 2; iteration++)
+ for (int iteration = testBrowser ? 0 : 1; iteration < 2; iteration++)
{
+ System.out.println("Iteration: " + iteration);
+
+ session.stop();
+
// first time with a browser
- if (realFiles)
+ consumer = session.createConsumer(ADDRESS, null, iteration == 0);
+
+ if (useMessageConsumer)
{
- consumer = session.createFileConsumer(new File(getClientLargeMessagesDir()),
- ADDRESS,
- null,
- iteration == 0);
- }
- else
- {
- consumer = session.createConsumer(ADDRESS, null, iteration == 0);
- }
+ final CountDownLatch latchDone = new CountDownLatch(numberOfMessages);
+ final AtomicInteger errrors = new AtomicInteger(0);
- session.start();
+ MessageHandler handler = new MessageHandler()
+ {
+ int msgCounter;
- for (int i = 0; i < numberOfMessages; i++)
- {
- long start = System.currentTimeMillis();
+ public void onMessage(final ClientMessage message)
+ {
- ClientMessage message = consumer.receive(waitOnConsumer + delayDelivery);
+ try
+ {
+ latchDone.countDown();
- assertNotNull(message);
+ System.out.println("Message on consumer: " + msgCounter);
- if (realFiles)
- {
- assertTrue(message instanceof ClientFileMessage);
- }
+ if (delayDelivery > 0)
+ {
+ long originalTime = (Long)message.getProperty(new SimpleString("original-time"));
+ assertTrue(System.currentTimeMillis() - originalTime + "<" + delayDelivery,
+ System.currentTimeMillis() - originalTime >= delayDelivery);
+ }
- if (testTime)
- {
- System.out.println("Message received in " + (System.currentTimeMillis() - start));
- }
- start = System.currentTimeMillis();
+ if (!preAck)
+ {
+ message.acknowledge();
+ }
- if (delayDelivery > 0)
- {
- long originalTime = (Long)message.getProperty(new SimpleString("original-time"));
- assertTrue((System.currentTimeMillis() - originalTime) + "<" + delayDelivery,
- System.currentTimeMillis() - originalTime >= delayDelivery);
- }
+ assertNotNull(message);
- if (!preAck)
- {
- message.acknowledge();
- }
+ if (delayDelivery <= 0)
+ {
+ // right now there is no guarantee of ordered delivered on multiple scheduledMessages with
+ // the same
+ // scheduled delivery time
+ assertEquals(msgCounter,
+ ((Integer)message.getProperty(new SimpleString("counter-message"))).intValue());
+ }
- if (isXA)
- {
- session.end(xid, XAResource.TMSUCCESS);
- session.commit(xid, true);
- xid = newXID();
- session.start(xid, XAResource.TMNOFLAGS);
- }
- else
- {
- session.commit();
- }
+ MessagingBuffer buffer = message.getBody();
+ buffer.resetReaderIndex();
+ assertEquals(numberOfBytes, buffer.writerIndex());
+ for (int b = 0; b < numberOfBytes; b++)
+ {
+ assertEquals((byte)'a', buffer.readByte());
+ }
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ errrors.incrementAndGet();
+ }
+ finally
+ {
+ msgCounter++;
+ }
+ }
+ };
- assertNotNull(message);
+ session.start();
+
+ Thread.sleep(1000);
- if (delayDelivery <= 0)
+ consumer.setMessageHandler(handler);
+
+ assertTrue(latchDone.await(20, TimeUnit.SECONDS));
+ assertEquals(0, errrors.get());
+
+ }
+ else
+ {
+
+ session.start();
+
+ for (int i = 0; i < numberOfMessages; i++)
{
- // right now there is no guarantee of ordered delivered on multiple scheduledMessages with the same
- // scheduled delivery time
- assertEquals(i, ((Integer)message.getProperty(new SimpleString("counter-message"))).intValue());
- }
+ System.currentTimeMillis();
- if (!testTime)
- {
- if (message instanceof ClientFileMessage)
+ ClientMessage message = consumer.receive(waitOnConsumer + delayDelivery);
+
+ assertNotNull(message);
+
+ System.out.println("Message: " + i);
+
+ System.currentTimeMillis();
+
+ if (delayDelivery > 0)
{
- checkFileRead(((ClientFileMessage)message).getFile(), numberOfIntegers);
+ long originalTime = (Long)message.getProperty(new SimpleString("original-time"));
+ assertTrue(System.currentTimeMillis() - originalTime + "<" + delayDelivery,
+ System.currentTimeMillis() - originalTime >= delayDelivery);
}
- else
+
+ if (!preAck)
{
- MessagingBuffer buffer = message.getBody();
- buffer.resetReaderIndex();
- assertEquals(numberOfIntegers * DataConstants.SIZE_INT, buffer.writerIndex());
- for (int b = 0; b < numberOfIntegers; b++)
- {
- assertEquals(b, buffer.readInt());
- }
+ message.acknowledge();
}
+
+ assertNotNull(message);
+
+ if (delayDelivery <= 0)
+ {
+ // right now there is no guarantee of ordered delivered on multiple scheduledMessages with the same
+ // scheduled delivery time
+ assertEquals(i, ((Integer)message.getProperty(new SimpleString("counter-message"))).intValue());
+ }
+
+ MessagingBuffer buffer = message.getBody();
+ buffer.resetReaderIndex();
+ assertEquals(numberOfBytes, buffer.writerIndex());
+ for (int b = 0; b < numberOfBytes; b++)
+ {
+ assertEquals((byte)'a', buffer.readByte());
+ }
}
+
}
+ consumer.close();
if (iteration == 0)
{
- consumer.close();
if (isXA)
{
session.end(xid, XAResource.TMSUCCESS);
@@ -319,6 +355,20 @@
session.rollback();
}
}
+ else
+ {
+ if (isXA)
+ {
+ session.end(xid, XAResource.TMSUCCESS);
+ session.commit(xid, true);
+ xid = newXID();
+ session.start(xid, XAResource.TMNOFLAGS);
+ }
+ else
+ {
+ session.commit();
+ }
+ }
}
session.close();
@@ -355,69 +405,45 @@
* @throws IOException
* @throws MessagingException
*/
- private void sendMessages(final boolean useFile,
- final int numberOfMessages,
- final int numberOfIntegers,
+ private void sendMessages(final int numberOfMessages,
+ final int numberOfBytes,
final long delayDelivery,
- final boolean testTime,
- ClientSession session,
- ClientProducer producer) throws FileNotFoundException, IOException, MessagingException
+ final ClientSession session,
+ final ClientProducer producer) throws Exception
{
- if (useFile)
+ for (int i = 0; i < numberOfMessages; i++)
{
- File tmpData = createLargeFile(getTemporaryDir(), "someFile.dat", numberOfIntegers);
-
- for (int i = 0; i < numberOfMessages; i++)
+ ClientMessage message = session.createClientMessage(true);
+
+ // If the test is using more than 1M, we will only use the Streaming, as it require too much memory from the test
+ if (numberOfBytes > 1024 * 1024 || i % 2 == 0)
{
- ClientMessage message = session.createFileMessage(true);
- ((ClientFileMessage)message).setFile(tmpData);
- message.putIntProperty(new SimpleString("counter-message"), i);
- long timeStart = System.currentTimeMillis();
- if (delayDelivery > 0)
+ System.out.println("Sending message (stream)" + i);
+ message.setBodyInputStream(createFakeLargeStream(numberOfBytes, (byte)'a'));
+ }
+ else
+ {
+ System.out.println("Sending message (array)" + i);
+ byte[] bytes = new byte[numberOfBytes];
+ for (int j = 0; j < bytes.length; j++)
{
- long time = System.currentTimeMillis();
- message.putLongProperty(new SimpleString("original-time"), time);
- message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, time + delayDelivery);
-
- producer.send(message);
+ bytes[j] = 'a';
}
- else
- {
- producer.send(message);
- }
- if (testTime)
- {
- System.out.println("Message sent in " + (System.currentTimeMillis() - timeStart));
- }
+ message.getBody().writeBytes(bytes);
}
-
- }
- else
- {
- for (int i = 0; i < numberOfMessages; i++)
+ message.putIntProperty(new SimpleString("counter-message"), i);
+ if (delayDelivery > 0)
{
- ClientMessage message = session.createClientMessage(true);
- message.putIntProperty(new SimpleString("counter-message"), i);
- message.setBody(createLargeBuffer(numberOfIntegers));
- long timeStart = System.currentTimeMillis();
- if (delayDelivery > 0)
- {
- long time = System.currentTimeMillis();
- message.putLongProperty(new SimpleString("original-time"), time);
- message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, time + delayDelivery);
+ long time = System.currentTimeMillis();
+ message.putLongProperty(new SimpleString("original-time"), time);
+ message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, time + delayDelivery);
- producer.send(message);
- }
- else
- {
- producer.send(message);
- }
-
- if (testTime)
- {
- System.out.println("Message sent in " + (System.currentTimeMillis() - timeStart));
- }
+ producer.send(message);
}
+ else
+ {
+ producer.send(message);
+ }
}
}
@@ -434,66 +460,24 @@
}
- protected ClientFileMessage createLargeClientMessage(final ClientSession session, final int numberOfIntegers) throws Exception
+ protected ClientMessage createLargeClientMessage(final ClientSession session, final int numberOfBytes) throws Exception
{
- return createLargeClientMessage(session, numberOfIntegers, true);
+ return createLargeClientMessage(session, numberOfBytes, true);
}
- protected ClientFileMessage createLargeClientMessage(final ClientSession session,
- final int numberOfIntegers,
- boolean persistent) throws Exception
+ protected ClientMessage createLargeClientMessage(final ClientSession session,
+ final int numberOfBytes,
+ final boolean persistent) throws Exception
{
- ClientFileMessage clientMessage = session.createFileMessage(persistent);
+ ClientMessage clientMessage = session.createClientMessage(persistent);
- File tmpFile = createLargeFile(getTemporaryDir(), "tmpUpload.data", numberOfIntegers);
+ clientMessage.setBodyInputStream(createFakeLargeStream(numberOfBytes, (byte)'a'));
- clientMessage.setFile(tmpFile);
-
return clientMessage;
}
/**
- * @param name
- * @param numberOfIntegers
- * @return
- * @throws FileNotFoundException
- * @throws IOException
- */
- protected File createLargeFile(final String directory, final String name, final int numberOfIntegers) throws FileNotFoundException,
- IOException
- {
- File tmpFile = new File(directory + "/" + name);
-
- RandomAccessFile random = new RandomAccessFile(tmpFile, "rw");
- FileChannel channel = random.getChannel();
-
- ByteBuffer buffer = ByteBuffer.allocate(4 * 1000);
-
- for (int i = 0; i < numberOfIntegers; i++)
- {
- if (buffer.position() > 0 && i % 1000 == 0)
- {
- buffer.flip();
- channel.write(buffer);
- buffer.clear();
- }
- buffer.putInt(i);
- }
-
- if (buffer.position() > 0)
- {
- buffer.flip();
- channel.write(buffer);
- }
-
- channel.close();
- random.close();
-
- return tmpFile;
- }
-
- /**
* @param session
* @param queueToRead
* @param numberOfIntegers
@@ -501,36 +485,18 @@
* @throws FileNotFoundException
* @throws IOException
*/
- protected void readMessage(final ClientSession session, final SimpleString queueToRead, final int numberOfIntegers) throws MessagingException,
- FileNotFoundException,
- IOException
+ protected void readMessage(final ClientSession session, final SimpleString queueToRead, final int numberOfBytes) throws MessagingException,
+ FileNotFoundException,
+ IOException
{
session.start();
- ClientConsumer consumer = session.createFileConsumer(new File(getClientLargeMessagesDir()), queueToRead);
+ ClientConsumer consumer = session.createConsumer(queueToRead);
ClientMessage clientMessage = consumer.receive(5000);
assertNotNull(clientMessage);
- if (!(clientMessage instanceof ClientFileMessage))
- {
- System.out.println("Size = " + clientMessage.getBodySize());
- }
-
- if (clientMessage instanceof ClientFileMessage)
- {
- assertTrue(clientMessage instanceof ClientFileMessage);
-
- ClientFileMessage fileClientMessage = (ClientFileMessage)clientMessage;
-
- assertNotNull(fileClientMessage);
- File receivedFile = fileClientMessage.getFile();
-
- checkFileRead(receivedFile, numberOfIntegers);
-
- }
-
clientMessage.acknowledge();
session.commit();
@@ -539,61 +505,97 @@
}
/**
- * @param receivedFile
- * @throws FileNotFoundException
- * @throws IOException
+ * Deleting a file on LargeDire is an asynchronous process. Wee need to keep looking for a while if the file hasn't been deleted yet
*/
- protected void checkFileRead(final File receivedFile, final int numberOfIntegers) throws FileNotFoundException,
- IOException
+ protected void validateNoFilesOnLargeDir() throws Exception
{
- RandomAccessFile random2 = new RandomAccessFile(receivedFile, "r");
- FileChannel channel2 = random2.getChannel();
+ File largeMessagesFileDir = new File(getLargeMessagesDir());
- ByteBuffer buffer2 = ByteBuffer.allocate(1000 * 4);
+ // Deleting the file is async... we keep looking for a period of the time until the file is really gone
+ for (int i = 0; i < 100; i++)
+ {
+ if (largeMessagesFileDir.listFiles().length > 0)
+ {
+ Thread.sleep(10);
+ }
+ else
+ {
+ break;
+ }
+ }
- channel2.position(0l);
+ assertEquals(0, largeMessagesFileDir.listFiles().length);
+ }
- for (int i = 0; i < numberOfIntegers;)
+ protected InputStream createFakeLargeStream(final int size, final byte byteUsed) throws Exception
+ {
+ return new InputStream()
{
- channel2.read(buffer2);
+ private int count;
- buffer2.flip();
- for (int j = 0; j < buffer2.limit() / 4; j++, i++)
+ private boolean closed = false;
+
+ @Override
+ public void close() throws IOException
{
- assertEquals(i, buffer2.getInt());
+ super.close();
+ closed = true;
}
- buffer2.clear();
- }
+ @Override
+ public int read() throws IOException
+ {
+ if (closed)
+ {
+ throw new IOException("Stream was closed");
+ }
+ if (count++ < size)
+ {
+ return byteUsed;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ };
- channel2.close();
}
- /**
- * Deleting a file on LargeDire is an asynchronous process. Wee need to keep looking for a while if the file hasn't been deleted yet
- */
- protected void validateNoFilesOnLargeDir() throws Exception
+ protected OutputStream createFakeOutputStream() throws Exception
{
- File largeMessagesFileDir = new File(getLargeMessagesDir());
- // Deleting the file is async... we keep looking for a period of the time until the file is really gone
- for (int i = 0; i < 100; i++)
+ return new OutputStream()
{
- if (largeMessagesFileDir.listFiles().length > 0)
+ private boolean closed = false;
+
+ private int count;
+
+ @Override
+ public void close() throws IOException
{
- Thread.sleep(10);
+ super.close();
+ closed = true;
}
- else
+
+ @Override
+ public void write(final int b) throws IOException
{
- break;
+ if (count++ % 1024 * 1024 == 0)
+ {
+ System.out.println("OutputStream received " + count + " bytes");
+ }
+ if (closed)
+ {
+ throw new IOException("Stream was closed");
+ }
}
- }
- assertEquals(0, largeMessagesFileDir.listFiles().length);
+ };
+
}
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
-
}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientFileMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientFileMessageTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientFileMessageTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -1,133 +0,0 @@
-/*
- * 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.tests.integration.client;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.impl.ClientFileMessageImpl;
-import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.tests.util.ServiceTestBase;
-import org.jboss.messaging.utils.SimpleString;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-
-/**
- * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
- */
-public class ClientFileMessageTest extends ServiceTestBase
-{
- public final SimpleString addressA = new SimpleString("addressA");
-
- public final SimpleString queueA = new SimpleString("queueA");
-
- public void testConsumeFileMessage() throws Exception
- {
- String testDir = System.getProperty("java.io.tmpdir", "/tmp") + "/jbm-unit-test";
-
- MessagingServer server = createServer(false);
- try
- {
- server.start();
- ClientSessionFactory cf = createInVMFactory();
- cf.setMinLargeMessageSize(1000);
- ClientSession sendSession = cf.createSession(false, true, true);
- ClientSession recSession = cf.createSession(false, true, true);
- sendSession.createQueue(addressA, queueA, false);
- ClientProducer cp = sendSession.createProducer(addressA);
- File directory = new File(testDir);
- directory.mkdirs();
- ClientConsumer cc = recSession.createFileConsumer(directory, queueA);
- recSession.start();
- ClientMessage message = recSession.createClientMessage(false);
- byte[] bytes = new byte[3000];
- message.getBody().writeBytes(bytes);
- cp.send(message);
- ClientFileMessageImpl m = (ClientFileMessageImpl) cc.receive(5000);
- assertNotNull(m);
- FileChannel channel = m.getChannel();
- ByteBuffer dst = ByteBuffer.allocate(3000);
- channel.read(dst);
- assertEqualsByteArrays(bytes, dst.array());
- sendSession.close();
- recSession.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
- }
-
- public void testProduceFileMessage() throws Exception
- {
- String testDir = System.getProperty("java.io.tmpdir", "/tmp") + "/jbm-unit-test";
-
- MessagingServer server = createServer(false);
- try
- {
- server.start();
- ClientSessionFactory cf = createInVMFactory();
- cf.setMinLargeMessageSize(1000);
- ClientSession sendSession = cf.createSession(false, true, true);
- ClientSession recSession = cf.createSession(false, true, true);
- sendSession.createQueue(addressA, queueA, false);
- ClientProducer cp = sendSession.createProducer(addressA);
- File directory = new File(testDir);
- directory.delete();
- directory.mkdirs();
- ClientConsumer cc = recSession.createConsumer(queueA);
- recSession.start();
- ClientFileMessage message = sendSession.createFileMessage(false);
- byte[] bytes = new byte[3000];
- File src = new File(directory, "test.jbm");
- src.createNewFile();
- FileOutputStream fos = new FileOutputStream(src);
- fos.write(bytes);
- fos.close();
- message.setFile(src);
- cp.send(message);
- ClientMessage m = cc.receive(5000);
- assertNotNull(m);
- byte[] recBytes = new byte[3000];
- m.getBody().readBytes(recBytes);
- assertEqualsByteArrays(bytes, recBytes);
- sendSession.close();
- recSession.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
- }
-}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -26,8 +26,6 @@
import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
import static org.jboss.messaging.tests.util.RandomUtil.randomXid;
-import java.io.File;
-
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
@@ -98,14 +96,6 @@
{
public void run() throws MessagingException
{
- session.createFileConsumer(new File("."), randomSimpleString());
- }
- });
-
- expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
- {
- public void run() throws MessagingException
- {
session.createQueue(randomSimpleString(), randomSimpleString(), randomBoolean());
}
});
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCreateConsumerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCreateConsumerTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCreateConsumerTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -28,8 +28,6 @@
import org.jboss.messaging.core.server.MessagingServer;
import org.jboss.messaging.tests.util.ServiceTestBase;
-import java.io.File;
-
/**
* @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
*/
@@ -47,7 +45,7 @@
cf.setProducerMaxRate(99);
cf.setBlockOnNonPersistentSend(true);
cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+ ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
ClientConsumer consumer = clientSession.createConsumer(queueName);
assertNotNull(consumer);
@@ -69,7 +67,7 @@
cf.setProducerMaxRate(99);
cf.setBlockOnNonPersistentSend(true);
cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+ ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
try
{
clientSession.createConsumer(queueName);
@@ -97,7 +95,7 @@
cf.setProducerMaxRate(99);
cf.setBlockOnNonPersistentSend(true);
cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+ ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
ClientConsumer consumer = clientSession.createConsumer(queueName, "foo=bar");
assertNotNull(consumer);
@@ -119,7 +117,7 @@
cf.setProducerMaxRate(99);
cf.setBlockOnNonPersistentSend(true);
cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+ ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
try
{
@@ -148,7 +146,7 @@
cf.setProducerMaxRate(99);
cf.setBlockOnNonPersistentSend(true);
cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+ ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
ClientConsumer consumer = clientSession.createConsumer(queueName, null, true);
assertNotNull(consumer);
@@ -170,7 +168,7 @@
cf.setProducerMaxRate(99);
cf.setBlockOnNonPersistentSend(true);
cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+ ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
clientSession.createQueue(queueName, queueName, false);
ClientConsumer consumer = clientSession.createConsumer(queueName, null, 100, 100, false);
assertNotNull(consumer);
@@ -182,148 +180,4 @@
}
}
- public void testCreateFileConsumerTest() throws Exception
- {
- MessagingServer service = createServer(false);
- try
- {
- service.start();
- ClientSessionFactory cf = createInVMFactory();
- cf.setProducerMaxRate(99);
- cf.setBlockOnNonPersistentSend(true);
- cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
- clientSession.createQueue(queueName, queueName, false);
- ClientConsumer consumer = clientSession.createFileConsumer(new File(""), queueName);
- assertNotNull(consumer);
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
- }
-
- public void testCreateFileConsumerNoQ() throws Exception
- {
- MessagingServer service = createServer(false);
- try
- {
- service.start();
- ClientSessionFactory cf = createInVMFactory();
- cf.setProducerMaxRate(99);
- cf.setBlockOnNonPersistentSend(true);
- cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
- try
- {
- clientSession.createFileConsumer(new File(""), queueName);
- fail("should throw exception");
- }
- catch (MessagingException e)
- {
- assertEquals(e.getCode(), MessagingException.QUEUE_DOES_NOT_EXIST);
- }
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
- }
-
- public void testCreateFileConsumerWithFilter() throws Exception
- {
- MessagingServer service = createServer(false);
- try
- {
- service.start();
- ClientSessionFactory cf = createInVMFactory();
- cf.setProducerMaxRate(99);
- cf.setBlockOnNonPersistentSend(true);
- cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
- clientSession.createQueue(queueName, queueName, false);
- ClientConsumer consumer = clientSession.createFileConsumer(new File(""), queueName, "foo=bar");
- assertNotNull(consumer);
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
- }
-
- public void testCreateFileConsumerWithInvalidFilter() throws Exception
- {
- MessagingServer service = createServer(false);
- try
- {
- service.start();
- ClientSessionFactory cf = createInVMFactory();
- cf.setProducerMaxRate(99);
- cf.setBlockOnNonPersistentSend(true);
- cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
- clientSession.createQueue(queueName, queueName, false);
- try
- {
- clientSession.createFileConsumer(new File(""), queueName, "foobar");
- fail("should throw exception");
- }
- catch (MessagingException e)
- {
- assertEquals(e.getCode(), MessagingException.INVALID_FILTER_EXPRESSION);
- }
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
- }
-
- public void testCreateFileConsumerWithBrowseOnly() throws Exception
- {
- MessagingServer service = createServer(false);
- try
- {
- service.start();
- ClientSessionFactory cf = createInVMFactory();
- cf.setProducerMaxRate(99);
- cf.setBlockOnNonPersistentSend(true);
- cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
- clientSession.createQueue(queueName, queueName, false);
- ClientConsumer consumer = clientSession.createFileConsumer(new File(""), queueName, null, true);
- assertNotNull(consumer);
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
- }
-
- public void testCreateFileConsumerWithOverrides() throws Exception
- {
- MessagingServer service = createServer(false);
- try
- {
- service.start();
- ClientSessionFactory cf = createInVMFactory();
- cf.setProducerMaxRate(99);
- cf.setBlockOnNonPersistentSend(true);
- cf.setBlockOnNonPersistentSend(true);
- ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
- clientSession.createQueue(queueName, queueName, false);
- ClientConsumer consumer = clientSession.createFileConsumer(new File(""), queueName, null, 100, 100, false);
- assertNotNull(consumer);
- clientSession.close();
- }
- finally
- {
- service.stop();
- }
- }
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -26,7 +26,6 @@
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.impl.ClientFileMessageInternal;
import org.jboss.messaging.core.client.impl.ClientSessionImpl;
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.remoting.FailureListener;
@@ -348,48 +347,6 @@
}
}
- public void testCreateClientFileMessageNonDurable() throws Exception
- {
- MessagingServer server = createServer(false);
- try
- {
- server.start();
- ClientSessionFactory cf = createInVMFactory();
- ClientSession clientSession = cf.createSession(false, true, true);
- ClientFileMessageInternal clientMessage = (ClientFileMessageInternal) clientSession.createFileMessage(false);
- assertEquals(false, clientMessage.isDurable());
- clientSession.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
- }
-
- public void testCreateClientFileMessageDurable() throws Exception
- {
- MessagingServer server = createServer(false);
- try
- {
- server.start();
- ClientSessionFactory cf = createInVMFactory();
- ClientSession clientSession = cf.createSession(false, true, true);
- ClientFileMessageInternal clientMessage = (ClientFileMessageInternal) clientSession.createFileMessage(true);
- assertEquals(true, clientMessage.isDurable());
- clientSession.close();
- }
- finally
- {
- if (server.isStarted())
- {
- server.stop();
- }
- }
- }
-
public void testGetVersion() throws Exception
{
MessagingServer server = createServer(false);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/ConsumerWindowSizeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/ConsumerWindowSizeTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/ConsumerWindowSizeTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -479,6 +479,17 @@
public void testSlowConsumerOnMessageHandlerNoBuffers() throws Exception
{
+ internalTestSlowConsumerOnMessageHandlerNoBuffers(false);
+ }
+
+ public void testSlowConsumerOnMessageHandlerNoBuffersLargeMessage() throws Exception
+ {
+ internalTestSlowConsumerOnMessageHandlerNoBuffers(true);
+ }
+
+ public void internalTestSlowConsumerOnMessageHandlerNoBuffers(boolean largeMessages) throws Exception
+ {
+
MessagingServer server = createServer(false);
ClientSession sessionB = null;
@@ -493,6 +504,12 @@
ClientSessionFactory sf = createInVMFactory();
sf.setConsumerWindowSize(0);
+ if (largeMessages)
+ {
+ sf.setMinLargeMessageSize(100);
+ }
+
+
session = sf.createSession(false, true, true);
SimpleString ADDRESS = new SimpleString("some-queue");
@@ -561,7 +578,12 @@
for (int i = 0; i < numberOfMessages; i++)
{
- prod.send(createTextMessage(session, "Msg" + i));
+ ClientMessage msg = createTextMessage(session, "Msg" + i);
+ if (largeMessages)
+ {
+ msg.getBody().writeBytes(new byte[600]);
+ }
+ prod.send(msg);
}
consReceiveOneAndHold.setMessageHandler(handler);
@@ -622,11 +644,6 @@
internalTestSlowConsumerOnMessageHandlerBufferOne(false);
}
- public void testSlowConsumerOnMessageHandlerBufferOneLargeMessages() throws Exception
- {
- internalTestSlowConsumerOnMessageHandlerBufferOne(true);
- }
-
private void internalTestSlowConsumerOnMessageHandlerBufferOne(final boolean largeMessage) throws Exception
{
MessagingServer server = createServer(false);
@@ -682,7 +699,7 @@
{
String str = getTextMessage(message);
- System.out.println("Received " + str);
+ System.out.println("Received " + str + " on consumer");
failed = failed || !str.equals("Msg" + count);
@@ -692,6 +709,7 @@
if (count++ == 1)
{
+ System.out.println("Waiting on Consumer");
// it will hold here for a while
if (!latchDone.await(TIMEOUT, TimeUnit.SECONDS))
{
@@ -735,7 +753,9 @@
{
ClientMessage msg = cons1.receive(1000);
assertNotNull("expected message at i = " + i, msg);
- assertEquals("Msg" + i, getTextMessage(msg));
+ String text = getTextMessage(msg);
+ System.out.println("Received message " + text);
+ assertEquals("Msg" + i, text);
msg.acknowledge();
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/DurableQueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/DurableQueueTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/DurableQueueTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -28,14 +28,12 @@
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.config.Configuration;
import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
-import org.jboss.messaging.core.server.Messaging;
import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.tests.util.ServiceTestBase;
import org.jboss.messaging.utils.SimpleString;
/**
@@ -43,7 +41,7 @@
*
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
*/
-public class DurableQueueTest extends UnitTestCase
+public class DurableQueueTest extends ServiceTestBase
{
// Constants -----------------------------------------------------
@@ -54,7 +52,7 @@
private ClientSession session;
- private ClientSessionFactoryImpl sf;
+ private ClientSessionFactory sf;
// Static --------------------------------------------------------
@@ -153,12 +151,12 @@
{
super.setUp();
- Configuration config = new ConfigurationImpl();
- config.setSecurityEnabled(false);
- server = Messaging.newMessagingServer(config);
- server.start();
+ server = createServer(true);
- sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ server.start();
+
+ sf = createInVMFactory();
+
session = sf.createSession(false, true, true);
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -22,7 +22,6 @@
package org.jboss.messaging.tests.integration.client;
-import java.io.File;
import java.util.HashMap;
import javax.transaction.xa.XAResource;
@@ -32,15 +31,17 @@
import org.jboss.messaging.core.buffers.ChannelBuffers;
import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientConsumerInternal;
import org.jboss.messaging.core.config.Configuration;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.Queue;
import org.jboss.messaging.core.settings.impl.AddressSettings;
import org.jboss.messaging.tests.integration.chunkmessage.ChunkTestBase;
import org.jboss.messaging.utils.DataConstants;
@@ -62,6 +63,8 @@
final static int RECEIVE_WAIT_TIME = 10000;
+ private final int LARGE_MESSAGE_SIZE = 20 * 1024;
+
// Attributes ----------------------------------------------------
static final SimpleString ADDRESS = new SimpleString("SimpleAddress");
@@ -73,67 +76,239 @@
// Public --------------------------------------------------------
+ public void testResendSmallStreamMessage() throws Exception
+ {
+ internalTestResendMessage(50000);
+ }
+
+ public void testResendLargeStreamMessage() throws Exception
+ {
+ internalTestResendMessage(150 * 1024);
+ }
+
+ public void internalTestResendMessage(int messageSize) throws Exception
+ {
+ ClientSession session = null;
+ try
+ {
+ server = createServer(true);
+
+ server.start();
+
+ ClientSessionFactory sf = createInVMFactory();
+
+ session = sf.createSession(false, false, false);
+
+ session.createQueue(ADDRESS, ADDRESS, true);
+
+ SimpleString ADDRESS2 = ADDRESS.concat("-2");
+
+ session.createQueue(ADDRESS2, ADDRESS2, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ ClientProducer producer2 = session.createProducer(ADDRESS2);
+
+ Message clientFile = createLargeClientMessage(session, messageSize, false);
+
+ producer.send(clientFile);
+
+ session.commit();
+
+ session.start();
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+ ClientConsumer consumer2 = session.createConsumer(ADDRESS2);
+
+ ClientMessage msg1 = consumer.receive(10000);
+ msg1.acknowledge();
+
+ producer2.send(msg1);
+
+
+ try
+ {
+ producer2.send(msg1);
+ fail("Expected Exception");
+ }
+ catch (Throwable e)
+ {
+ }
+
+ session.commit();
+
+ ClientMessage msg2 = consumer2.receive(10000);
+
+ assertNotNull(msg2);
+
+ msg2.acknowledge();
+
+ session.commit();
+
+ assertEquals(messageSize, msg2.getBodySize());
+
+
+ for (int i = 0 ; i < messageSize; i++)
+ {
+ assertEquals((byte)'a', msg2.getBody().readByte());
+ }
+
+ session.close();
+
+ validateNoFilesOnLargeDir();
+ }
+ finally
+ {
+ try
+ {
+ server.stop();
+ }
+ catch (Throwable ignored)
+ {
+ }
+
+ try
+ {
+ session.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ }
+ // Reusing a largemessage should throw an exception
+ }
+
+ public void testMessageChunkFilePersistenceOneMessage() throws Exception
+ {
+ testChunks(false, true, false, false, true, false, 10, 1024 * 1024, RECEIVE_WAIT_TIME, 0);
+ }
+
+ public void testMessageChunkFilePersistenceOneMessageConsumer() throws Exception
+ {
+ testChunks(false, true, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkFilePersistence() throws Exception
{
- testChunks(false, true, false, false, false, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, true, false, false, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
}
+ public void testMessageChunkFilePersistenceConsumer() throws Exception
+ {
+ testChunks(false, true, false, false, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkFilePersistenceXA() throws Exception
{
- testChunks(true, true, false, false, false, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, true, false, false, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
}
+ public void testMessageChunkFilePersistenceXAConsumer() throws Exception
+ {
+ testChunks(true, true, false, false, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkFilePersistenceBlocked() throws Exception
{
- testChunks(false, true, false, false, true, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, true, false, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
}
+ public void testMessageChunkFilePersistenceBlockedConsumer() throws Exception
+ {
+ testChunks(false, true, false, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkFilePersistenceBlockedXA() throws Exception
{
- testChunks(true, true, false, false, true, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, true, false, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
}
+ public void testMessageChunkFilePersistenceBlockedXAConsumer() throws Exception
+ {
+ testChunks(true, true, false, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkFilePersistenceBlockedPreACK() throws Exception
{
- testChunks(false, true, false, true, true, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, true, true, true, true, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
}
+ public void testMessageChunkFilePersistenceBlockedPreACKConsumer() throws Exception
+ {
+ testChunks(false, true, true, true, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkFilePersistenceBlockedPreACKXA() throws Exception
{
- testChunks(true, true, false, true, true, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, true, true, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
}
+ public void testMessageChunkFilePersistenceBlockedPreACKXAConsumer() throws Exception
+ {
+ testChunks(true, true, true, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkFilePersistenceDelayed() throws Exception
{
- testChunks(false, true, false, false, false, false, 1, 50000, RECEIVE_WAIT_TIME, 2000);
+ testChunks(false, true, false, false, false, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
}
+ public void testMessageChunkFilePersistenceDelayedConsumer() throws Exception
+ {
+ testChunks(false, true, false, false, false, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
+ }
+
public void testMessageChunkFilePersistenceDelayedXA() throws Exception
{
- testChunks(true, true, false, false, false, false, 1, 50000, RECEIVE_WAIT_TIME, 2000);
+ testChunks(true, true, false, false, false, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
}
+ public void testMessageChunkFilePersistenceDelayedXAConsumer() throws Exception
+ {
+ testChunks(true, true, false, false, false, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
+ }
+
public void testMessageChunkNullPersistence() throws Exception
{
- testChunks(false, false, false, false, false, true, 1, 50000, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
}
+ public void testMessageChunkNullPersistenceConsumer() throws Exception
+ {
+ testChunks(false, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkNullPersistenceXA() throws Exception
{
- testChunks(true, false, false, false, false, true, 1, 50000, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, false, false, false, true, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
}
+ public void testMessageChunkNullPersistenceXAConsumer() throws Exception
+ {
+ testChunks(true, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+ }
+
public void testMessageChunkNullPersistenceDelayed() throws Exception
{
- testChunks(false, false, false, false, false, false, 100, 50000, RECEIVE_WAIT_TIME, 100);
+ testChunks(false, false, false, false, false, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
}
+ public void testMessageChunkNullPersistenceDelayedConsumer() throws Exception
+ {
+ testChunks(false, false, false, false, false, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
+ }
+
public void testMessageChunkNullPersistenceDelayedXA() throws Exception
{
- testChunks(true, false, false, false, false, false, 100, 50000, RECEIVE_WAIT_TIME, 100);
+ testChunks(true, false, false, false, false, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
}
+ public void testMessageChunkNullPersistenceDelayedXAConsumer() throws Exception
+ {
+ testChunks(true, false, false, false, false, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
+ }
+
public void testPageOnLargeMessage() throws Exception
{
testPageOnLargeMessage(true, false);
@@ -145,84 +320,84 @@
}
- public void testSendfileMessage() throws Exception
+ public void testSendSmallMessageXA() throws Exception
{
- testChunks(false, true, true, false, false, true, 100, 50000, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, true, false, false, true, false, 100, 4, RECEIVE_WAIT_TIME, 0);
}
- public void testSendfileMessageXA() throws Exception
+ public void testSendSmallMessageXAConsumer() throws Exception
{
- testChunks(true, true, true, false, false, true, 100, 50000, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, true, false, false, true, true, 100, 4, RECEIVE_WAIT_TIME, 0);
}
- public void testSendfileMessageOnNullPersistence() throws Exception
+ public void testSendSmallMessageNullPersistenceXA() throws Exception
{
- testChunks(false, false, true, false, false, true, 100, 50000, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, false, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
}
- public void testSendfileMessageOnNullPersistenceXA() throws Exception
+ public void testSendSmallMessageNullPersistenceXAConsumer() throws Exception
{
- testChunks(true, false, true, false, false, true, 100, 50000, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, false, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
}
- public void testSendfileMessageOnNullPersistenceSmallMessage() throws Exception
+ public void testSendRegularMessageNullPersistenceDelayed() throws Exception
{
- testChunks(false, false, true, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
}
- public void testSendfileMessageOnNullPersistenceSmallMessageXA() throws Exception
+ public void testSendRegularMessageNullPersistenceDelayedConsumer() throws Exception
{
- testChunks(true, false, true, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
}
- public void testSendfileMessageSmallMessage() throws Exception
+ public void testSendRegularMessageNullPersistenceDelayedXA() throws Exception
{
- testChunks(false, true, true, false, false, true, 100, 4, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
}
- public void testSendfileMessageSmallMessageXA() throws Exception
+ public void testSendRegularMessageNullPersistenceDelayedXAConsumer() throws Exception
{
- testChunks(true, true, true, false, false, true, 100, 4, RECEIVE_WAIT_TIME, 0);
+ testChunks(true, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
}
- public void testSendRegularMessageNullPersistence() throws Exception
+ public void testSendRegularMessagePersistence() throws Exception
{
- testChunks(false, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, true, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
}
- public void testSendRegularMessageNullPersistenceXA() throws Exception
+ public void testSendRegularMessagePersistenceConsumer() throws Exception
{
- testChunks(true, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, true, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
}
- public void testSendRegularMessageNullPersistenceDelayed() throws Exception
+ public void testSendRegularMessagePersistenceXA() throws Exception
{
- testChunks(false, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+ testChunks(true, true, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
}
- public void testSendRegularMessageNullPersistenceDelayedXA() throws Exception
+ public void testSendRegularMessagePersistenceXAConsumer() throws Exception
{
- testChunks(true, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+ testChunks(true, true, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
}
- public void testSendRegularMessagePersistence() throws Exception
+ public void testSendRegularMessagePersistenceDelayed() throws Exception
{
- testChunks(false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
}
- public void testSendRegularMessagePersistenceXA() throws Exception
+ public void testSendRegularMessagePersistenceDelayedConsumer() throws Exception
{
- testChunks(true, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+ testChunks(false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
}
- public void testSendRegularMessagePersistenceDelayed() throws Exception
+ public void testSendRegularMessagePersistenceDelayedXA() throws Exception
{
testChunks(false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
}
- public void testSendRegularMessagePersistenceDelayedXA() throws Exception
+ public void testSendRegularMessagePersistenceDelayedXAConsumer() throws Exception
{
- testChunks(false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+ testChunks(false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
}
public void testTwoBindingsTwoStartedConsumers() throws Exception
@@ -230,8 +405,6 @@
// there are two bindings.. one is ACKed, the other is not, the server is restarted
// The other binding is acked... The file must be deleted
- clearData();
-
try
{
@@ -248,10 +421,9 @@
session.createQueue(ADDRESS, queue[0], null, true);
session.createQueue(ADDRESS, queue[1], null, true);
- int numberOfIntegers = 100000;
+ int numberOfBytes = 400000;
- Message clientFile = createLargeClientMessage(session, numberOfIntegers);
- // Message clientFile = createLargeClientMessage(session, numberOfIntegers);
+ Message clientFile = createLargeClientMessage(session, numberOfBytes);
ClientProducer producer = session.createProducer(ADDRESS);
@@ -261,7 +433,7 @@
producer.close();
- ClientConsumer consumer = session.createFileConsumer(new File(getClientLargeMessagesDir()), queue[1]);
+ ClientConsumer consumer = session.createConsumer(queue[1]);
ClientMessage msg = consumer.receive(RECEIVE_WAIT_TIME);
assertNull(consumer.receive(1000));
assertNotNull(msg);
@@ -273,7 +445,7 @@
session.stop();
- ClientConsumer consumer1 = session.createFileConsumer(new File(getClientLargeMessagesDir()), queue[0]);
+ ClientConsumer consumer1 = session.createConsumer(queue[0]);
session.start();
@@ -316,8 +488,6 @@
// there are two bindings.. one is ACKed, the other is not, the server is restarted
// The other binding is acked... The file must be deleted
- clearData();
-
try
{
@@ -334,17 +504,16 @@
session.createQueue(ADDRESS, queue[0], null, true);
session.createQueue(ADDRESS, queue[1], null, true);
- int numberOfIntegers = 100000;
+ int numberOfBytes = 400000;
- Message clientFile = createLargeClientMessage(session, numberOfIntegers);
- // Message clientFile = createLargeClientMessage(session, numberOfIntegers);
+ Message clientFile = createLargeClientMessage(session, numberOfBytes);
ClientProducer producer = session.createProducer(ADDRESS);
producer.send(clientFile);
producer.close();
- readMessage(session, queue[1], numberOfIntegers);
+ readMessage(session, queue[1], numberOfBytes);
if (restart)
{
@@ -363,7 +532,7 @@
session = sf.createSession(null, null, false, true, true, false, 0);
}
- readMessage(session, queue[0], numberOfIntegers);
+ readMessage(session, queue[0], numberOfBytes);
session.close();
@@ -394,52 +563,72 @@
private void internalTestSendRollback(final boolean isXA) throws Exception
{
- clearData();
- server = createServer(true);
+ ClientSession session = null;
- server.start();
+ try
+ {
+ server = createServer(true);
- ClientSessionFactory sf = createInVMFactory();
+ server.start();
- ClientSession session = sf.createSession(isXA, false, false);
+ ClientSessionFactory sf = createInVMFactory();
- session.createQueue(ADDRESS, ADDRESS, true);
+ session = sf.createSession(isXA, false, false);
- Xid xid = null;
+ session.createQueue(ADDRESS, ADDRESS, true);
- if (isXA)
- {
- xid = newXID();
- session.start(xid, XAResource.TMNOFLAGS);
- }
+ Xid xid = null;
- ClientProducer producer = session.createProducer(ADDRESS);
+ if (isXA)
+ {
+ xid = newXID();
+ session.start(xid, XAResource.TMNOFLAGS);
+ }
- Message clientFile = createLargeClientMessage(session, 50000, false);
+ ClientProducer producer = session.createProducer(ADDRESS);
- for (int i = 0; i < 1; i++)
- {
- producer.send(clientFile);
- }
+ Message clientFile = createLargeClientMessage(session, 50000, false);
- if (isXA)
- {
- session.end(xid, XAResource.TMSUCCESS);
- session.prepare(xid);
- session.rollback(xid);
+ for (int i = 0; i < 1; i++)
+ {
+ producer.send(clientFile);
+ }
+
+ if (isXA)
+ {
+ session.end(xid, XAResource.TMSUCCESS);
+ session.prepare(xid);
+ session.rollback(xid);
+ }
+ else
+ {
+ session.rollback();
+ }
+
+ session.close();
+
+ validateNoFilesOnLargeDir();
}
- else
+ finally
{
- session.rollback();
+ try
+ {
+ server.stop();
+ }
+ catch (Throwable ignored)
+ {
+ }
+
+ try
+ {
+ session.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
}
- session.close();
-
- validateNoFilesOnLargeDir();
-
- server.stop();
-
}
public void testSimpleRollback() throws Exception
@@ -452,13 +641,11 @@
simpleRollbackInternalTest(true);
}
- public void simpleRollbackInternalTest(boolean isXA) throws Exception
+ public void simpleRollbackInternalTest(final boolean isXA) throws Exception
{
// there are two bindings.. one is ACKed, the other is not, the server is restarted
// The other binding is acked... The file must be deleted
- clearData();
-
try
{
@@ -480,7 +667,7 @@
session.createQueue(ADDRESS, ADDRESS, null, true);
- int numberOfIntegers = 50000;
+ int numberOfBytes = 200000;
session.start();
@@ -492,7 +679,7 @@
for (int n = 0; n < 10; n++)
{
- Message clientFile = createLargeClientMessage(session, numberOfIntegers, n % 2 == 0);
+ Message clientFile = createLargeClientMessage(session, numberOfBytes, n % 2 == 0);
producer.send(clientFile);
@@ -510,6 +697,8 @@
session.rollback();
}
+ clientFile = createLargeClientMessage(session, numberOfBytes, n % 2 == 0);
+
producer.send(clientFile);
assertNull(consumer.receiveImmediate());
@@ -533,7 +722,7 @@
assertNotNull(clientMessage);
- assertEquals(numberOfIntegers * 4, clientMessage.getBody().writerIndex());
+ assertEquals(numberOfBytes, clientMessage.getBody().writerIndex());
clientMessage.acknowledge();
@@ -586,6 +775,270 @@
}
+ public void testBufferMultipleLargeMessages() throws Exception
+ {
+ ClientSession session = null;
+ MessagingServer server = null;
+
+ final int SIZE = 10 * 1024;
+ final int NUMBER_OF_MESSAGES = 30;
+ try
+ {
+
+ server = createServer(true);
+
+ server.start();
+
+ ClientSessionFactory sf = createInVMFactory();
+
+ sf.setMinLargeMessageSize(1024);
+ sf.setConsumerWindowSize(1024 * 1024);
+
+ session = sf.createSession(null, null, false, false, false, false, 0);
+
+ session.createQueue(ADDRESS, ADDRESS, null, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
+ {
+ Message clientFile = session.createClientMessage(true);
+ clientFile.setBodyInputStream(createFakeLargeStream(SIZE, (byte)i));
+ producer.send(clientFile);
+
+ }
+ session.commit();
+ producer.close();
+
+ session.start();
+
+ ClientConsumerInternal consumer = (ClientConsumerInternal)session.createConsumer(ADDRESS);
+
+ // Wait the consumer to be complete with 10 messages before getting others
+ long timeout = System.currentTimeMillis() + 10000;
+ while (consumer.getBufferSize() < NUMBER_OF_MESSAGES && timeout > System.currentTimeMillis())
+ {
+ Thread.sleep(10);
+ }
+ assertEquals(NUMBER_OF_MESSAGES, consumer.getBufferSize());
+
+ // Reads the messages, rollback.. read them again
+ for (int trans = 0; trans < 2; trans++)
+ {
+
+ for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
+ {
+ ClientMessage msg = consumer.receive(10000);
+ assertNotNull(msg);
+
+ // it will ignore the buffer (not read it) on the first try
+ if (trans == 0)
+ {
+ for (int byteRead = 0; byteRead < SIZE; byteRead++)
+ {
+ assertEquals((byte)i, msg.getBody().readByte());
+ }
+ }
+
+ msg.acknowledge();
+ }
+ if (trans == 0)
+ {
+ session.rollback();
+ }
+ else
+ {
+ session.commit();
+ }
+ }
+
+ assertEquals(0l, server.getPostOffice().getPagingManager().getGlobalSize());
+ assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
+ assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getMessageCount());
+
+ }
+ finally
+ {
+ try
+ {
+ session.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
+
+ try
+ {
+ server.stop();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ }
+ }
+
+ public void testSendStreamingSingleMessage() throws Exception
+ {
+ ClientSession session = null;
+ MessagingServer server = null;
+
+ final int SIZE = 10 * 1024 * 1024;
+ try
+ {
+
+ server = createServer(true);
+
+ server.start();
+
+ ClientSessionFactory sf = createInVMFactory();
+
+ sf.setMinLargeMessageSize(100 * 1024);
+
+ session = sf.createSession(null, null, false, true, true, false, 0);
+
+ session.createQueue(ADDRESS, ADDRESS, null, true);
+
+ Message clientFile = session.createClientMessage(true);
+ clientFile.setBodyInputStream(createFakeLargeStream(SIZE, (byte)'a'));
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ session.start();
+
+ System.out.println("Sending");
+ producer.send(clientFile);
+
+ producer.close();
+
+ System.out.println("Waiting");
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ ClientMessage msg2 = consumer.receive(10000);
+
+ msg2.acknowledge();
+
+ msg2.setOutputStream(createFakeOutputStream());
+ assertTrue(msg2.waitOutputStreamCompletion(60000));
+
+ // for (int i = 0; i < SIZE; i++)
+ // {
+ // byte value = msg2.getBody().readByte();
+ // assertEquals("Error position " + i, (byte)'a', value);
+ // }
+
+ session.commit();
+
+ assertEquals(0l, server.getPostOffice().getPagingManager().getGlobalSize());
+ assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
+ assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getMessageCount());
+
+ }
+ finally
+ {
+ try
+ {
+ session.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
+
+ try
+ {
+ server.stop();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ }
+ }
+
+ /** Receive messages but never reads them, leaving the buffer pending */
+ public void testIgnoreStreaming() throws Exception
+ {
+ ClientSession session = null;
+ MessagingServer server = null;
+
+ final int SIZE = 10 * 1024;
+ final int NUMBER_OF_MESSAGES = 1;
+ try
+ {
+
+ server = createServer(true);
+
+ server.start();
+
+ ClientSessionFactory sf = createInVMFactory();
+
+ sf.setMinLargeMessageSize(1024);
+
+ session = sf.createSession(null, null, false, true, true, false, 0);
+
+ session.createQueue(ADDRESS, ADDRESS, null, true);
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
+ {
+ Message msg = session.createClientMessage(true);
+ msg.setBodyInputStream(createFakeLargeStream(SIZE, (byte)'a'));
+ msg.putIntProperty(new SimpleString("key"), i);
+ producer.send(msg);
+
+ System.out.println("Sent msg " + i);
+ }
+
+ session.start();
+
+ System.out.println("Sending");
+
+ producer.close();
+
+ System.out.println("Waiting");
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
+ {
+ ClientMessage msg = consumer.receive(50000);
+ assertNotNull(msg);
+
+ assertEquals(i, msg.getProperty(new SimpleString("key")));
+
+ msg.acknowledge();
+ }
+
+ consumer.close();
+
+ session.commit();
+
+ assertEquals(0l, server.getPostOffice().getPagingManager().getGlobalSize());
+ assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
+ assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getMessageCount());
+
+ System.out.println("Thread done");
+ }
+ finally
+ {
+ try
+ {
+ session.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
+
+ try
+ {
+ server.stop();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ }
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@@ -594,22 +1047,21 @@
protected void setUp() throws Exception
{
super.setUp();
- log.info("\n*********************************************************************************\n Starting " + this.getName() +
+ clearData();
+ log.info("\n*********************************************************************************\n Starting " + getName() +
"\n*********************************************************************************");
}
@Override
protected void tearDown() throws Exception
{
- log.info("\n*********************************************************************************\nDone with " + this.getName() +
+ log.info("\n*********************************************************************************\nDone with " + getName() +
"\n*********************************************************************************");
super.tearDown();
}
protected void testPageOnLargeMessage(final boolean realFiles, final boolean sendBlocking) throws Exception
{
- clearData();
-
Configuration config = createDefaultConfig();
config.setPagingMaxGlobalSizeBytes(20 * 1024);
@@ -619,9 +1071,9 @@
server.start();
- final int numberOfIntegers = 256;
+ final int numberOfBytes = 1024;
- final int numberOfIntegersBigMessage = 100000;
+ final int numberOfBytesBigMessage = 400000;
try
{
@@ -648,9 +1100,9 @@
for (int i = 0; i < 100; i++)
{
- MessagingBuffer bodyLocal = ChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfIntegers);
+ MessagingBuffer bodyLocal = ChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfBytes);
- for (int j = 1; j <= numberOfIntegers; j++)
+ for (int j = 1; j <= numberOfBytes; j++)
{
bodyLocal.writeInt(j);
}
@@ -666,7 +1118,7 @@
producer.send(message);
}
- ClientFileMessage clientFile = createLargeClientMessage(session, numberOfIntegersBigMessage);
+ ClientMessage clientFile = createLargeClientMessage(session, numberOfBytesBigMessage);
producer.send(clientFile);
@@ -718,7 +1170,7 @@
session = sf.createSession(null, null, false, true, true, false, 0);
- readMessage(session, ADDRESS, numberOfIntegersBigMessage);
+ readMessage(session, ADDRESS, numberOfBytesBigMessage);
// printBuffer("message received : ", message2.getBody());
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageExpirationTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageExpirationTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageExpirationTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -38,6 +38,7 @@
import org.jboss.messaging.core.server.Messaging;
import org.jboss.messaging.core.server.MessagingServer;
import org.jboss.messaging.core.settings.impl.AddressSettings;
+import org.jboss.messaging.tests.util.ServiceTestBase;
import org.jboss.messaging.tests.util.UnitTestCase;
import org.jboss.messaging.utils.SimpleString;
@@ -48,7 +49,7 @@
*
*
*/
-public class MessageExpirationTest extends UnitTestCase
+public class MessageExpirationTest extends ServiceTestBase
{
// Constants -----------------------------------------------------
@@ -142,12 +143,10 @@
{
super.setUp();
- Configuration config = new ConfigurationImpl();
- config.setSecurityEnabled(false);
- server = Messaging.newMessagingServer(config);
+ server = createServer(false);
server.start();
- ClientSessionFactory sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ ClientSessionFactory sf = createInVMFactory();
session = sf.createSession(false, true, true);
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/TemporaryQueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/TemporaryQueueTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/TemporaryQueueTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -28,17 +28,15 @@
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
-import org.jboss.messaging.core.config.Configuration;
import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.remoting.RemotingConnection;
import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
-import org.jboss.messaging.core.server.Messaging;
import org.jboss.messaging.core.server.MessagingServer;
import org.jboss.messaging.core.server.impl.ServerSessionImpl;
-import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.tests.util.ServiceTestBase;
import org.jboss.messaging.utils.SimpleString;
/**
@@ -53,7 +51,7 @@
*
*
*/
-public class TemporaryQueueTest extends UnitTestCase
+public class TemporaryQueueTest extends ServiceTestBase
{
// Constants -----------------------------------------------------
@@ -64,7 +62,7 @@
private ClientSession session;
- private ClientSessionFactoryImpl sf;
+ private ClientSessionFactory sf;
// Static --------------------------------------------------------
@@ -215,12 +213,10 @@
{
super.setUp();
- Configuration config = new ConfigurationImpl();
- config.setSecurityEnabled(false);
- server = Messaging.newMessagingServer(config);
+ server = createServer(false);
server.start();
- sf = new ClientSessionFactoryImpl(new TransportConfiguration(InVMConnectorFactory.class.getName()));
+ sf = createInVMFactory();
session = sf.createSession(false, true, true);
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/ClusterTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/ClusterTestBase.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/ClusterTestBase.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -959,6 +959,7 @@
configuration.setJournalMinFiles(2);
configuration.setJournalDirectory(getJournalDir(node, false));
configuration.setJournalFileSize(100 * 1024);
+ configuration.setJournalType(JournalType.NIO);
configuration.setPagingDirectory(getPageDir(node, false));
configuration.setLargeMessagesDirectory(getLargeMessagesDir(node, false));
configuration.setClustered(true);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/LargeMessageMultiThreadFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/LargeMessageMultiThreadFailoverTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/LargeMessageMultiThreadFailoverTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -32,6 +32,8 @@
import org.jboss.messaging.core.config.TransportConfiguration;
import org.jboss.messaging.core.config.impl.ConfigurationImpl;
import org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnection;
+import org.jboss.messaging.core.remoting.impl.invm.InVMRegistry;
import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
import org.jboss.messaging.core.server.JournalType;
import org.jboss.messaging.core.server.Messaging;
@@ -80,10 +82,17 @@
}
- @Override
protected void start() throws Exception
{
+ InVMRegistry.instance.clear();
+ //startNullPersistence();
+ startJournal();
+ }
+
+ protected void startJournal() throws Exception
+ {
+
deleteDirectory(new File(getTestDir()));
Configuration backupConf = new ConfigurationImpl();
@@ -135,11 +144,42 @@
liveServer.start();
}
+
+
+ protected void startNullPersistence() throws Exception
+ {
+ Configuration backupConf = new ConfigurationImpl();
+ backupConf.setSecurityEnabled(false);
+ backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
+ backupConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory",
+ backupParams));
+ backupConf.setBackup(true);
+ backupConf.setJMXManagementEnabled(false);
+ backupServer = Messaging.newMessagingServer(backupConf, false);
+ backupServer.start();
+ Configuration liveConf = new ConfigurationImpl();
+ liveConf.setSecurityEnabled(false);
+ liveConf.getAcceptorConfigurations()
+ .add(new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory"));
+ Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();
+ TransportConfiguration backupTC = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+ backupParams,
+ "backup-connector");
+ connectors.put(backupTC.getName(), backupTC);
+ liveConf.setConnectorConfigurations(connectors);
+ liveConf.setBackupConnectorName(backupTC.getName());
+ liveConf.setJMXManagementEnabled(false);
+ liveServer = Messaging.newMessagingServer(liveConf, false);
+ liveServer.start();
+ }
+
+
+
@Override
protected void setBody(final ClientMessage message) throws Exception
{
-
message.getBody().writeBytes(FIVE_HUNDRED_BYTES);
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/paging/PageCrashTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/paging/PageCrashTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/paging/PageCrashTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -23,12 +23,36 @@
package org.jboss.messaging.tests.integration.paging;
import java.io.File;
+import java.io.ObjectInputStream;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.Executor;
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.OperationsException;
+import javax.management.QueryExp;
+import javax.management.ReflectionException;
+import javax.management.loading.ClassLoaderRepository;
+
import org.jboss.messaging.core.client.ClientConsumer;
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientProducer;
@@ -228,8 +252,10 @@
{
JBMSecurityManager securityManager = new JBMSecurityManagerImpl();
- ManagementService managementService = new ManagementServiceImpl(ManagementFactory.getPlatformMBeanServer(), false, false);
-
+ ManagementService managementService = new ManagementServiceImpl(ManagementFactory.getPlatformMBeanServer(),
+ false,
+ false);
+
MessagingServer server = new FailingMessagingServerImpl(configuration, securityManager);
AddressSettings defaultSetting = new AddressSettings();
@@ -249,8 +275,9 @@
{
FailingMessagingServerImpl(final Configuration config, final JBMSecurityManager securityManager)
{
- super(config, null, securityManager);
+ super(config, new FakeMBean(), securityManager);
}
+
@Override
protected PagingManager createPagingManager()
{
@@ -433,6 +460,389 @@
}
+ class FakeMBean implements MBeanServer
+ {
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#addNotificationListener(javax.management.ObjectName, javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)
+ */
+ public void addNotificationListener(ObjectName name,
+ NotificationListener listener,
+ NotificationFilter filter,
+ Object handback) throws InstanceNotFoundException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#addNotificationListener(javax.management.ObjectName, javax.management.ObjectName, javax.management.NotificationFilter, java.lang.Object)
+ */
+ public void addNotificationListener(ObjectName name,
+ ObjectName listener,
+ NotificationFilter filter,
+ Object handback) throws InstanceNotFoundException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#createMBean(java.lang.String, javax.management.ObjectName)
+ */
+ public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#createMBean(java.lang.String, javax.management.ObjectName, javax.management.ObjectName)
+ */
+ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException,
+ InstanceNotFoundException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#createMBean(java.lang.String, javax.management.ObjectName, java.lang.Object[], java.lang.String[])
+ */
+ public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature) throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#createMBean(java.lang.String, javax.management.ObjectName, javax.management.ObjectName, java.lang.Object[], java.lang.String[])
+ */
+ public ObjectInstance createMBean(String className,
+ ObjectName name,
+ ObjectName loaderName,
+ Object[] params,
+ String[] signature) throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException,
+ InstanceNotFoundException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#deserialize(javax.management.ObjectName, byte[])
+ */
+ public ObjectInputStream deserialize(ObjectName name, byte[] data) throws InstanceNotFoundException,
+ OperationsException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#deserialize(java.lang.String, byte[])
+ */
+ public ObjectInputStream deserialize(String className, byte[] data) throws OperationsException,
+ ReflectionException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#deserialize(java.lang.String, javax.management.ObjectName, byte[])
+ */
+ public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data) throws InstanceNotFoundException,
+ OperationsException,
+ ReflectionException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getAttribute(javax.management.ObjectName, java.lang.String)
+ */
+ public Object getAttribute(ObjectName name, String attribute) throws MBeanException,
+ AttributeNotFoundException,
+ InstanceNotFoundException,
+ ReflectionException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getAttributes(javax.management.ObjectName, java.lang.String[])
+ */
+ public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException,
+ ReflectionException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getClassLoader(javax.management.ObjectName)
+ */
+ public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getClassLoaderFor(javax.management.ObjectName)
+ */
+ public ClassLoader getClassLoaderFor(ObjectName mbeanName) throws InstanceNotFoundException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getClassLoaderRepository()
+ */
+ public ClassLoaderRepository getClassLoaderRepository()
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getDefaultDomain()
+ */
+ public String getDefaultDomain()
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getDomains()
+ */
+ public String[] getDomains()
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getMBeanCount()
+ */
+ public Integer getMBeanCount()
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getMBeanInfo(javax.management.ObjectName)
+ */
+ public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException,
+ IntrospectionException,
+ ReflectionException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#getObjectInstance(javax.management.ObjectName)
+ */
+ public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#instantiate(java.lang.String)
+ */
+ public Object instantiate(String className) throws ReflectionException, MBeanException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#instantiate(java.lang.String, javax.management.ObjectName)
+ */
+ public Object instantiate(String className, ObjectName loaderName) throws ReflectionException,
+ MBeanException,
+ InstanceNotFoundException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#instantiate(java.lang.String, java.lang.Object[], java.lang.String[])
+ */
+ public Object instantiate(String className, Object[] params, String[] signature) throws ReflectionException,
+ MBeanException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#instantiate(java.lang.String, javax.management.ObjectName, java.lang.Object[], java.lang.String[])
+ */
+ public Object instantiate(String className, ObjectName loaderName, Object[] params, String[] signature) throws ReflectionException,
+ MBeanException,
+ InstanceNotFoundException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#invoke(javax.management.ObjectName, java.lang.String, java.lang.Object[], java.lang.String[])
+ */
+ public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws InstanceNotFoundException,
+ MBeanException,
+ ReflectionException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#isInstanceOf(javax.management.ObjectName, java.lang.String)
+ */
+ public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException
+ {
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#isRegistered(javax.management.ObjectName)
+ */
+ public boolean isRegistered(ObjectName name)
+ {
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#queryMBeans(javax.management.ObjectName, javax.management.QueryExp)
+ */
+ public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query)
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#queryNames(javax.management.ObjectName, javax.management.QueryExp)
+ */
+ public Set<ObjectName> queryNames(ObjectName name, QueryExp query)
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#registerMBean(java.lang.Object, javax.management.ObjectName)
+ */
+ public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ NotCompliantMBeanException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#removeNotificationListener(javax.management.ObjectName, javax.management.ObjectName)
+ */
+ public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#removeNotificationListener(javax.management.ObjectName, javax.management.NotificationListener)
+ */
+ public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#removeNotificationListener(javax.management.ObjectName, javax.management.ObjectName, javax.management.NotificationFilter, java.lang.Object)
+ */
+ public void removeNotificationListener(ObjectName name,
+ ObjectName listener,
+ NotificationFilter filter,
+ Object handback) throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#removeNotificationListener(javax.management.ObjectName, javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object)
+ */
+ public void removeNotificationListener(ObjectName name,
+ NotificationListener listener,
+ NotificationFilter filter,
+ Object handback) throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#setAttribute(javax.management.ObjectName, javax.management.Attribute)
+ */
+ public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException,
+ AttributeNotFoundException,
+ InvalidAttributeValueException,
+ MBeanException,
+ ReflectionException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#setAttributes(javax.management.ObjectName, javax.management.AttributeList)
+ */
+ public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException,
+ ReflectionException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.management.MBeanServer#unregisterMBean(javax.management.ObjectName)
+ */
+ public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException
+ {
+
+ }
+
+ }
+
// Inner classes -------------------------------------------------
}
Modified: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -39,79 +39,79 @@
public SimpleString getClusterName()
{
- // TODO Auto-generated method stub
+
return null;
}
public BindingType getType()
{
- // TODO Auto-generated method stub
+
return null;
}
public int getDistance()
{
- // TODO Auto-generated method stub
+
return 0;
}
public SimpleString getOriginatingNodeID()
{
- // TODO Auto-generated method stub
+
return null;
}
public Filter getFilter()
{
- // TODO Auto-generated method stub
+
return null;
}
public int getID()
{
- // TODO Auto-generated method stub
+
return 0;
}
public void setID(int id)
{
- // TODO Auto-generated method stub
+
}
public void willRoute(ServerMessage message)
{
- // TODO Auto-generated method stub
+
}
public boolean filterMatches(ServerMessage message) throws Exception
{
- // TODO Auto-generated method stub
+
return false;
}
public boolean isHighAcceptPriority(ServerMessage message)
{
- // TODO Auto-generated method stub
+
return false;
}
public SimpleString getRoutingName()
{
- // TODO Auto-generated method stub
+
return null;
}
public SimpleString getUniqueName()
{
- // TODO Auto-generated method stub
+
return null;
}
public boolean isExclusive()
{
- // TODO Auto-generated method stub
+
return false;
}
Modified: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -49,13 +49,13 @@
{
public boolean redistribute(ServerMessage message, SimpleString routingName, Transaction tx) throws Exception
{
- // TODO Auto-generated method stub
+
return false;
}
public void sendQueueInfoToQueue(SimpleString queueName, SimpleString address) throws Exception
{
- // TODO Auto-generated method stub
+
}
Modified: trunk/tests/src/org/jboss/messaging/tests/soak/chunk/MessageChunkSoakTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/soak/chunk/MessageChunkSoakTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/soak/chunk/MessageChunkSoakTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -49,20 +49,18 @@
public void testMessageChunkFilePersistence1G() throws Exception
{
- testChunks(false,
+ testChunks(false,
true,
- true,
false,
- true,
false,
- 2,
- 268435456,
+ false,
+ false,
+ 1,
+ 1024 * 1024 * 1024,
300000,
0,
-1,
- ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
- ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
- true);
+ ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
}
// Package protected ---------------------------------------------
Modified: trunk/tests/src/org/jboss/messaging/tests/stress/chunk/MessageChunkStressTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/chunk/MessageChunkStressTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/chunk/MessageChunkStressTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -48,8 +48,7 @@
public void testMessageChunkFilePersistence1M() throws Exception
{
- // testChunks(true, true, false, true, false, 1000, 262144, 120000, 0, -1, false);
- // Hudson seems to be failing because of disk full. Temporarily commenting it out
+ testChunks(false, true, false, false, true, false, 100, 1024 * 1024, 50000, 0);
}
// Package protected ---------------------------------------------
Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -0,0 +1,700 @@
+/*
+ * 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.client.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.messaging.core.buffers.ChannelBuffer;
+import org.jboss.messaging.core.buffers.ChannelBuffers;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.MessageHandler;
+import org.jboss.messaging.core.client.impl.ClientConsumerInternal;
+import org.jboss.messaging.core.client.impl.ClientMessageInternal;
+import org.jboss.messaging.core.client.impl.LargeMessageBuffer;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveMessage;
+import org.jboss.messaging.tests.util.RandomUtil;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * A LargeMessageBufferUnitTest
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class LargeMessageBufferTest extends UnitTestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // Test Simple getBytes
+ public void testGetBytes() throws Exception
+ {
+ LargeMessageBuffer buffer = create15BytesSample();
+
+ for (int i = 1; i <= 15; i++)
+ {
+ try
+ {
+ assertEquals(i, buffer.readByte());
+ }
+ catch (Exception e)
+ {
+ throw new Exception("Exception at position " + i, e);
+ }
+ }
+
+ try
+ {
+ buffer.readByte();
+ fail("supposed to throw an exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ }
+ }
+
+ // Test for void getBytes(final int index, final byte[] dst)
+ public void testGetBytesIByteArray() throws Exception
+ {
+ LargeMessageBuffer buffer = create15BytesSample();
+
+ byte[] bytes = new byte[15];
+ buffer.getBytes(0, bytes);
+
+ validateAgainstSample(bytes);
+
+ try
+ {
+ buffer = create15BytesSample();
+
+ bytes = new byte[16];
+ buffer.getBytes(0, bytes);
+ fail("supposed to throw an exception");
+ }
+ catch (java.lang.IndexOutOfBoundsException e)
+ {
+ }
+ }
+
+ // testing void getBytes(int index, ChannelBuffer dst, int dstIndex, int length)
+ public void testGetBytesILChannelBufferII() throws Exception
+ {
+ LargeMessageBuffer buffer = create15BytesSample();
+
+ ChannelBuffer dstBuffer = ChannelBuffers.buffer(20);
+
+ dstBuffer.setIndex(0, 5);
+
+ buffer.getBytes(0, dstBuffer);
+
+ byte[] compareBytes = new byte[15];
+ dstBuffer.getBytes(5, compareBytes);
+
+ validateAgainstSample(compareBytes);
+ }
+
+ // testing void getBytes(int index, ChannelBuffer dst, int dstIndex, int length)
+ public void testReadIntegers() throws Exception
+ {
+ LargeMessageBuffer buffer = createBufferWithIntegers(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+
+ for (int i = 1; i <= 15; i++)
+ {
+ assertEquals(i, buffer.readInt());
+ }
+
+ try
+ {
+ buffer.readByte();
+ fail("supposed to throw an exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ }
+ }
+
+ // testing void getBytes(int index, ChannelBuffer dst, int dstIndex, int length)
+ public void testReadLongs() throws Exception
+ {
+ LargeMessageBuffer buffer = createBufferWithLongs(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+
+ for (int i = 1; i <= 15; i++)
+ {
+ assertEquals(i, buffer.readLong());
+ }
+
+ try
+ {
+ buffer.readByte();
+ fail("supposed to throw an exception");
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ }
+ }
+
+ public void testReadData() throws Exception
+ {
+ ChannelBuffer dynamic = ChannelBuffers.dynamicBuffer(1);
+
+ String str1 = RandomUtil.randomString();
+ String str2 = RandomUtil.randomString();
+ Double d1 = RandomUtil.randomDouble();
+ float f1 = RandomUtil.randomFloat();
+
+ dynamic.writeUTF(str1);
+ dynamic.writeString(str2);
+ dynamic.writeDouble(d1);
+ dynamic.writeFloat(f1);
+
+ LargeMessageBuffer readBuffer = splitBuffer(3, dynamic.array());
+
+ assertEquals(str1, readBuffer.readUTF());
+ assertEquals(str2, readBuffer.readString());
+ assertEquals(d1, readBuffer.readDouble());
+ assertEquals(f1, readBuffer.readFloat());
+ }
+
+ public void testReadPartialData() throws Exception
+ {
+
+ final LargeMessageBuffer buffer = new LargeMessageBuffer(new FakeConsumerInternal(), 10, 10);
+
+ buffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[] { 0, 1, 2, 3, 4 }, true, true));
+
+ byte bytes[] = new byte[30];
+ buffer.readBytes(bytes, 0, 5);
+
+ for (byte i = 0; i < 5; i++)
+ {
+ assertEquals(i, bytes[i]);
+ }
+
+ final CountDownLatch latchGo = new CountDownLatch(1);
+
+ final AtomicInteger errorCount = new AtomicInteger(0);
+
+ Thread t = new Thread()
+ {
+ public void run()
+ {
+
+ try
+ {
+ latchGo.countDown();
+ buffer.readBytes(new byte[5]);
+ }
+ catch (IndexOutOfBoundsException ignored)
+ {
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ errorCount.incrementAndGet();
+ }
+ }
+ };
+
+ t.start();
+
+ latchGo.await();
+
+ buffer.close();
+
+ t.join();
+
+ assertEquals(0, errorCount.get());
+
+ }
+
+ public void testInterruptData() throws Exception
+ {
+ LargeMessageBuffer readBuffer = splitBuffer(3, new byte[] { 0, 1, 2, 3, 4 });
+
+ byte bytes[] = new byte[30];
+ readBuffer.readBytes(bytes, 0, 5);
+
+ for (byte i = 0; i < 5; i++)
+ {
+ assertEquals(i, bytes[i]);
+ }
+ }
+
+ public void testStreamData() throws Exception
+ {
+ final LargeMessageBuffer outBuffer = new LargeMessageBuffer(new FakeConsumerInternal(), 1024 * 11 + 123, 1);
+
+ final PipedOutputStream output = new PipedOutputStream();
+ final PipedInputStream input = new PipedInputStream(output);
+
+ final AtomicInteger errors = new AtomicInteger(0);
+
+ // Done reading 3 elements
+ final CountDownLatch done1 = new CountDownLatch(1);
+ // Done with the thread
+ final CountDownLatch done2 = new CountDownLatch(1);
+
+ final AtomicInteger count = new AtomicInteger(0);
+ final AtomicInteger totalBytes = new AtomicInteger(0);
+
+ Thread treader = new Thread("treader")
+ {
+ public void run()
+ {
+ try
+ {
+
+ byte line[] = new byte[1024];
+ int dataRead = 0;
+ while (dataRead >= 0)
+ {
+ dataRead = input.read(line);
+ if (dataRead > 0)
+ {
+ System.out.println("Read one line with " + dataRead + " bytes");
+ totalBytes.addAndGet(dataRead);
+ if (count.incrementAndGet() == 3)
+ {
+ done1.countDown();
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ errors.incrementAndGet();
+ }
+ finally
+ {
+ done1.countDown();
+ done2.countDown();
+ }
+ }
+ };
+
+ treader.setDaemon(true);
+ treader.start();
+
+ for (int i = 0; i < 3; i++)
+ {
+ outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[1024], true, false));
+ }
+
+ outBuffer.setOutputStream(output);
+
+ final CountDownLatch waiting = new CountDownLatch(1);
+
+ Thread twaiter = new Thread("twaiter")
+ {
+ public void run()
+ {
+ try
+ {
+ outBuffer.waitCompletion(0);
+ waiting.countDown();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ errors.incrementAndGet();
+ }
+ }
+ };
+
+ twaiter.setDaemon(true);
+ twaiter.start();
+
+ assertTrue(done1.await(10, TimeUnit.SECONDS));
+
+ assertEquals(3, count.get());
+ assertEquals(1024 * 3, totalBytes.get());
+
+ for (int i = 0; i < 8; i++)
+ {
+ outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[1024], true, false));
+ }
+
+ assertEquals(1, waiting.getCount());
+
+ outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[123], false, false));
+
+ assertTrue(done2.await(10, TimeUnit.SECONDS));
+
+ assertTrue(waiting.await(10, TimeUnit.SECONDS));
+
+ assertEquals(12, count.get());
+ assertEquals(1024 * 11 + 123, totalBytes.get());
+
+ treader.join();
+
+ twaiter.join();
+
+ assertEquals(0, errors.get());
+
+ }
+
+ public void testErrorOnSetStreaming() throws Exception
+ {
+ long start = System.currentTimeMillis();
+ final LargeMessageBuffer outBuffer = new LargeMessageBuffer(new FakeConsumerInternal(), 5, 30);
+
+ outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[] { 0, 1, 2, 3, 4 }, true, false));
+
+
+ final CountDownLatch latchBytesWritten1 = new CountDownLatch(5);
+ final CountDownLatch latchBytesWritten2 = new CountDownLatch(10);
+
+ outBuffer.setOutputStream(new OutputStream()
+ {
+ @Override
+ public void write(int b) throws IOException
+ {
+ latchBytesWritten1.countDown();
+ latchBytesWritten2.countDown();
+ }
+ });
+
+
+ latchBytesWritten1.await();
+
+ try
+ {
+ outBuffer.readByte();
+ fail("supposed to throw an exception");
+ }
+ catch (IllegalAccessError ignored)
+ {
+ }
+
+
+ assertTrue("It waited too much", System.currentTimeMillis() - start < 30000);
+
+ }
+
+ /**
+ * @return
+ */
+ private LargeMessageBuffer create15BytesSample() throws Exception
+ {
+ return splitBuffer(5, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
+ }
+
+ private LargeMessageBuffer createBufferWithIntegers(int splitFactor, int... values) throws Exception
+ {
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream(values.length * 4);
+ DataOutputStream dataOut = new DataOutputStream(byteOut);
+
+ for (int value : values)
+ {
+ dataOut.writeInt(value);
+ }
+
+ return splitBuffer(splitFactor, byteOut.toByteArray());
+ }
+
+ private LargeMessageBuffer createBufferWithLongs(int splitFactor, long... values) throws Exception
+ {
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream(values.length * 8);
+ DataOutputStream dataOut = new DataOutputStream(byteOut);
+
+ for (long value : values)
+ {
+ dataOut.writeLong(value);
+ }
+
+ return splitBuffer(splitFactor, byteOut.toByteArray());
+ }
+
+ private LargeMessageBuffer splitBuffer(int splitFactor, byte[] bytes) throws Exception
+ {
+ LargeMessageBuffer outBuffer = new LargeMessageBuffer(new FakeConsumerInternal(), bytes.length, 5);
+
+ ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+
+ while (true)
+ {
+ byte[] splitElement = new byte[splitFactor];
+ int size = input.read(splitElement);
+ if (size <= 0)
+ {
+ break;
+ }
+
+ if (size < splitFactor)
+ {
+ byte[] newSplit = new byte[size];
+ System.arraycopy(splitElement, 0, newSplit, 0, size);
+
+ outBuffer.addPacket(new SessionReceiveContinuationMessage(1, newSplit, input.available() > 0, false));
+ }
+ else
+ {
+ outBuffer.addPacket(new SessionReceiveContinuationMessage(1, splitElement, input.available() > 0, false));
+ }
+ }
+
+ return outBuffer;
+
+ }
+
+ /**
+ * @param bytes
+ */
+ private void validateAgainstSample(byte[] bytes)
+ {
+ for (int i = 1; i <= 15; i++)
+ {
+ assertEquals(i, bytes[i - 1]);
+ }
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+ static class FakeConsumerInternal implements ClientConsumerInternal
+ {
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#acknowledge(org.jboss.messaging.core.client.ClientMessage)
+ */
+ public void acknowledge(ClientMessage message) throws MessagingException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#cleanUp()
+ */
+ public void cleanUp() throws MessagingException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#clear()
+ */
+ public void clear()
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#flowControl(int, boolean)
+ */
+ public void flowControl(int messageBytes, boolean isLargeMessage) throws MessagingException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#flushAcks()
+ */
+ public void flushAcks() throws MessagingException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#getBufferSize()
+ */
+ public int getBufferSize()
+ {
+
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#getClientWindowSize()
+ */
+ public int getClientWindowSize()
+ {
+
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#getCreditsToSend()
+ */
+ public int getCreditsToSend()
+ {
+
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#getID()
+ */
+ public long getID()
+ {
+
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#handleLargeMessage(org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveMessage)
+ */
+ public void handleLargeMessage(SessionReceiveMessage largeMessageHeader) throws Exception
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#handleLargeMessageContinuation(org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage)
+ */
+ public void handleLargeMessageContinuation(SessionReceiveContinuationMessage continuation) throws Exception
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#handleMessage(org.jboss.messaging.core.client.impl.ClientMessageInternal)
+ */
+ public void handleMessage(ClientMessageInternal message) throws Exception
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#isFileConsumer()
+ */
+ public boolean isFileConsumer()
+ {
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#start()
+ */
+ public void start()
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#stop()
+ */
+ public void stop() throws MessagingException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientConsumer#close()
+ */
+ public void close() throws MessagingException
+ {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientConsumer#getLastException()
+ */
+ public Exception getLastException()
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientConsumer#getMessageHandler()
+ */
+ public MessageHandler getMessageHandler() throws MessagingException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientConsumer#isClosed()
+ */
+ public boolean isClosed()
+ {
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientConsumer#receive()
+ */
+ public ClientMessage receive() throws MessagingException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientConsumer#receive(long)
+ */
+ public ClientMessage receive(long timeout) throws MessagingException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientConsumer#receiveImmediate()
+ */
+ public ClientMessage receiveImmediate() throws MessagingException
+ {
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.client.ClientConsumer#setMessageHandler(org.jboss.messaging.core.client.MessageHandler)
+ */
+ public void setMessageHandler(MessageHandler handler) throws MessagingException
+ {
+
+ }
+
+ }
+
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -22,6 +22,7 @@
package org.jboss.messaging.tests.unit.core.postoffice.impl;
+import java.io.InputStream;
import java.util.Set;
import javax.transaction.xa.Xid;
@@ -724,6 +725,21 @@
}
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.message.Message#getBodyInputStream()
+ */
+ public InputStream getBodyInputStream()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.messaging.core.message.Message#setBodyInputStream(java.io.InputStream)
+ */
+ public void setBodyInputStream(InputStream stream)
+ {
+ }
+
}
class FakeFilter implements Filter
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -46,19 +46,19 @@
public void connectionCreated(Connection connection)
{
- // TODO Auto-generated method stub
+
}
public void connectionDestroyed(Object connectionID)
{
- // TODO Auto-generated method stub
+
}
public void connectionException(Object connectionID, MessagingException me)
{
- // TODO Auto-generated method stub
+
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeConsumer.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeConsumer.java 2009-04-14 19:33:08 UTC (rev 6428)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeConsumer.java 2009-04-15 04:54:59 UTC (rev 6429)
@@ -60,7 +60,6 @@
public Filter getFilter()
{
- // TODO Auto-generated method stub
return null;
}
More information about the jboss-cvs-commits
mailing list