You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/04/05 23:39:44 UTC
svn commit: r525971 - in /activemq/activemq-cpp/trunk/activemq-cpp/src:
main/activemq/connector/stomp/commands/
test/activemq/connector/openwire/commands/
test/activemq/connector/stomp/commands/
Author: tabish
Date: Thu Apr 5 14:39:43 2007
New Revision: 525971
URL: http://svn.apache.org/viewvc?view=rev&rev=525971
Log:
https://issues.apache.org/activemq/browse/AMQCPP-96
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.h
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/MessageCommandTest.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.cpp?view=diff&rev=525971&r1=525970&r2=525971
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.cpp Thu Apr 5 14:39:43 2007
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
#include "CommandConstants.h"
#include <stdio.h>
@@ -44,7 +44,7 @@
////////////////////////////////////////////////////////////////////////////////
CommandConstants::StaticInitializer::StaticInitializer(){
-
+
stompHeaders[HEADER_DESTINATION] = "destination";
stompHeaders[HEADER_TRANSACTIONID] = "transaction";
stompHeaders[HEADER_CONTENTLENGTH] = "content-length";
@@ -67,8 +67,6 @@
stompHeaders[HEADER_REPLYTO] = "reply-to";
stompHeaders[HEADER_TYPE] = "type";
stompHeaders[HEADER_AMQMSGTYPE] = "amq-msg-type";
- stompHeaders[HEADER_JMSXGROUPID] = "JMSXGroupID";
- stompHeaders[HEADER_JMSXGROUPSEQNO] = "JMSXGroupSeq";
stompHeaders[HEADER_SELECTOR] = "selector";
stompHeaders[HEADER_DISPATCH_ASYNC] = "activemq.dispatchAsync";
stompHeaders[HEADER_EXCLUSIVE] = "activemq.exclusive";
@@ -105,11 +103,11 @@
for( int ix=0; ix<NUM_STOMP_HEADERS; ++ix ){
stompHeaderMap[stompHeaders[ix]] = (StompHeader)ix;
}
-
+
for( int ix=0; ix<NUM_COMMANDS; ++ix ){
commandMap[commands[ix]] = (CommandId)ix;
}
-
+
for( int ix=0; ix<NUM_ACK_MODES; ++ix ){
ackModeMap[ackModes[ix]] = (AckMode)ix;
}
@@ -125,7 +123,7 @@
{
std::size_t qpos = dest.find(queuePrefix);
std::size_t tpos = dest.find(topicPrefix);
-
+
if(tpos == 0)
{
return new StompTopic(dest.substr(strlen(topicPrefix)));
@@ -140,6 +138,6 @@
__FILE__, __LINE__,
"CommandConstants::toDestination - Not a valid Stomp Dest [%s]", dest.c_str());
}
-}
+}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.h?view=diff&rev=525971&r1=525970&r2=525971
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/CommandConstants.h Thu Apr 5 14:39:43 2007
@@ -27,10 +27,10 @@
namespace connector{
namespace stomp{
namespace commands{
-
- class CommandConstants{
+
+ class CommandConstants{
public:
-
+
enum CommandId{
CONNECT,
CONNECTED,
@@ -47,7 +47,7 @@
RECEIPT,
NUM_COMMANDS
};
-
+
enum StompHeader{
HEADER_DESTINATION,
HEADER_TRANSACTIONID,
@@ -69,8 +69,6 @@
HEADER_REPLYTO,
HEADER_TYPE,
HEADER_AMQMSGTYPE,
- HEADER_JMSXGROUPID,
- HEADER_JMSXGROUPSEQNO,
HEADER_DISPATCH_ASYNC,
HEADER_EXCLUSIVE,
HEADER_MAXPENDINGMSGLIMIT,
@@ -87,98 +85,98 @@
HEADER_ID,
HEADER_SUBSCRIPTION,
NUM_STOMP_HEADERS
- };
-
+ };
+
enum AckMode{
ACK_CLIENT,
ACK_AUTO,
NUM_ACK_MODES
};
-
+
enum MessageType
{
TEXT,
BYTES,
NUM_MSG_TYPES
};
-
+
static const char* queuePrefix;
static const char* topicPrefix;
-
+
static const std::string& toString( const CommandId cmd ){
return StaticInitializer::commands[cmd];
}
-
- static CommandId toCommandId( const std::string& cmd ){
- std::map<std::string, CommandId>::iterator iter =
+
+ static CommandId toCommandId( const std::string& cmd ){
+ std::map<std::string, CommandId>::iterator iter =
StaticInitializer::commandMap.find(cmd);
if( iter == StaticInitializer::commandMap.end() ){
return NUM_COMMANDS;
}
-
+
return iter->second;
}
-
+
static bool isCommandId( const std::string& str ){
- std::map<std::string, CommandId>::iterator iter =
+ std::map<std::string, CommandId>::iterator iter =
StaticInitializer::commandMap.find(str);
return iter != StaticInitializer::commandMap.end();
- }
-
+ }
+
static std::string toString( const StompHeader header ){
return StaticInitializer::stompHeaders[header];
}
-
- static StompHeader toStompHeader( const std::string& header ){
-
- std::map<std::string, StompHeader>::iterator iter =
+
+ static StompHeader toStompHeader( const std::string& header ){
+
+ std::map<std::string, StompHeader>::iterator iter =
StaticInitializer::stompHeaderMap.find(header);
if( iter == StaticInitializer::stompHeaderMap.end() ){
return NUM_STOMP_HEADERS;
}
-
- return iter->second;
+
+ return iter->second;
}
-
+
static bool isStompHeader( const std::string& str ){
- std::map<std::string, StompHeader>::iterator iter =
+ std::map<std::string, StompHeader>::iterator iter =
StaticInitializer::stompHeaderMap.find(str);
return iter != StaticInitializer::stompHeaderMap.end();
- }
-
+ }
+
static std::string toString( const AckMode mode ){
return StaticInitializer::ackModes[mode];
}
-
+
static AckMode toAckMode( const std::string& mode ){
- std::map<std::string, AckMode>::iterator iter =
+ std::map<std::string, AckMode>::iterator iter =
StaticInitializer::ackModeMap.find(mode);
if( iter == StaticInitializer::ackModeMap.end() ){
return NUM_ACK_MODES;
}
-
+
return iter->second;
- }
-
+ }
+
static std::string toString( const MessageType type ){
return StaticInitializer::msgTypes[type];
}
-
+
static MessageType toMessageType( const std::string& type ){
- std::map<std::string, MessageType>::iterator iter =
+ std::map<std::string, MessageType>::iterator iter =
StaticInitializer::msgTypeMap.find(type);
if( iter == StaticInitializer::msgTypeMap.end() ){
return NUM_MSG_TYPES;
}
-
+
return iter->second;
- }
+ }
static cms::Destination* toDestination( const std::string& dest )
throw ( exceptions::IllegalArgumentException );
@@ -187,7 +185,7 @@
public:
StaticInitializer();
virtual ~StaticInitializer(){}
-
+
static std::string stompHeaders[NUM_STOMP_HEADERS];
static std::string commands[NUM_COMMANDS];
static std::string ackModes[NUM_ACK_MODES];
@@ -197,12 +195,12 @@
static std::map<std::string, AckMode> ackModeMap;
static std::map<std::string, MessageType> msgTypeMap;
};
-
+
private:
-
- static StaticInitializer staticInits;
+
+ static StaticInitializer staticInits;
};
-
+
}}}}
#endif /*ACTIVEMQ_CONNECTOR_STOMP_COMMANDS_COMMANDCONSTANTS_H_*/
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp?view=diff&rev=525971&r1=525970&r2=525971
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/commands/ActiveMQMessageTest.cpp Thu Apr 5 14:39:43 2007
@@ -36,20 +36,20 @@
MyAckHandler ackHandler;
CPPUNIT_ASSERT( myMessage.getDataStructureType() == ActiveMQMessage::ID_ACTIVEMQMESSAGE );
-
+
myMessage.setAckHandler( &ackHandler );
myMessage.acknowledge();
-
+
CPPUNIT_ASSERT( ackHandler.wasAcked == true );
-
+
CPPUNIT_ASSERT( myMessage.getPropertyNames().size() == 0 );
CPPUNIT_ASSERT( myMessage.propertyExists( "something" ) == false );
-
+
try {
myMessage.getBooleanProperty( "somethingElse" );
CPPUNIT_ASSERT( false );
} catch(...) {}
-
+
myMessage.setBooleanProperty( "boolean", false );
myMessage.setByteProperty( "byte", 60 );
myMessage.setDoubleProperty( "double", 642.5643 );
@@ -58,7 +58,7 @@
myMessage.setLongProperty( "long", 0xFFFFFFFF0000000LL );
myMessage.setShortProperty( "short", 512 );
myMessage.setStringProperty( "string", "This is a test String" );
-
+
CPPUNIT_ASSERT( myMessage.getBooleanProperty( "boolean" ) == false );
CPPUNIT_ASSERT( myMessage.getByteProperty( "byte" ) == 60 );
CPPUNIT_ASSERT( myMessage.getDoubleProperty( "double" ) == 642.5643 );
@@ -67,4 +67,7 @@
CPPUNIT_ASSERT( myMessage.getLongProperty( "long" ) == 0xFFFFFFFF0000000LL );
CPPUNIT_ASSERT( myMessage.getShortProperty( "short" ) == 512 );
CPPUNIT_ASSERT( myMessage.getStringProperty( "string" ) == "This is a test String" );
+
+ myMessage.setStringProperty( "JMSXGroupID", "hello" );
+ CPPUNIT_ASSERT( myMessage.getStringProperty( "JMSXGroupID" ) == "hello" );
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/MessageCommandTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/MessageCommandTest.h?view=diff&rev=525971&r1=525970&r2=525971
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/MessageCommandTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/MessageCommandTest.h Thu Apr 5 14:39:43 2007
@@ -43,39 +43,39 @@
CPPUNIT_TEST_SUITE_END();
protected:
-
+
class TestAckHandler : public core::ActiveMQAckHandler
{
public:
-
+
TestAckHandler(void) { wasAcked = false; }
virtual ~TestAckHandler(void) {}
-
+
virtual void acknowledgeMessage( const core::ActiveMQMessage* message AMQCPP_UNUSED)
- throw ( cms::CMSException )
+ throw ( cms::CMSException )
{
wasAcked = true;
}
-
+
public:
-
+
bool wasAcked;
};
-
+
public:
- MessageCommandTest() {}
- virtual ~MessageCommandTest() {}
+ MessageCommandTest() {}
+ virtual ~MessageCommandTest() {}
void test(void)
{
TestAckHandler ackHandler;
MessageCommand cmd;
- CPPUNIT_ASSERT( cmd.getStompCommandId() ==
+ CPPUNIT_ASSERT( cmd.getStompCommandId() ==
CommandConstants::SEND );
-
+
CPPUNIT_ASSERT( cmd.isResponseRequired() == false );
cmd.setResponseRequired( true );
cmd.setCommandId( 123 );
@@ -85,53 +85,53 @@
CPPUNIT_ASSERT( cmd.getCorrelationId() == 0 );
CPPUNIT_ASSERT( cmd.getTransactionId() == "" );
cmd.setTransactionId( "ID:123456" );
- CPPUNIT_ASSERT( std::string( cmd.getTransactionId() ) ==
+ CPPUNIT_ASSERT( std::string( cmd.getTransactionId() ) ==
"ID:123456" );
StompTopic topic("testTopic");
cmd.setCMSDestination( &topic );
-
+
StompFrame* frame = cmd.marshal().clone();
-
+
CPPUNIT_ASSERT( frame != NULL );
-
+
MessageCommand cmd1( frame );
-
+
CPPUNIT_ASSERT( cmd.getCommandId() == cmd1.getCommandId() );
CPPUNIT_ASSERT( cmd.getStompCommandId() == CommandConstants::SEND );
CPPUNIT_ASSERT( cmd.isResponseRequired() == cmd1.isResponseRequired() );
CPPUNIT_ASSERT( cmd.getCorrelationId() == cmd1.getCorrelationId() );
CPPUNIT_ASSERT( std::string(cmd.getTransactionId()) == cmd1.getTransactionId() );
-
+
cmd.setAckHandler( &ackHandler );
cmd.acknowledge();
CPPUNIT_ASSERT( ackHandler.wasAcked == true );
-
- CPPUNIT_ASSERT(
+
+ CPPUNIT_ASSERT(
cmd.getProperties().hasProperty( "test" ) == false );
cmd.getProperties().setProperty( "test", "value" );
- CPPUNIT_ASSERT(
+ CPPUNIT_ASSERT(
cmd.getProperties().hasProperty( "test" ) == true );
- CPPUNIT_ASSERT(
- std::string( cmd.getProperties().getProperty( "test" ) ) ==
+ CPPUNIT_ASSERT(
+ std::string( cmd.getProperties().getProperty( "test" ) ) ==
"value" );
-
+
CPPUNIT_ASSERT( cmd.getCMSCorrelationID() == "" );
cmd.setCMSCorrelationID( "ID:1234567" );
- CPPUNIT_ASSERT( std::string( cmd.getCMSCorrelationID() ) ==
+ CPPUNIT_ASSERT( std::string( cmd.getCMSCorrelationID() ) ==
"ID:1234567" );
- CPPUNIT_ASSERT( cmd.getCMSDeliveryMode() ==
+ CPPUNIT_ASSERT( cmd.getCMSDeliveryMode() ==
cms::DeliveryMode::PERSISTENT );
cmd.setCMSDeliveryMode( cms::DeliveryMode::NON_PERSISTENT );
- CPPUNIT_ASSERT( cmd.getCMSDeliveryMode() ==
+ CPPUNIT_ASSERT( cmd.getCMSDeliveryMode() ==
cms::DeliveryMode::NON_PERSISTENT );
- CPPUNIT_ASSERT( cmd.getCMSDestination()->toProviderString() ==
+ CPPUNIT_ASSERT( cmd.getCMSDestination()->toProviderString() ==
"/topic/testTopic" );
CPPUNIT_ASSERT( cmd.getCMSExpiration() == 0 );
cmd.setCMSExpiration( 123 );
CPPUNIT_ASSERT( cmd.getCMSExpiration() == 123 );
CPPUNIT_ASSERT( cmd.getCMSMessageID() == "" );
cmd.setCMSMessageID( "ID:1234567" );
- CPPUNIT_ASSERT( std::string( cmd.getCMSMessageID() ) ==
+ CPPUNIT_ASSERT( std::string( cmd.getCMSMessageID() ) ==
"ID:1234567" );
CPPUNIT_ASSERT( cmd.getCMSPriority() == 0 );
cmd.setCMSPriority( 5 );
@@ -141,21 +141,21 @@
CPPUNIT_ASSERT( cmd.getCMSRedelivered() == true );
CPPUNIT_ASSERT( cmd.getCMSReplyTo() == NULL );
cmd.setCMSReplyTo( &topic );
- CPPUNIT_ASSERT( cmd.getCMSReplyTo()->toProviderString() ==
+ CPPUNIT_ASSERT( cmd.getCMSReplyTo()->toProviderString() ==
"/topic/testTopic" );
CPPUNIT_ASSERT( cmd.getCMSTimestamp() == 0 );
cmd.setCMSTimestamp( 123 );
CPPUNIT_ASSERT( cmd.getCMSTimestamp() == 123 );
CPPUNIT_ASSERT( cmd.getCMSType() == "" );
cmd.setCMSType( "test" );
- CPPUNIT_ASSERT( std::string( cmd.getCMSType() ) ==
+ CPPUNIT_ASSERT( std::string( cmd.getCMSType() ) ==
"test" );
CPPUNIT_ASSERT( cmd.getRedeliveryCount() == 0 );
cmd.setRedeliveryCount( 123 );
CPPUNIT_ASSERT( cmd.getRedeliveryCount() == 123 );
cms::Message* cmd2 = cmd.clone();
-
+
CPPUNIT_ASSERT( cmd.getCMSPriority() == cmd2->getCMSPriority() );
CPPUNIT_ASSERT( cmd.getCMSTimestamp() == cmd2->getCMSTimestamp() );
CPPUNIT_ASSERT( cmd.getCMSExpiration() == cmd2->getCMSExpiration() );
@@ -165,14 +165,14 @@
CPPUNIT_ASSERT( std::string(cmd.getCMSType()) == cmd2->getCMSType() );
CPPUNIT_ASSERT( std::string(cmd.getCMSMessageID()) == cmd2->getCMSMessageID() );
- core::ActiveMQMessage* message =
+ core::ActiveMQMessage* message =
dynamic_cast< core::ActiveMQMessage* >( cmd2 );
-
+
CPPUNIT_ASSERT( message != NULL );
- CPPUNIT_ASSERT( cmd.getRedeliveryCount() ==
+ CPPUNIT_ASSERT( cmd.getRedeliveryCount() ==
message->getRedeliveryCount() );
-
- StompCommand* cmd4 =
+
+ StompCommand* cmd4 =
dynamic_cast< StompCommand* >( cmd2 );
CPPUNIT_ASSERT( cmd4 != NULL );
@@ -180,7 +180,7 @@
CPPUNIT_ASSERT( cmd.getStompCommandId() == cmd4->getStompCommandId() );
CPPUNIT_ASSERT( cmd.isResponseRequired() == cmd4->isResponseRequired() );
CPPUNIT_ASSERT( cmd.getCorrelationId() == cmd4->getCorrelationId() );
- CPPUNIT_ASSERT( std::string(cmd.getTransactionId()) ==
+ CPPUNIT_ASSERT( std::string(cmd.getTransactionId()) ==
cmd4->getTransactionId() );
delete cmd2;
@@ -188,43 +188,46 @@
void testSetProperties(){
MessageCommand cmd;
-
+
cmd.setBooleanProperty( "bool", true );
CPPUNIT_ASSERT( cmd.getBooleanProperty( "bool" ) == true );
-
+
cmd.setByteProperty( "byte", 1 );
CPPUNIT_ASSERT( cmd.getByteProperty( "byte" ) == 1 );
-
+
cmd.setDoubleProperty( "double", 2.2 );
CPPUNIT_ASSERT( cmd.getDoubleProperty( "double" ) == 2.2 );
-
+
cmd.setFloatProperty( "float", 3.3f );
CPPUNIT_ASSERT( cmd.getFloatProperty( "float" ) == 3.3f );
-
+
cmd.setIntProperty( "int", 4 );
CPPUNIT_ASSERT( cmd.getIntProperty( "int" ) == 4 );
-
+
cmd.setLongProperty( "long", 5LL );
CPPUNIT_ASSERT( cmd.getLongProperty( "long" ) == 5LL );
-
+
cmd.setShortProperty( "short", 6 );
CPPUNIT_ASSERT( cmd.getShortProperty( "short" ) == 6 );
-
+
cmd.setStringProperty( "string", "hello" );
- CPPUNIT_ASSERT( cmd.getStringProperty( "string" ) == "hello" );
+ CPPUNIT_ASSERT( cmd.getStringProperty( "string" ) == "hello" );
+
+ cmd.setStringProperty( "JMSXGroupID", "hello" );
+ CPPUNIT_ASSERT( cmd.getStringProperty( "JMSXGroupID" ) == "hello" );
}
void testFailedGetProperties(){
MessageCommand cmd;
-
- // Test getting a string property that doesn't exist.
+
+ // Test getting a string property that doesn't exist.
try {
std::string str = cmd.getStringProperty( "text" );
CPPUNIT_ASSERT(false);
} catch( cms::CMSException& e){
}
-
- // Test getting a bool property that doesn't exist.
+
+ // Test getting a bool property that doesn't exist.
try {
cmd.getBooleanProperty( "text" );
CPPUNIT_ASSERT(false);
@@ -235,57 +238,57 @@
try{
cmd.getIntProperty("string");
CPPUNIT_ASSERT(false);
- } catch( cms::CMSException& e ){
+ } catch( cms::CMSException& e ){
}
-
+
// Test failed extraction
try{
cmd.setStringProperty("string", "hello");
cmd.getIntProperty("string");
CPPUNIT_ASSERT(false);
- } catch( cms::CMSException& e ){
+ } catch( cms::CMSException& e ){
}
- }
-
+ }
+
void testGetPropertyNames(){
-
+
MessageCommand cmd;
-
+
std::vector<std::string> names = cmd.getPropertyNames();
CPPUNIT_ASSERT( names.size() == 0 );
-
+
cmd.setIntProperty( "int1", 1 );
names = cmd.getPropertyNames();
CPPUNIT_ASSERT( names.size() == 1 );
CPPUNIT_ASSERT( names[0] == "int1" );
-
+
cmd.setIntProperty( "int2", 2 );
names = cmd.getPropertyNames();
CPPUNIT_ASSERT( names.size() == 2 );
CPPUNIT_ASSERT( names[0] == "int1" || names[1] == "int1" );
CPPUNIT_ASSERT( names[0] == "int2" || names[1] == "int2" );
-
+
// Make sure headers aren't included in the property names.
cmd.setCMSExpiration( 10000 );
names = cmd.getPropertyNames();
CPPUNIT_ASSERT( names.size() == 2 );
}
-
+
void testClearProperties(){
MessageCommand cmd;
-
+
cmd.setIntProperty( "int1", 1 );
cmd.setIntProperty( "int2", 2 );
-
+
CPPUNIT_ASSERT( cmd.propertyExists( "int1" ) == true );
CPPUNIT_ASSERT( cmd.propertyExists( "int2" ) == true );
-
+
cmd.clearProperties();
-
+
CPPUNIT_ASSERT( cmd.propertyExists( "int1" ) == false );
- CPPUNIT_ASSERT( cmd.propertyExists( "int2" ) == false );
+ CPPUNIT_ASSERT( cmd.propertyExists( "int2" ) == false );
}
-
+
};
}}}}