source: java/main/src/test/java/com/framsticks/hosting/ServerTest.java @ 96

Last change on this file since 96 was 96, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • cleanup Instance management
    • extract Instance interface
    • extract Instance common algorithms to InstanceUtils?
  • fix closing issues: Ctrl+C or window close button

properly shutdown whole program

by Java Framsticks framework

  • fix parsing and printing of all request types
  • hide exception passing in special handle method of closures
    • substantially improve readability of closures
    • basically enable use of exception in asynchronous closures

(thrown exception is transported back to the caller)

  • implement call request on both sides

CHANGELOG:
Further improve calling.

Improve instance calling.

Calling is working on both sides.

Improve exception handling in testing.

Waiters do not supercede other apllication exception being thrown.

Finished parsing and printing of all request types (with tests).

Move implementation and tests of request parsing to Request.

Add tests for Requests.

Improve waits in asynchronours tests.

Extract more algorithms to InstanceUtils?.

Extract Instance.resolve to InstanceUtils?.

Improve naming.

Improve passing exception in InstanceClient?.

Hide calling of passed functor in StateCallback?.

Hide Exception passing in asynchronous closures.

Hide exception passing in Future.

Make ResponseCallback? an abstract class.

Make Future an abstract class.

Minor change.

Move getPath to Path.to()

Move bindAccess to InstanceUtils?.

Extract common things to InstanceUtils?.

Fix synchronization bug in Connection.

Move resolve to InstanceUtils?.

Allow names of Joinable to be dynamic.

Add support for set request server side.

More fixes in communication.

Fix issues with parsing in connection.

Cut new line characters when reading.

More improvements.

Migrate closures to FramsticksException?.

Several changes.

Extract resolveAndFetch to InstanceUtils? algorithms.

Test resolving and fetching.

More fixes with function signature deduction.

Do not print default values in SimpleAbstractAccess?.

Add test of FramsClass? printing.

Improve FramsticksException? messages.

Add explicit dispatcher synchronization feature.

Rework assertions in tests.

Previous solution was not generic enough.

Allow addition of joinables to collection after start.

Extract SimulatorInstance? from RemoteInstance?.

Remove PrivateJoinableCollection?.

Improve connections.

Move shutdown hook to inside the Monitor.

It should work in TestNG tests, but it seems that
hooks are not called.

In ServerTest? client connects to testing server.

Move socket initialization to receiver thread.

