ojrlopez27/multiuser-framework

synchronization of ProcessOrchestratorImpl.sendResponse()

timobaumann opened this issue · 2 comments

there's now a test-case in my scratch repo git@bitbucket.org:timobaumann/mufswingscratch.git
Please have a look at and run test/jav/edu.cmu.lti.articulab.movies.muf.TwoConsecutivePosts with the following modification:

If onEvent in TestOrchestrator is not synchronized, then sometimes messages arrive out-of-order (expected) but what's more, sometimes the broker complains about invald messages. See below.
Sometimes, both messages arrive, sometimes just one message arrives.

Expected behaviour: of course, messages may arrive out of order if ordering is not synchronized, but they should certainly work.

As this is a synchronization bug, please make sure that tests work many times in a row. The fact that a test works once does not tell us anything.

2017-12-05 09:41:15,963 INFO    Broker                         - creating broker: 5555
2017-12-05 09:41:16,001 INFO    SessionManager                 - Starting Multiuser framework...
2017-12-05 09:41:16,104 INFO    SessionManager                 - Creating session: myID
2017-12-05 09:41:16,109 INFO    SessionImpl                    - A new session has been created with id: myID
2017-12-05 09:41:16,111 INFO    SessionImpl                    - Initializing session: myID.
2017-12-05 09:41:16,124 INFO    TestOrchestrator               - myID	Creating Process Orchestrator for session: myID
2017-12-05 09:41:16,126 INFO    TestOrchestrator               - myID	Initializing ServiceManager for session: myID
client received: {"requestType":"SESSION_INITIATED","sessionId":"","url":"","payload":"tcp://127.0.0.1:5555"}
2017-12-05 09:41:16,150 INFO    TestComponent                  - myID	Starting up component: TestComponent on session: myID
2017-12-05 09:41:16,154 INFO    TestOrchestrator               - myID	Starting Process Orchestrator for session: myID
orchestrator received: {"requestType":"","sessionId":"","url":"","payload":"connect","messageId":"MSG_START_DM"}
2017-12-05 09:41:16,162 INFO    TestOrchestrator               - myID	ServiceManager has initialized all the statefull components for session: myID
posted helo1
seeing [status: ELEMENT_ADDED, id: MSG_TEST, element: helo1]
sending on [status: ELEMENT_ADDED, id: MSG_TEST, element: helo1]
posted helo2
seeing [status: ELEMENT_ADDED, id: MSG_TEST, element: helo2]
sending on [status: ELEMENT_ADDED, id: MSG_TEST, element: helo2]
2017-12-05 09:41:19,143 ERROR   Broker                         - invalid message: MDPW01
[{"requestType":"SESSION_INITIATED","sessionId":"","url":"","payload":"tcp://127.0.0.1:5555"}]

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:86)
	at org.junit.Assert.assertTrue(Assert.java:41)
	at org.junit.Assert.assertTrue(Assert.java:52)
	at edu.cmu.lti.articulab.movies.muf.TwoConsecutivePosts.twoConsecutivePosts(TwoConsecutivePosts.java:88)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)

2017-12-05 09:41:22,148 INFO    SessionManager                 - Start closing all external services (slave MUF's)...
2017-12-05 09:41:22,149 INFO    SessionManager                 - Start closing all sessions...
2017-12-05 09:41:22,150 INFO    SessionImpl                    - Closing session: myID

Now the client receives all the messages sent by the server. However, if you need them to be ordered, you have to implement a proper communication between your client and the server, that is, client sends a request, server sends message1, client sends a confirmation, server sends message2, and so on. If you don't want to send the confirmation from clients, MUF can do it automatically for you, you only have to set session.receive.automatic.ack = true in the config.properties file

Hi Oscar, can we change the default behaviour so that messages arrive in order (FIFO) by default and have the LIFO behaviour optional? I frankly cannot envision a use-case where LIFO would be better.