Fix test failure after recent MessageId changes.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1489994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2013-06-05 18:29:35 +00:00
parent 1f5694ed60
commit 01cda8582a
3 changed files with 43 additions and 45 deletions

View File

@ -32,41 +32,43 @@ import org.apache.commons.net.ftp.FTPClient;
* A FTP implementation of {@link BlobUploadStrategy}. * A FTP implementation of {@link BlobUploadStrategy}.
*/ */
public class FTPBlobUploadStrategy extends FTPStrategy implements BlobUploadStrategy { public class FTPBlobUploadStrategy extends FTPStrategy implements BlobUploadStrategy {
public FTPBlobUploadStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException {
super(transferPolicy);
}
public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException { public FTPBlobUploadStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException {
return uploadStream(message, new FileInputStream(file)); super(transferPolicy);
} }
public URL uploadStream(ActiveMQBlobMessage message, InputStream in) @Override
throws JMSException, IOException { public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException {
return uploadStream(message, new FileInputStream(file));
}
FTPClient ftp = createFTP(); @Override
try { public URL uploadStream(ActiveMQBlobMessage message, InputStream in)
String path = url.getPath(); throws JMSException, IOException {
FTPClient ftp = createFTP();
try {
String path = url.getPath();
String workingDir = path.substring(0, path.lastIndexOf("/")); String workingDir = path.substring(0, path.lastIndexOf("/"));
String filename = message.getMessageId().toString().replaceAll(":", "_"); String filename = message.getMessageId().toString().replaceAll(":", "_");
ftp.setFileType(FTPClient.BINARY_FILE_TYPE); ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
String url; String url;
if(!ftp.changeWorkingDirectory(workingDir)) { if(!ftp.changeWorkingDirectory(workingDir)) {
url = this.url.toString().replaceFirst(this.url.getPath(), "")+"/"; url = this.url.toString().replaceFirst(this.url.getPath(), "")+"/";
} else { } else {
url = this.url.toString(); url = this.url.toString();
} }
if (!ftp.storeFile(filename, in)) { if (!ftp.storeFile(filename, in)) {
throw new JMSException("FTP store failed: " + ftp.getReplyString()); throw new JMSException("FTP store failed: " + ftp.getReplyString());
} }
return new URL(url + filename); return new URL(url + filename);
} finally { } finally {
ftp.quit(); ftp.quit();
ftp.disconnect(); ftp.disconnect();
} }
} }
} }

View File

@ -77,9 +77,8 @@ public class MessageId implements DataStructure, Comparable<MessageId> {
} }
/** /**
* Sets the transient text view of the message which will be ignored if the * Sets the transient text view of the message which will be ignored if the message is marshaled on a transport; so
* message is marshaled on a transport; so is only for in-JVM changes to * is only for in-JVM changes to accommodate foreign JMS message IDs
* accommodate foreign JMS message IDs
*/ */
public void setTextView(String key) { public void setTextView(String key) {
this.textView = key; this.textView = key;
@ -107,20 +106,20 @@ public class MessageId implements DataStructure, Comparable<MessageId> {
return false; return false;
} }
MessageId id = (MessageId)o; MessageId id = (MessageId) o;
return producerSequenceId == id.producerSequenceId && producerId.equals(id.producerId); return producerSequenceId == id.producerSequenceId && producerId.equals(id.producerId);
} }
@Override @Override
public int hashCode() { public int hashCode() {
if (hashCode == 0) { if (hashCode == 0) {
hashCode = producerId.hashCode() ^ (int)producerSequenceId; hashCode = producerId.hashCode() ^ (int) producerSequenceId;
} }
return hashCode; return hashCode;
} }
public String toProducerKey() { public String toProducerKey() {
if( textView==null ) { if (textView == null) {
return toString(); return toString();
} else { } else {
return producerId.toString() + ":" + producerSequenceId; return producerId.toString() + ":" + producerSequenceId;
@ -130,11 +129,11 @@ public class MessageId implements DataStructure, Comparable<MessageId> {
@Override @Override
public String toString() { public String toString() {
if (key == null) { if (key == null) {
if( textView!=null ) { if (textView != null) {
if( textView.startsWith("ID:") ) { if (textView.startsWith("ID:")) {
key = textView; key = textView;
} else { } else {
key = "ID:"+textView; key = "ID:" + textView;
} }
} else { } else {
key = producerId.toString() + ":" + producerSequenceId; key = producerId.toString() + ":" + producerSequenceId;
@ -207,16 +206,14 @@ public class MessageId implements DataStructure, Comparable<MessageId> {
} }
/** /**
* @return a locator which aids a message store in loading a message faster. Only used * @return a locator which aids a message store in loading a message faster. Only used by the message stores.
* by the message stores.
*/ */
public Object getDataLocator() { public Object getDataLocator() {
return dataLocator.get(); return dataLocator.get();
} }
/** /**
* Sets a locator which aids a message store in loading a message faster. Only used * Sets a locator which aids a message store in loading a message faster. Only used by the message stores.
* by the message stores.
*/ */
public void setDataLocator(Object value) { public void setDataLocator(Object value) {
this.dataLocator.set(value); this.dataLocator.set(value);

View File

@ -26,7 +26,6 @@ import javax.jms.Session;
import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQSession; import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.command.ActiveMQBlobMessage; import org.apache.activemq.command.ActiveMQBlobMessage;
import org.apache.activemq.command.MessageId;
public class FTPBlobUploadStrategyTest extends FTPTestSupport { public class FTPBlobUploadStrategyTest extends FTPTestSupport {
@ -43,10 +42,10 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport {
((ActiveMQConnection)connection).setCopyMessageOnSend(false); ((ActiveMQConnection)connection).setCopyMessageOnSend(false);
ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file); ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file);
message.setMessageId(new MessageId("testmessage")); message.setJMSMessageID("testmessage");
message.onSend(); message.onSend();
assertEquals(ftpUrl + "testmessage", message.getURL().toString()); assertEquals(ftpUrl + "ID_testmessage", message.getURL().toString());
File uploaded = new File(ftpHomeDirFile, "testmessage"); File uploaded = new File(ftpHomeDirFile, "ID_testmessage");
assertTrue("File doesn't exists", uploaded.exists()); assertTrue("File doesn't exists", uploaded.exists());
} }
@ -63,7 +62,7 @@ public class FTPBlobUploadStrategyTest extends FTPTestSupport {
((ActiveMQConnection)connection).setCopyMessageOnSend(false); ((ActiveMQConnection)connection).setCopyMessageOnSend(false);
ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file); ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession)session).createBlobMessage(file);
message.setMessageId(new MessageId("testmessage")); message.setJMSMessageID("testmessage");
try { try {
message.onSend(); message.onSend();
} catch (JMSException e) { } catch (JMSException e) {