Add proper closing on Ctrl+C (don't use signals).

Fix bugs with server accepting connections.

Merge Entity into Joinable.

Reworking ServerInstance?.

Extract more algorithm to InstanceUtils?.

Extract some common functionality from AbstractInstance?.

Functions were placed in InstanceUtils?.

Hide registry of Instance.

Use ValueParam? in Instance interface.

Minor change.

Extract Instance interface.

Old Instance is now AbstractInstance?.

File size: 4.6 KB
Line 
1package com.framsticks.hosting;
2
3// import org.apache.log4j.Logger;
4import org.testng.annotations.Test;
5
6import com.framsticks.core.ObjectInstance;
7import com.framsticks.core.Path;
8import com.framsticks.core.XmlBasedTest;
9import com.framsticks.remote.RemoteInstance;
10
11import com.framsticks.test.TestClass;
12import com.framsticks.core.Instance;
13import com.framsticks.params.FramsClass;
14import com.framsticks.util.AbstractStateFunctor;
15import com.framsticks.util.dispatching.Dispatching;
16import com.framsticks.params.AccessInterface;
17import com.framsticks.params.PropertiesAccess;
18import com.framsticks.params.ValueParam;
19import com.framsticks.params.types.ProcedureParam;
20import com.framsticks.util.dispatching.Dispatching.Waiter;
21import com.framsticks.util.dispatching.Future;
22import com.framsticks.util.dispatching.RunAt;
23
24import static com.framsticks.core.InstanceUtils.*;
25
26import static org.fest.assertions.Assertions.*;
27
28@Test
29public class ServerTest extends XmlBasedTest {
30
31        protected RemoteInstance remote;
32        protected FramsClass remoteTestFramsClass;
33        protected Path remotePath;
34
35        protected Server server;
36        protected ObjectInstance hosted;
37        protected TestClass hostedObject;
38
39        @Override
40        protected String getConfigurationName() {
41                return "ServerTest.xml";
42        }
43
44        @Test
45        public void runServer() {
46                assertThat(framsticks.size()).isEqualTo(2);
47                assertThat(framsticks.get("test")).isInstanceOf(Server.class);
48                assertThat(framsticks.get("remote")).isInstanceOf(RemoteInstance.class);
49
50                server = (Server) framsticks.get("test");
51                remote = (RemoteInstance) framsticks.get("remote");
52                assertThat(server.getHosted()).isInstanceOf(ObjectInstance.class);
53                hosted = (ObjectInstance) server.getHosted();
54                assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class);
55                hostedObject = hosted.getRootObject(TestClass.class);
56        }
57
58        @Test(dependsOnMethods = "runServer")
59        public void fetchInfo() {
60                remote.dispatch(new RunAt<Instance>() {
61                        @Override
62                        public void run() {
63                                remote.fetchInfo(Path.to(remote, "/"), new Future<FramsClass>(failOnException()) {
64                                        @Override
65                                        protected void result(FramsClass result) {
66                                                remoteTestFramsClass = result;
67                                                assertThat(result.getId()).isEqualTo("TestClass");
68                                        }
69                                });
70                        }
71                });
72
73                Dispatching.synchronize(remote, 1.0);
74        }
75
76        @Test(dependsOnMethods = "fetchInfo")
77        public void resolveAndfetchRootObject() {
78                final Waiter waiter = produceWaiter(1.0);
79
80                remote.dispatch(new RunAt<Instance>() {
81                        @Override
82                        public void run() {
83                                final Path path = Path.to(remote, "/");
84                                assertThat(path.isResolved()).isFalse();
85
86                                remote.resolve(path, new Future<Path>(failOnException()) {
87                                        @Override
88                                        protected void result(final Path result) {
89                                                assertThat(result.isResolved()).isTrue();
90                                                remotePath = result;
91                                                remote.fetchValues(result, new AbstractStateFunctor(failOnException()) {
92                                                        @Override
93                                                        public void call() {
94                                                                AccessInterface access = bindAccess(result);
95                                                                assertThat(access).isInstanceOf(PropertiesAccess.class);
96                                                                assertThat(access.get("name", String.class)).isEqualTo("a test name");
97                                                                waiter.pass();
98                                                        }
99                                                });
100                                        }
101                                });
102                        }
103                });
104        }
105
106        @Test(dependsOnMethods = "resolveAndfetchRootObject")
107        public void setValueName() {
108                final Waiter waiter = produceWaiter(2.0);
109
110                storeValue(remotePath, remoteTestFramsClass.getParamEntry("name", ValueParam.class), "new name", new AbstractStateFunctor(failOnException()) {
111                        @Override
112                        public void call() {
113                                /** And now check directly whether it was really set. */
114                                hosted.dispatch(new RunAt<Instance>() {
115                                        @Override
116                                        public void run() {
117                                                assertThat(hostedObject.getName()).isEqualTo("new name");
118                                                waiter.pass();
119                                        }
120                                });
121                        }
122                });
123        }
124
125        @Test(dependsOnMethods = "setValueName")
126        public void callMethod() {
127                final Waiter firstWaiter = produceWaiter(2.0);
128                final Waiter waiter = produceWaiter(2.0);
129
130                call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, new Future<Object>(failOnException()) {
131                        @Override
132                        protected void result(Object result) {
133                                firstWaiter.pass();
134                        }
135                });
136
137                call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new Future<Object>(failOnException()) {
138                        @Override
139                        protected void result(Object result) {
140                                hosted.dispatch(new RunAt<Instance>() {
141                                        @Override
142                                        public void run() {
143                                                assertThat(hostedObject.getHistory()).isEqualTo("next word|");
144                                                waiter.pass();
145                                        }
146                                });
147                        }
148                });
149
150        }
151
152        @Test(dependsOnMethods = "callMethod")
153        public void endWait() {
154                monitor.useFor(1.0);
155        }
156}
Note: See TracBrowser for help on using the repository browser.