Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2009-04-17 17:30:54 -0400
committerslewis2009-04-17 17:30:54 -0400
commit7c7f6b32ec8470c840c0b51020df44bd7336df3f (patch)
tree9e3619a90d7df201e1c9a9099a03afa815fe0b49 /tests/bundles/org.eclipse.ecf.tests.sharedobject
parentf21debbddaa11b58e9d6e473b2c7a5e20d66d2f1 (diff)
downloadorg.eclipse.ecf-7c7f6b32ec8470c840c0b51020df44bd7336df3f.tar.gz
org.eclipse.ecf-7c7f6b32ec8470c840c0b51020df44bd7336df3f.tar.xz
org.eclipse.ecf-7c7f6b32ec8470c840c0b51020df44bd7336df3f.zip
Added more/more generalized tests, plus AbstractSharedObjectTest
Diffstat (limited to 'tests/bundles/org.eclipse.ecf.tests.sharedobject')
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AbstractSharedObjectTest.java60
-rw-r--r--[-rwxr-xr-x]tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AddSharedObjectTest.java (renamed from tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AddTest.java)21
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/IMessageReceiver.java17
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/IMessageSender.java18
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/SendSharedObjectMessageTest.java79
-rw-r--r--tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/TestMessagingSharedObject.java110
6 files changed, 289 insertions, 16 deletions
diff --git a/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AbstractSharedObjectTest.java b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AbstractSharedObjectTest.java
new file mode 100644
index 000000000..11427bd42
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AbstractSharedObjectTest.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
+* program and the accompanying materials are made available under the terms of
+* the Eclipse Public License v1.0 which accompanies this distribution, and is
+* available at http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.sharedobject;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.sharedobject.ISharedObject;
+import org.eclipse.ecf.core.sharedobject.ISharedObjectContainer;
+import org.eclipse.ecf.core.sharedobject.ISharedObjectManager;
+import org.eclipse.ecf.core.sharedobject.SharedObjectAddException;
+import org.eclipse.ecf.tests.ContainerAbstractTestCase;
+
+public class AbstractSharedObjectTest extends ContainerAbstractTestCase {
+
+
+ public ISharedObjectContainer getClientSOContainer(int clientindex) {
+ return (ISharedObjectContainer) getClient(clientindex);
+ }
+
+ public ISharedObjectManager getClientSOManager(int clientindex) {
+ return getClientSOContainer(clientindex).getSharedObjectManager();
+ }
+
+ public ID addClientSharedObject(int clientindex, ID sharedObjectID, ISharedObject so, Map properties) throws SharedObjectAddException {
+ return getClientSOManager(clientindex).addSharedObject(sharedObjectID, so, properties);
+ }
+
+ public ISharedObjectContainer getServerSOContainer() {
+ return (ISharedObjectContainer) getServer();
+ }
+
+ public ISharedObjectManager getServerSOManager() {
+ return getServerSOContainer().getSharedObjectManager();
+ }
+
+ public ID addServerSharedObject(int clientindex, ID sharedObjectID, ISharedObject so, Map properties) throws SharedObjectAddException {
+ return getClientSOManager(clientindex).addSharedObject(sharedObjectID, so, properties);
+ }
+
+ public ISharedObject getClientSharedObject(int clientindex, ID sharedObjectID) {
+ return getClientSOManager(clientindex).getSharedObject(sharedObjectID);
+ }
+
+ public ISharedObject getServerSharedObject(ID sharedObjectID) {
+ return getServerSOManager().getSharedObject(sharedObjectID);
+ }
+
+ public void sendMessage(IMessageSender sender, ID targetID, Object message) throws IOException {
+ sender.sendMessage(targetID, message);
+ }
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AddTest.java b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AddSharedObjectTest.java
index bb2d62975..b6ed834c4 100755..100644
--- a/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AddTest.java
+++ b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/AddSharedObjectTest.java
@@ -22,7 +22,7 @@ import org.eclipse.ecf.tests.ContainerAbstractTestCase;
/**
*
*/
-public class AddTest extends ContainerAbstractTestCase {
+public class AddSharedObjectTest extends AbstractSharedObjectTest {
public static final String SERVER_NAME = "ecftcp://localhost:5888/server";
@@ -61,13 +61,7 @@ public class AddTest extends ContainerAbstractTestCase {
}
public void testAddSharedObject() throws Exception {
- final IContainer client0Container = getClient(0);
- assertNotNull(client0Container);
- //
- ISharedObjectContainer socontainer = (ISharedObjectContainer) client0Container
- .getAdapter(ISharedObjectContainer.class);
- final ISharedObjectManager manager = socontainer
- .getSharedObjectManager();
+ final ISharedObjectManager manager = getClientSOManager(0);
assertNotNull(manager);
final ID id = manager.addSharedObject(IDFactory.getDefault()
.createStringID("foo"), new TestSharedObject(TEST_USERNAME0),
@@ -75,16 +69,11 @@ public class AddTest extends ContainerAbstractTestCase {
assertNotNull(id);
final ISharedObject sharedObject = manager.getSharedObject(id);
assertNotNull(sharedObject);
- sleep(3000);
+ sleep(1000);
}
public void testAddTwoSharedObjects() throws Exception {
- final IContainer client0Container = getClient(0);
- assertNotNull(client0Container);
- ISharedObjectContainer socontainer = (ISharedObjectContainer) client0Container
- .getAdapter(ISharedObjectContainer.class);
- final ISharedObjectManager manager = socontainer
- .getSharedObjectManager();
+ final ISharedObjectManager manager = getClientSOManager(0);
assertNotNull(manager);
final ID id0 = manager.addSharedObject(IDFactory.getDefault()
.createStringID("foo0"), new TestSharedObject(TEST_USERNAME0),
@@ -98,7 +87,7 @@ public class AddTest extends ContainerAbstractTestCase {
assertNotNull(sharedObject0);
final ISharedObject sharedObject1 = manager.getSharedObject(id1);
assertNotNull(sharedObject1);
- sleep(3000);
+ sleep(1000);
}
}
diff --git a/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/IMessageReceiver.java b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/IMessageReceiver.java
new file mode 100644
index 000000000..ae5afc962
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/IMessageReceiver.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
+* program and the accompanying materials are made available under the terms of
+* the Eclipse Public License v1.0 which accompanies this distribution, and is
+* available at http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.sharedobject;
+
+import org.eclipse.ecf.core.identity.ID;
+
+public interface IMessageReceiver {
+ public void handleMessage(ID fromID, Object message);
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/IMessageSender.java b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/IMessageSender.java
new file mode 100644
index 000000000..ca4646b81
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/IMessageSender.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
+* program and the accompanying materials are made available under the terms of
+* the Eclipse Public License v1.0 which accompanies this distribution, and is
+* available at http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.sharedobject;
+
+import java.io.IOException;
+
+import org.eclipse.ecf.core.identity.ID;
+
+public interface IMessageSender {
+ public void sendMessage(ID targetID, Object message) throws IOException;
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/SendSharedObjectMessageTest.java b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/SendSharedObjectMessageTest.java
new file mode 100644
index 000000000..d5ab52a00
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/SendSharedObjectMessageTest.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
+* program and the accompanying materials are made available under the terms of
+* the Eclipse Public License v1.0 which accompanies this distribution, and is
+* available at http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* EclipseSource - initial API and implementation
+******************************************************************************/
+package org.eclipse.ecf.tests.sharedobject;
+
+import java.io.IOException;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+
+public class SendSharedObjectMessageTest extends AbstractSharedObjectTest {
+
+ public static final String SERVER_NAME = "ecftcp://localhost:5889/server";
+
+ public static final String TEST_USERNAME0 = "slewis";
+
+ private static final int MESSAGE_SEND_COUNT = 10;
+
+ ID sharedObjectID;
+ TestMessagingSharedObject sharedObject;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.tests.ContainerAbstractTestCase#getClientCount()
+ */
+ protected int getClientCount() {
+ return 1;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.tests.ContainerAbstractTestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ createServerAndClients();
+ connectClients();
+ // Add test messaging shared object
+ sharedObjectID = addClientSharedObject(0,IDFactory.getDefault()
+ .createStringID("foo0"),new TestMessagingSharedObject(TEST_USERNAME0,new IMessageReceiver() {
+ public void handleMessage(ID fromID, Object message) {
+ System.out.println("received fromId="+fromID+" message="+message);
+ }}),null);
+ sharedObject = (TestMessagingSharedObject) getClientSOManager(0).getSharedObject(sharedObjectID);
+ sleep(2000);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ cleanUpServerAndClients();
+ sharedObjectID = null;
+ sharedObject = null;
+ }
+
+ private void testMessageSend(String message) throws IOException {
+ sharedObject.sendMessage(null, message);
+ sleep(1000);
+ }
+
+ public void testMessageSend() throws Exception {
+ for(int i=0; i < MESSAGE_SEND_COUNT; i++) {
+ testMessageSend("greetings program");
+ }
+ }
+
+}
diff --git a/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/TestMessagingSharedObject.java b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/TestMessagingSharedObject.java
new file mode 100644
index 000000000..a61f430ed
--- /dev/null
+++ b/tests/bundles/org.eclipse.ecf.tests.sharedobject/src/org/eclipse/ecf/tests/sharedobject/TestMessagingSharedObject.java
@@ -0,0 +1,110 @@
+/****************************************************************************
+ * Copyright (c) 2007 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.tests.sharedobject;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.sharedobject.BaseSharedObject;
+import org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription;
+import org.eclipse.ecf.core.sharedobject.SharedObjectInitException;
+import org.eclipse.ecf.core.sharedobject.SharedObjectMsg;
+import org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent;
+import org.eclipse.ecf.core.util.Event;
+import org.eclipse.ecf.core.util.IEventProcessor;
+
+/**
+ *
+ */
+public class TestMessagingSharedObject extends BaseSharedObject implements IMessageSender {
+
+ public static final String NAME_PROPERTY = "name";
+
+ String name;
+ IMessageReceiver messageReceiver;
+
+ /**
+ * Primary constructor
+ * @param name the name to say hello to
+ */
+ public TestMessagingSharedObject(String name, IMessageReceiver receiver) {
+ this.name = name;
+ Assert.isNotNull(name);
+ this.messageReceiver = receiver;
+ }
+
+ /**
+ * Replica constructor (null constructor)
+ */
+ public TestMessagingSharedObject() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.sharedobject.BaseSharedObject#initialize()
+ */
+ protected void initialize() throws SharedObjectInitException {
+ super.initialize();
+ if (isPrimary()) {
+ // If primary, then add an event processor that handles activated
+ // event by replicating to all current remote containers
+ addEventProcessor(new IEventProcessor() {
+ public boolean processEvent(Event event) {
+ if (event instanceof ISharedObjectActivatedEvent) {
+ ISharedObjectActivatedEvent ae = (ISharedObjectActivatedEvent) event;
+ if (ae.getActivatedID().equals(getID()) && isConnected()) {
+ TestMessagingSharedObject.this.replicateToRemoteContainers(null);
+ }
+ }
+ return false;
+ }
+ });
+ System.out.println("Primary(" + getContext().getLocalContainerID() + ") says Hello " + name);
+ } else {
+ // This is a replica, so initialize the name from property
+ name = (String) getConfig().getProperties().get(NAME_PROPERTY);
+ System.out.println("Replica(" + getContext().getLocalContainerID() + ") says Hello " + name);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.sharedobject.BaseSharedObject#getReplicaDescription(org.eclipse.ecf.core.identity.ID)
+ */
+ protected ReplicaSharedObjectDescription getReplicaDescription(ID receiver) {
+ // Put primary state into properties and include in replica description
+ final Map properties = new HashMap();
+ properties.put(NAME_PROPERTY, name);
+ return new ReplicaSharedObjectDescription(this.getClass(), getConfig().getSharedObjectID(), getConfig().getHomeContainerID(), properties);
+ }
+
+ protected void handleMessage(ID fromID, String message) {
+ if (messageReceiver != null) messageReceiver.handleMessage(fromID, message);
+ else System.out.println(name+" says "+message);
+ }
+
+ protected boolean handleSharedObjectMsg(SharedObjectMsg msg) {
+ try {
+ msg.invoke(this);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return true;
+ }
+
+ public void sendMessage(ID targetId, Object message) throws IOException {
+ sendSharedObjectMsgTo(null, SharedObjectMsg.createMsg(this.getClass().getName(),"handleMessage", new Object[] { getLocalContainerID(), message }));
+ }
+}

Back to the top