Search in sources :

Example 1 with MessageConsumer

use of org.apache.synapse.message.MessageConsumer 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());
}
Also used : MessageConsumer(org.apache.synapse.message.MessageConsumer) InMemoryStore(org.apache.synapse.message.store.impl.memory.InMemoryStore) MessageContext(org.apache.synapse.MessageContext)

Example 2 with MessageConsumer

use of org.apache.synapse.message.MessageConsumer 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());
}
Also used : MessageConsumer(org.apache.synapse.message.MessageConsumer) InMemoryStore(org.apache.synapse.message.store.impl.memory.InMemoryStore) MessageContext(org.apache.synapse.MessageContext) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with MessageConsumer

use of org.apache.synapse.message.MessageConsumer 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();
    }
}
Also used : MessageConsumer(org.apache.synapse.message.MessageConsumer) InMemoryStore(org.apache.synapse.message.store.impl.memory.InMemoryStore)

Aggregations

MessageConsumer (org.apache.synapse.message.MessageConsumer)3 InMemoryStore (org.apache.synapse.message.store.impl.memory.InMemoryStore)3 MessageContext (org.apache.synapse.MessageContext)2 NoSuchElementException (java.util.NoSuchElementException)1