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

File DefaultJobExecutorTest.java

 

Code metrics

0
37
3
1
136
71
3
0.08
12.33
3
1

Classes

Class Line # Actions
DefaultJobExecutorTest 46 37 0% 3 0
1.0100%
 

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.job.internal;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Before;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.component.internal.ContextComponentManagerProvider;
28    import org.xwiki.component.manager.ComponentLookupException;
29    import org.xwiki.job.DefaultRequest;
30    import org.xwiki.job.JobExecutor;
31    import org.xwiki.job.JobGroupPath;
32    import org.xwiki.job.event.status.JobStatus.State;
33    import org.xwiki.job.test.TestBasicGroupedJob;
34    import org.xwiki.test.annotation.ComponentList;
35    import org.xwiki.test.mockito.MockitoComponentMockingRule;
36   
37    import static org.junit.Assert.assertNull;
38    import static org.junit.Assert.assertSame;
39   
40    /**
41    * Validate {@link DefaultJobExecutor};
42    *
43    * @version $Id: fc6ad8ece2c5a2d7862f979f33bf4bcc8b05de94 $
44    */
45    @ComponentList(ContextComponentManagerProvider.class)
 
46    public class DefaultJobExecutorTest
47    {
48    @Rule
49    public MockitoComponentMockingRule<JobExecutor> mocker =
50    new MockitoComponentMockingRule<JobExecutor>(DefaultJobExecutor.class);
51   
 
52  1 toggle @Before
53    public void before() throws Exception
54    {
55    }
56   
 
57  4 toggle private TestBasicGroupedJob groupedJob(String... path)
58    {
59  4 return new TestBasicGroupedJob(new JobGroupPath(Arrays.asList(path)), new DefaultRequest());
60    }
61   
62    // Tests
63   
 
64  1 toggle @Test
65    public void testMatchingGroupPathAreBlocked() throws ComponentLookupException, InterruptedException
66    {
67  1 TestBasicGroupedJob jobA = groupedJob("A");
68  1 TestBasicGroupedJob jobAB = groupedJob("A", "B");
69   
70  1 TestBasicGroupedJob job12 = groupedJob("1", "2");
71  1 TestBasicGroupedJob job1 = groupedJob("1");
72   
73    // Pre-lock all jobs
74  1 jobA.lock();
75  1 jobAB.lock();
76  1 job12.lock();
77  1 job1.lock();
78   
79    // Give all jobs to JobExecutor
80  1 this.mocker.getComponentUnderTest().execute(jobA);
81    // Give enough time for the job to be fully taken into account
82  1 Thread.sleep(10);
83   
84  1 this.mocker.getComponentUnderTest().execute(jobAB);
85    // Give enough time for the job to be fully taken into account
86  1 Thread.sleep(10);
87   
88  1 this.mocker.getComponentUnderTest().execute(job12);
89    // Give enough time for the job to be fully taken into account
90  1 Thread.sleep(10);
91   
92  1 this.mocker.getComponentUnderTest().execute(job1);
93    // Give enough time for the job to be fully taken into account
94  1 Thread.sleep(10);
95   
96    ////////////////////
97    // A and A/B
98   
99  1 assertSame(State.WAITING, jobA.getStatus().getState());
100  1 assertNull(jobAB.getStatus().getState());
101   
102    // Next job
103  1 jobA.unlock();
104  1 Thread.sleep(10);
105   
106  1 assertSame(State.FINISHED, jobA.getStatus().getState());
107  1 assertSame(State.WAITING, jobAB.getStatus().getState());
108   
109    // Next job
110  1 jobAB.unlock();
111  1 Thread.sleep(10);
112   
113  1 assertSame(State.FINISHED, jobA.getStatus().getState());
114  1 assertSame(State.FINISHED, jobAB.getStatus().getState());
115   
116    ////////////////////
117    // 1/2 and 1
118   
119  1 assertSame(State.WAITING, job12.getStatus().getState());
120  1 assertNull(job1.getStatus().getState());
121   
122    // Next job
123  1 job12.unlock();
124  1 Thread.sleep(10);
125   
126  1 assertSame(State.FINISHED, job12.getStatus().getState());
127  1 assertSame(State.WAITING, job1.getStatus().getState());
128   
129    // Next job
130  1 job1.unlock();
131  1 Thread.sleep(10);
132   
133  1 assertSame(State.FINISHED, job1.getStatus().getState());
134  1 assertSame(State.FINISHED, job1.getStatus().getState());
135    }
136    }