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}.
*/
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 {
return uploadStream(message, new FileInputStream(file));
}
public FTPBlobUploadStrategy(BlobTransferPolicy transferPolicy) throws MalformedURLException {
super(transferPolicy);
}
public URL uploadStream(ActiveMQBlobMessage message, InputStream in)
throws JMSException, IOException {
@Override
public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException {
return uploadStream(message, new FileInputStream(file));
}
FTPClient ftp = createFTP();
try {
String path = url.getPath();
@Override
public URL uploadStream(ActiveMQBlobMessage message, InputStream in)
throws JMSException, IOException {
FTPClient ftp = createFTP();
try {
String path = url.getPath();
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);
String url;
if(!ftp.changeWorkingDirectory(workingDir)) {
url = this.url.toString().replaceFirst(this.url.getPath(), "")+"/";
url = this.url.toString().replaceFirst(this.url.getPath(), "")+"/";
} else {
url = this.url.toString();
url = this.url.toString();
}
if (!ftp.storeFile(filename, in)) {
throw new JMSException("FTP store failed: " + ftp.getReplyString());
}
return new URL(url + filename);
} finally {
ftp.quit();
ftp.disconnect();
}
}
if (!ftp.storeFile(filename, in)) {
throw new JMSException("FTP store failed: " + ftp.getReplyString());
}
return new URL(url + filename);
} finally {
ftp.quit();
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
* message is marshaled on a transport; so is only for in-JVM changes to
* accommodate foreign JMS message IDs
* Sets the transient text view of the message which will be ignored if the message is marshaled on a transport; so
* is only for in-JVM changes to accommodate foreign JMS message IDs
*/
public void setTextView(String key) {
this.textView = key;
@ -107,20 +106,20 @@ public class MessageId implements DataStructure, Comparable<MessageId> {
return false;
}
MessageId id = (MessageId)o;
MessageId id = (MessageId) o;
return producerSequenceId == id.producerSequenceId && producerId.equals(id.producerId);
}
@Override
public int hashCode() {
if (hashCode == 0) {
hashCode = producerId.hashCode() ^ (int)producerSequenceId;
hashCode = producerId.hashCode() ^ (int) producerSequenceId;
}
return hashCode;
}
public String toProducerKey() {
if( textView==null ) {
if (textView == null) {
return toString();
} else {
return producerId.toString() + ":" + producerSequenceId;
@ -130,11 +129,11 @@ public class MessageId implements DataStructure, Comparable<MessageId> {
@Override
public String toString() {
if (key == null) {
if( textView!=null ) {
if( textView.startsWith("ID:") ) {
if (textView != null) {
if (textView.startsWith("ID:")) {
key = textView;
} else {
key = "ID:"+textView;
key = "ID:" + textView;
}
} else {
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
* by the message stores.
* @return a locator which aids a message store in loading a message faster. Only used by the message stores.
*/
public Object getDataLocator() {
return dataLocator.get();
}
/**
* Sets a locator which aids a message store in loading a message faster. Only used
* by the message stores.
* Sets a locator which aids a message store in loading a message faster. Only used by the message stores.
*/
public void setDataLocator(Object value) {
this.dataLocator.set(value);

View File

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