1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.observation.remote

File TCPROMTest.java

 

Code metrics

0
22
2
2
95
52
2
0.09
11
1
1

Classes

Class Line # Actions
TCPROMTest 44 22 0% 2 0
1.0100%
TCPROMTest.Unserializable 46 0 - 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

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.junit.jupiter.api.BeforeEach;
25    import org.junit.jupiter.api.Test;
26    import org.xwiki.logging.event.LogEvent;
27    import org.xwiki.observation.EventListener;
28    import org.xwiki.observation.remote.test.AbstractROMTestCase;
29    import org.xwiki.observation.remote.test.TestEvent;
30    import org.xwiki.test.annotation.AllComponents;
31   
32    import static org.mockito.ArgumentMatchers.eq;
33    import static org.mockito.ArgumentMatchers.same;
34    import static org.mockito.Mockito.mock;
35    import static org.mockito.Mockito.verify;
36    import static org.mockito.Mockito.when;
37   
38    /**
39    * Integration test checking that event are well converted and transported from one cluster member to another.
40    *
41    * @version $Id: af8aca67cc486c985a3abab7c6ce945f2ad3f356 $
42    */
43    @AllComponents
 
44    public class TCPROMTest extends AbstractROMTestCase
45    {
 
46    static class Unserializable
47    {
48    }
49   
 
50  1 toggle @Override
51    @BeforeEach
52    public void beforeEach() throws Exception
53    {
54  1 super.beforeEach();
55   
56  1 System.setProperty("jgroups.bind_addr", "localhost");
57   
58  1 getConfigurationSource1().setProperty("observation.remote.channels", Arrays.asList("tcp"));
59  1 RemoteObservationManager rom = getComponentManager2().getInstance(RemoteObservationManager.class);
60  1 rom.startChannel("tcp");
61    }
62   
63    /**
64    * Validate sharing a simple Serializable event between two instances of {@link RemoteObservationManager}.
65    */
 
66  1 toggle @Test
67    public void testSerializableEvent() throws InterruptedException
68    {
69  1 EventListener localListener = mock(EventListener.class, "local");
70  1 EventListener remoteListener = mock(EventListener.class, "remote");
71   
72  1 TestEvent event = new TestEvent();
73   
74  1 Unserializable unserializable = new Unserializable();
75   
76  1 when(localListener.getName()).thenReturn("mylistener");
77  1 when(remoteListener.getName()).thenReturn("mylistener");
78  1 when(localListener.getEvents()).thenReturn(Arrays.asList(event));
79  1 when(remoteListener.getEvents()).thenReturn(Arrays.asList(event));
80   
81  1 getObservationManager1().addListener(localListener);
82  1 getObservationManager2().addListener(remoteListener);
83   
84  1 getObservationManager1().notify(event, "some source", "some data");
85  1 getObservationManager1().notify(event, unserializable, unserializable);
86  1 getObservationManager1().notify(new LogEvent(), "some source", "some data");
87   
88    // Make sure JGroups has enough time to send the message
89  1 Thread.sleep(1000);
90   
91  1 verify(localListener).onEvent(same(event), eq("some source"), eq("some data"));
92  1 verify(localListener).onEvent(same(event), same(unserializable), same(unserializable));
93  1 verify(remoteListener).onEvent(eq(event), eq("some source"), eq("some data"));
94    }
95    }