Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eca8ed17fc3bf9b13eefac51f8db0277baa7d801 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/****************************************************************************
 * Copyright (c) 2009 EclipseSource and others.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * Contributors:
 *   EclipseSource - initial API and implementation
 *
 * SPDX-License-Identifier: EPL-2.0
 *****************************************************************************/
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");
		}
	}

}

Back to the top