1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.observation.remote

File TCPROMTest.java

 

Code metrics

0
28
4
2
94
56
4
0.14
7
2
1

Classes

Class Line # Actions
TCPROMTest 33 28 0% 4 0
1.0100%
TCPROMTest.Unserializable 35 0 - 0 0
-1.0 -
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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   
 
33    public class TCPROMTest extends AbstractROMTestCase
34    {
 
35    static class Unserializable { }
36   
 
37  1 toggle @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   
 
50  1 toggle @After
51    public void tearDown() throws Exception
52    {
53  1 this.mockery.assertIsSatisfied();
54    }
55   
56    /**
57    * Validate sharing a simple Serializable event between two instances of {@link RemoteObservationManager}.
58    */
 
59  1 toggle @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()
 
70  1 toggle {{
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    // Make sure JGroups has enough time to send the message
92  1 Thread.sleep(1000);
93    }
94    }