use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class FailoverForwardingServiceTest method test.
/**
* Testing whether the failover forwarding service is successfully storing
* the message in the queue
*
* @throws Exception
*/
@Test
public void test() throws Exception {
JmsStore jmsStore = new JmsStore();
Map<String, Object> parameters = new HashMap<>();
parameters.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
parameters.put("java.naming.provider.url", "tcp://127.0.0.1:61616");
jmsStore.setParameters(parameters);
jmsStore.setName("JMSStore");
MessageProcessor messageProcessor = new FailoverScheduledMessageForwardingProcessor();
Map<String, Object> parametersPro = new HashMap<>();
parametersPro.put("message.target.store.name", jmsStore.getName());
parametersPro.put("interval", "5000");
messageProcessor.setName("FailoverProcessor");
messageProcessor.setParameters(parametersPro);
messageProcessor.setMessageStoreName("JMSStore");
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
ConfigurationContext cfgCtx = new ConfigurationContext(synapseConfiguration.getAxisConfiguration());
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
synapseConfiguration.addMessageStore("JMSStore", jmsStore);
synapseConfiguration.addMessageProcessor("FailoverProcessor", messageProcessor);
jmsStore.init(synapseEnvironment);
FailoverForwardingService failoverForwardingService = new FailoverForwardingService(messageProcessor, synapseEnvironment, 5000, false);
failoverForwardingService.init(synapseEnvironment);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
SOAP11Factory factory = new SOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement element = AXIOMUtil.stringToOM("<name><value>Test</value></name>");
envelope.getBody().addChild(element);
messageContext.setEnvelope(envelope);
Assert.assertEquals("Queue is not empty!", 0, broker.getAdminView().getTotalMessageCount());
failoverForwardingService.dispatch(messageContext);
Assert.assertEquals("Message not forwarded!", 1, broker.getAdminView().getTotalMessageCount());
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class InMemoryMessageStoreTest method createMessageContext.
private MessageContext createMessageContext(String identifier) throws Exception {
MessageContext msg = TestUtils.createLightweightSynapseMessageContext("<test/>");
msg.setMessageID(identifier);
return msg;
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class InMemoryMessageStoreTest method testOrderedDelivery2.
public void testOrderedDelivery2() throws Exception {
System.out.println("Testing InMemoryStore Guaranteed Delivery...");
MessageStore store = new InMemoryStore();
store.getProducer().storeMessage(createMessageContext("FOO"));
MessageConsumer consumer = store.getConsumer();
MessageContext msg = consumer.receive();
assertEquals("FOO", msg.getMessageID());
store.getProducer().storeMessage(createMessageContext("BAR"));
msg = consumer.receive();
assertEquals("FOO", msg.getMessageID());
consumer.ack();
msg = consumer.receive();
assertEquals("BAR", msg.getMessageID());
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class InMemoryMessageStoreTest method testBasics.
public void testBasics() throws Exception {
System.out.println("Testing Basic InMemoryStore operations...");
MessageStore store = new InMemoryStore();
populateStore(store, 10);
// test size()
assertEquals(10, store.size());
// test get(index)
for (int i = 0; i < 10; i++) {
assertEquals("ID" + i, store.get(i).getMessageID());
}
// test get(messageId)
for (int i = 0; i < 10; i++) {
assertEquals("ID" + i, store.get("ID" + i).getMessageID());
}
// test getAll()
List<MessageContext> list = store.getAll();
assertEquals(10, list.size());
for (int i = 0; i < 10; i++) {
assertEquals("ID" + i, list.get(i).getMessageID());
}
// test receive()
MessageConsumer consumer = store.getConsumer();
for (int i = 0; i < 10; i++) {
assertEquals("ID" + i, consumer.receive().getMessageID());
consumer.ack();
}
populateStore(store, 10);
// test remove()
for (int i = 0; i < 10; i++) {
assertEquals("ID" + i, store.remove().getMessageID());
}
try {
store.remove();
fail();
} catch (NoSuchElementException expected) {
}
populateStore(store, 10);
// test clear()
assertEquals(10, store.size());
store.clear();
assertEquals(0, store.size());
}
use of org.apache.synapse.MessageContext in project wso2-synapse by wso2.
the class JmsMessageStoreTest method testProducer.
/**
* Testing whether jms producer is storing the message to the store
* @throws Exception
*/
@Test
public void testProducer() throws Exception {
JmsStore jmsStore = new JmsStore();
Map<String, Object> parameters = new HashMap<>();
parameters.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
parameters.put("java.naming.provider.url", "tcp://127.0.0.1:61616");
jmsStore.setParameters(parameters);
jmsStore.setName("TestJmsStore");
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
synapseConfiguration.addMessageStore("JMSStore", jmsStore);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
SOAP11Factory factory = new SOAP11Factory();
SOAPEnvelope envelope = factory.createSOAPEnvelope();
messageContext.setEnvelope(envelope);
jmsStore.init(synapseEnvironment);
JmsProducer jmsProducer = (JmsProducer) jmsStore.getProducer();
boolean response = jmsProducer.storeMessage(messageContext);
Assert.assertTrue("Message not stored!", response);
}
Aggregations