use of org.apache.synapse.message.store.impl.memory.InMemoryStore 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.message.store.impl.memory.InMemoryStore 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.message.store.impl.memory.InMemoryStore in project wso2-synapse by wso2.
the class MessageStoreFactory method createMessageStore.
@SuppressWarnings({ "UnusedDeclaration" })
public static MessageStore createMessageStore(OMElement elem, Properties properties) {
OMAttribute clss = elem.getAttribute(CLASS_Q);
MessageStore messageStore;
if (clss != null) {
String clssName = clss.getAttributeValue();
// Make synapse configuration backward compatible
if (Constants.DEPRECATED_INMEMORY_CLASS.equals(clssName)) {
clssName = InMemoryStore.class.getName();
} else if (Constants.DEPRECATED_JMS_CLASS.equals(clssName)) {
clssName = JmsStore.class.getName();
}
try {
Class cls = Class.forName(clssName);
messageStore = (MessageStore) cls.newInstance();
} catch (Exception e) {
handleException("Error while instantiating the message store", e);
return null;
}
} else {
messageStore = new InMemoryStore();
}
OMAttribute nameAtt = elem.getAttribute(NAME_Q);
if (nameAtt != null) {
messageStore.setName(nameAtt.getAttributeValue());
} else {
handleException("Message Store name not specified");
}
OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
if (descriptionElem != null) {
messageStore.setDescription(descriptionElem.getText());
}
messageStore.setParameters(getParameters(elem));
log.info("Successfully added Message Store configuration of : [" + nameAtt.getAttributeValue() + "].");
return messageStore;
}
use of org.apache.synapse.message.store.impl.memory.InMemoryStore in project wso2-synapse by wso2.
the class InMemoryMessageStoreTest method testOrderedDelivery1.
public void testOrderedDelivery1() throws Exception {
System.out.println("Testing InMemoryStore Ordered Delivery...");
MessageStore store = new InMemoryStore();
for (int i = 0; i < 100; i++) {
store.getProducer().storeMessage(createMessageContext("ID" + i));
}
MessageConsumer consumer = store.getConsumer();
for (int i = 0; i < 100; i++) {
assertEquals("ID" + i, consumer.receive().getMessageID());
consumer.ack();
}
}
Aggregations