Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorafinkbein2010-04-05 19:26:48 -0400
committerafinkbein2010-04-05 19:26:48 -0400
commit4028d9f9a1ae4a6a11673bf1777512603f05414e (patch)
tree0b53c15d8283240eea75cca2f8ca5d7797100d25 /plugins/org.eclipse.osee.framework.messaging.test
parent10cd3e36a7a4728eb19da046a8696476680fdd41 (diff)
downloadorg.eclipse.osee-4028d9f9a1ae4a6a11673bf1777512603f05414e.tar.gz
org.eclipse.osee-4028d9f9a1ae4a6a11673bf1777512603f05414e.tar.xz
org.eclipse.osee-4028d9f9a1ae4a6a11673bf1777512603f05414e.zip
Changes to support using selectors for message filtering
Diffstat (limited to 'plugins/org.eclipse.osee.framework.messaging.test')
-rw-r--r--plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/BasicListener.java44
-rw-r--r--plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/TestMessageServicesMultipleConsumers.java107
2 files changed, 151 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/BasicListener.java b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/BasicListener.java
new file mode 100644
index 0000000000..250f3ad17a
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/BasicListener.java
@@ -0,0 +1,44 @@
+/*
+ * Created on Apr 5, 2010
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.messaging.services.internal;
+
+import java.util.Map;
+import org.eclipse.osee.framework.messaging.OseeMessagingListener;
+import org.eclipse.osee.framework.messaging.ReplyConnection;
+import org.eclipse.osee.framework.messaging.test.msg.TestMessage;
+
+/**
+ * @author b1528444
+ *
+ */
+public class BasicListener extends OseeMessagingListener {
+
+ private int id;
+ private boolean received = false;
+
+ public BasicListener(int id) {
+ this.id = id;
+ }
+
+ @Override
+ public Class<?> getClazz() {
+ return TestMessage.class;
+ }
+
+ @Override
+ public void process(Object message, Map<String, Object> headers, ReplyConnection replyConnection) {
+ System.out.println(message + " - " + id);
+ received = true;
+ }
+
+ public boolean isReceived(){
+ return received;
+ }
+
+ public String toString(){
+ return "BasicListener " + id;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/TestMessageServicesMultipleConsumers.java b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/TestMessageServicesMultipleConsumers.java
new file mode 100644
index 0000000000..f8405f01f8
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.messaging.test/src/org/eclipse/osee/framework/messaging/services/internal/TestMessageServicesMultipleConsumers.java
@@ -0,0 +1,107 @@
+/*
+ * Created on Jan 26, 2010
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.messaging.services.internal;
+
+import static org.junit.Assert.assertTrue;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import org.eclipse.osee.framework.messaging.ConnectionNode;
+import org.eclipse.osee.framework.messaging.NodeInfo;
+import org.eclipse.osee.framework.messaging.OseeMessagingStatusCallback;
+import org.eclipse.osee.framework.messaging.internal.BaseBrokerTesting;
+import org.eclipse.osee.framework.messaging.internal.TestMessages;
+import org.eclipse.osee.framework.messaging.test.msg.TestMessage;
+
+/**
+ * @author b1528444
+ *
+ */
+public class TestMessageServicesMultipleConsumers extends BaseBrokerTesting implements OseeMessagingStatusCallback {
+
+ private static String BROKER_URI_SERVER = "tcp://localhost:61616";
+ private static String BROKER_URI = "tcp://localhost:61616";
+
+ @org.junit.Before
+ public void startBroker(){
+ try {
+ startEmbeddedBroker("testBroker", BROKER_URI_SERVER);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ @org.junit.After
+ public void stopBroker(){
+ try {
+ stopEmbeddedBroker("testBroker", BROKER_URI_SERVER);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ @org.junit.Test
+ public void testMultipleConsumers() throws Exception{
+ ConnectionNode connection = getMessaging().get(new NodeInfo("osee-jms", new URI(BROKER_URI)));
+
+ List<BasicListener> listeners = new ArrayList<BasicListener>();
+ for(int i = 0; i < 20; i++){
+ BasicListener listener = new BasicListener(i);
+ listeners.add(listener);
+ connection.subscribe(TestMessages.JMS_TOPIC, listener, this);
+ }
+
+ TestMessage message = new TestMessage();
+ message.setMessage("TestMessage 1");
+ connection.send(TestMessages.JMS_TOPIC, message, this);
+
+ testWait(500);
+
+ for(BasicListener listener:listeners){
+ assertTrue(listener.toString(), listener.isReceived());
+ }
+ }
+
+ @org.junit.Test
+ public void testMultipleConsumersWithSelector() throws Exception{
+ ConnectionNode connection = getMessaging().get(new NodeInfo("osee-jms", new URI(BROKER_URI)));
+
+ List<BasicListener> listeners = new ArrayList<BasicListener>();
+ for(int i = 0; i < 20; i++){
+ BasicListener listener = new BasicListener(i);
+ listeners.add(listener);
+ connection.subscribe(TestMessages.JMS_TOPIC, listener, String.format("id = %d", i), this);
+ }
+
+ TestMessage message = new TestMessage();
+ message.setMessage("TestMessage 1");
+ Properties properties = new Properties();
+ properties.put("id", 1);
+ connection.send(TestMessages.JMS_TOPIC, message, properties, this);
+
+ testWait(500);
+
+ int receivedCount = 0;
+ for(BasicListener listener:listeners){
+ if(listener.isReceived()){
+ receivedCount++;
+ }
+ }
+
+ assertTrue(String.format("received %d messages", receivedCount), receivedCount == 1);
+ }
+
+ @Override
+ public void fail(Throwable th) {
+ assertTrue(th.getMessage(), false);
+ }
+
+ @Override
+ public void success() {
+ }
+
+}

Back to the top