| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 42 |
|
|
| 43 |
|
@version |
| 44 |
|
|
| 45 |
|
@ComponentList(ContextComponentManagerProvider.class) |
| |
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 3 |
Complexity Density: 0.08 |
|
| 46 |
|
public class DefaultJobExecutorTest |
| 47 |
|
{ |
| 48 |
|
@Rule |
| 49 |
|
public MockitoComponentMockingRule<JobExecutor> mocker = |
| 50 |
|
new MockitoComponentMockingRule<JobExecutor>(DefaultJobExecutor.class); |
| 51 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 52 |
1 |
@Before... |
| 53 |
|
public void before() throws Exception |
| 54 |
|
{ |
| 55 |
|
} |
| 56 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 57 |
4 |
private TestBasicGroupedJob groupedJob(String... path)... |
| 58 |
|
{ |
| 59 |
4 |
return new TestBasicGroupedJob(new JobGroupPath(Arrays.asList(path)), new DefaultRequest()); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 64 |
1 |
@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 |
|
|
| 74 |
1 |
jobA.lock(); |
| 75 |
1 |
jobAB.lock(); |
| 76 |
1 |
job12.lock(); |
| 77 |
1 |
job1.lock(); |
| 78 |
|
|
| 79 |
|
|
| 80 |
1 |
this.mocker.getComponentUnderTest().execute(jobA); |
| 81 |
|
|
| 82 |
1 |
Thread.sleep(10); |
| 83 |
|
|
| 84 |
1 |
this.mocker.getComponentUnderTest().execute(jobAB); |
| 85 |
|
|
| 86 |
1 |
Thread.sleep(10); |
| 87 |
|
|
| 88 |
1 |
this.mocker.getComponentUnderTest().execute(job12); |
| 89 |
|
|
| 90 |
1 |
Thread.sleep(10); |
| 91 |
|
|
| 92 |
1 |
this.mocker.getComponentUnderTest().execute(job1); |
| 93 |
|
|
| 94 |
1 |
Thread.sleep(10); |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
1 |
assertSame(State.WAITING, jobA.getStatus().getState()); |
| 100 |
1 |
assertNull(jobAB.getStatus().getState()); |
| 101 |
|
|
| 102 |
|
|
| 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 |
|
|
| 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 |
|
|
| 118 |
|
|
| 119 |
1 |
assertSame(State.WAITING, job12.getStatus().getState()); |
| 120 |
1 |
assertNull(job1.getStatus().getState()); |
| 121 |
|
|
| 122 |
|
|
| 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 |
|
|
| 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 |
|
} |