1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.observation.remote; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
|
24 |
|
import org.jmock.Expectations; |
25 |
|
import org.junit.After; |
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.logging.event.LogEvent; |
29 |
|
import org.xwiki.observation.EventListener; |
30 |
|
import org.xwiki.observation.remote.test.AbstractROMTestCase; |
31 |
|
import org.xwiki.observation.remote.test.TestEvent; |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 4 |
Complexity Density: 0.14 |
|
33 |
|
public class TCPROMTest extends AbstractROMTestCase |
34 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
35 |
|
static class Unserializable { } |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
37 |
1 |
@Override... |
38 |
|
@Before |
39 |
|
public void setUp() throws Exception |
40 |
|
{ |
41 |
1 |
super.setUp(); |
42 |
|
|
43 |
1 |
System.setProperty("jgroups.bind_addr", "localhost"); |
44 |
|
|
45 |
1 |
getConfigurationSource1().setProperty("observation.remote.channels", Arrays.asList("tcp")); |
46 |
1 |
RemoteObservationManager rom = getComponentManager2().getInstance(RemoteObservationManager.class); |
47 |
1 |
rom.startChannel("tcp"); |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
1 |
@After... |
51 |
|
public void tearDown() throws Exception |
52 |
|
{ |
53 |
1 |
this.mockery.assertIsSatisfied(); |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
@link |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
59 |
1 |
@Test... |
60 |
|
public void testSerializableEvent() throws InterruptedException |
61 |
|
{ |
62 |
1 |
final EventListener localListener = this.mockery.mock(EventListener.class, "local"); |
63 |
1 |
final EventListener remoteListener = this.mockery.mock(EventListener.class, "remote"); |
64 |
|
|
65 |
1 |
final TestEvent event = new TestEvent(); |
66 |
|
|
67 |
1 |
final Unserializable unserializable = new Unserializable(); |
68 |
|
|
69 |
1 |
this.mockery.checking(new Expectations() |
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
70 |
1 |
{{... |
71 |
1 |
allowing(localListener).getName(); |
72 |
1 |
will(returnValue("mylistener")); |
73 |
1 |
allowing(remoteListener).getName(); |
74 |
1 |
will(returnValue("mylistener")); |
75 |
1 |
allowing(localListener).getEvents(); |
76 |
1 |
will(returnValue(Arrays.asList(event))); |
77 |
1 |
allowing(remoteListener).getEvents(); |
78 |
1 |
will(returnValue(Arrays.asList(event))); |
79 |
1 |
oneOf(localListener).onEvent(with(same(event)), with(equal("some source")), with(equal("some data"))); |
80 |
1 |
oneOf(localListener).onEvent(with(same(event)), with(same(unserializable)), with(same(unserializable))); |
81 |
1 |
oneOf(remoteListener).onEvent(with(equal(event)), with(equal("some source")), with(equal("some data"))); |
82 |
|
}}); |
83 |
|
|
84 |
1 |
getObservationManager1().addListener(localListener); |
85 |
1 |
getObservationManager2().addListener(remoteListener); |
86 |
|
|
87 |
1 |
getObservationManager1().notify(event, "some source", "some data"); |
88 |
1 |
getObservationManager1().notify(event, unserializable, unserializable); |
89 |
1 |
getObservationManager1().notify(new LogEvent(), "some source", "some data"); |
90 |
|
|
91 |
|
|
92 |
1 |
Thread.sleep(1000); |
93 |
|
} |
94 |
|
} |