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

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

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

File size: 7.3 KB
Line 
1package com.framsticks.hosting;
2
3// import org.apache.log4j.Logger;
4import java.util.Arrays;
5import java.util.LinkedList;
6import java.util.List;
7
8import org.testng.annotations.Test;
9
10import com.framsticks.core.ListChange;
11import com.framsticks.core.LocalTree;
12import com.framsticks.core.Path;
13import com.framsticks.core.TreeOperations;
14import com.framsticks.core.XmlBasedTest;
15import com.framsticks.remote.RemoteTree;
16
17import com.framsticks.test.ChangeEvent;
18import com.framsticks.test.TestClass;
19import com.framsticks.core.Tree;
20import com.framsticks.params.FramsClass;
21import com.framsticks.params.Access;
22import com.framsticks.params.EventListener;
23import com.framsticks.params.PrimitiveParam;
24import com.framsticks.params.PropertiesAccess;
25import com.framsticks.params.types.EventParam;
26import com.framsticks.params.types.StringParam;
27// import com.framsticks.params.types.EventParam;
28import com.framsticks.params.types.ProcedureParam;
29import com.framsticks.util.dispatching.Dispatching.Waiter;
30import com.framsticks.util.dispatching.FutureHandler;
31import com.framsticks.util.dispatching.RunAt;
32
33import static com.framsticks.core.TreeOperations.*;
34
35import static org.fest.assertions.Assertions.*;
36
37@Test
38public class ServerTest extends XmlBasedTest {
39
40        protected RemoteTree remote;
41        protected FramsClass remoteTestFramsClass;
42        protected Path remotePath;
43
44        protected Server server;
45        protected LocalTree hosted;
46        protected TestClass hostedObject;
47        protected EventListener<ChangeEvent> listener;
48        protected EventListener<ListChange> childListener;
49
50        protected List<String> listenerArguments = new LinkedList<>();
51        protected List<ListChange> childrenChanges = new LinkedList<>();
52
53
54        @Override
55        protected String getConfigurationName() {
56                return "ServerTest.xml";
57        }
58
59        @Test
60        public void runServer() {
61                assertThat(framsticks.size()).isEqualTo(2);
62                assertThat(framsticks.get("test")).isInstanceOf(Server.class);
63                assertThat(framsticks.get("remote")).isInstanceOf(RemoteTree.class);
64
65                server = (Server) framsticks.get("test");
66                remote = (RemoteTree) framsticks.get("remote");
67                assertThat(server.getHosted()).isInstanceOf(LocalTree.class);
68                hosted = (LocalTree) server.getHosted();
69                assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class);
70                hostedObject = hosted.getRootObject(TestClass.class);
71        }
72
73        @Test(dependsOnMethods = "runServer")
74        public void fetchInfo() {
75                final Waiter waiter = produceWaiter(1.0);
76
77                TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) {
78                        @Override
79                        protected void result(Path path) {
80                                assertThat(path.isResolved()).isTrue();
81                                remoteTestFramsClass = bindAccess(path).getFramsClass();
82                                assertThat(remoteTestFramsClass.getName()).isEqualTo("TestClass");
83                                waiter.pass();
84                        }
85                });
86
87        }
88
89        @Test(dependsOnMethods = "fetchInfo")
90        public void resolveAndfetchRootObject() {
91                final Waiter waiter = produceWaiter(1.0);
92
93                TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) {
94                        @Override
95                        protected void result(Path path) {
96                                assertThat(path.isResolved()).isTrue();
97                                remotePath = path;
98                                Access access = bindAccess(path);
99                                assertThat(access).isInstanceOf(PropertiesAccess.class);
100                                assertThat(access.get("name", String.class)).isEqualTo("a test name");
101                                waiter.pass();
102                        }
103                });
104        }
105
106        @Test(dependsOnMethods = "resolveAndfetchRootObject")
107        public void setValueName() {
108                final Waiter waiter = produceWaiter(2.0);
109
110                set(remotePath, remoteTestFramsClass.getParamEntry("name", PrimitiveParam.class), "new name", new FutureHandler<Integer>(failOnException) {
111                        @Override
112                        protected void result(Integer flags) {
113                                // assertThat(flags).isEqualTo(0);
114                                /** And now check directly whether it was really set. */
115                                hosted.dispatch(new RunAt<Tree>(failOnException) {
116                                        @Override
117                                        protected void runAt() {
118                                                assertThat(hostedObject.getName()).isEqualTo("new name");
119                                                waiter.pass();
120                                        }
121                                });
122                        }
123                });
124        }
125
126        @Test(dependsOnMethods = "setValueName")
127        public void registerListener() {
128                final Waiter waiter = produceWaiter(1.0);
129                listener = new EventListener<ChangeEvent>() {
130
131                        @Override
132                        public void action(ChangeEvent argument) {
133                                listenerArguments.add(argument.history);
134                        }
135                };
136
137                TreeOperations.tryGet(remote, "/cli/events", new FutureHandler<Path>(failOnException) {
138                        @Override
139                        protected void result(Path path) {
140                                waiter.pass();
141                        }
142                });
143
144                addListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, ChangeEvent.class, produceWaiter(1.0).passInFuture(Void.class));
145        }
146
147        @Test(dependsOnMethods = "registerListener")
148        public void callMethod() {
149                final Waiter waiter = produceWaiter(2.0);
150
151                call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, produceWaiter(2.0).passInFuture(Object.class));
152
153                call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new FutureHandler<Object>(failOnException) {
154                        @Override
155                        protected void result(Object result) {
156                                hosted.dispatch(new RunAt<Tree>(failOnException) {
157                                        @Override
158                                        protected void runAt() {
159                                                assertThat(hostedObject.getHistory()).isEqualTo("next word|");
160                                                waiter.pass();
161                                        }
162                                });
163                        }
164                });
165        }
166
167
168        @Test(dependsOnMethods = "callMethod")
169        public void deregisterListener() {
170                removeListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, produceWaiter(1.0).passInFuture(Void.class));
171
172                assertThat(listenerArguments).isEqualTo(Arrays.asList("", "next word|"));
173        }
174
175
176        @Test(dependsOnMethods = "deregisterListener")
177        public void registerChildListener() {
178
179                childListener = new EventListener<ListChange>() {
180                        @Override
181                        public void action(ListChange listChange) {
182                                childrenChanges.add(listChange);
183                        }
184                };
185
186                addListener(remotePath, remoteTestFramsClass.getParamEntry("children_changed", EventParam.class), childListener, ListChange.class, produceWaiter(1.0).passInFuture(Void.class));
187        }
188
189        @Test(dependsOnMethods = "registerChildListener")
190        public void createChild() {
191                final Waiter waiter = produceWaiter(2.0);
192                call(remotePath, "createChild", new Object[] { "a child" }, produceWaiter(2.0).passInFuture(Object.class));
193                call(remotePath, "createChild", new Object[] { "another child" }, produceWaiter(2.0).passInFuture(Object.class));
194
195                tryGet(remote, "/testClass/children/c0", new FutureHandler<Path>(failOnException) {
196
197                        @Override
198                        protected void result(Path result) {
199                                set(result, getFramsClass(result).getParamEntry("name", StringParam.class), "new_name", new FutureHandler<Integer>(failOnException) {
200
201                                        @Override
202                                        protected void result(Integer result) {
203                                                waiter.pass();
204                                        }
205                                });
206                        }
207                });
208        }
209
210        @Test(dependsOnMethods = "createChild")
211        public void deregisterChildListener() {
212                removeListener(remotePath, remoteTestFramsClass.getParamEntry("children_changed", EventParam.class), childListener, produceWaiter(1.0).passInFuture(Void.class));
213        }
214
215        @Test(dependsOnMethods = "deregisterChildListener")
216        public void checkListChanges() {
217                assertThat(childrenChanges).isEqualTo(Arrays.asList(
218                        new ListChange(ListChange.Action.Add, 0, "c0"),
219                        new ListChange(ListChange.Action.Add, 1, "c1"),
220                        new ListChange(ListChange.Action.Modify, 0, "c0")
221                ));
222        }
223
224        @Test(dependsOnMethods = "checkListChanges")
225        public void endWait() {
226                monitor.useFor(1.0);
227        }
228}
Note: See TracBrowser for help on using the repository browser.