| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.store; |
| 21 |
|
|
| 22 |
|
import org.junit.Assert; |
| 23 |
|
import org.junit.Test; |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
@version |
| 29 |
|
@since |
| 30 |
|
|
| |
|
| 90.2% |
Uncovered Elements: 4 (41) |
Complexity: 14 |
Complexity Density: 0.48 |
|
| 31 |
|
public class StartableTransactionRunnableTest |
| 32 |
|
{ |
| 33 |
|
private final StartableTransactionRunnable testRunnable = new StartableTransactionRunnable(); |
| 34 |
|
|
| 35 |
|
private boolean hasRun; |
| 36 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 37 |
1 |
@Test(expected = IllegalStateException.class)... |
| 38 |
|
public void alreadyRunTest() throws Exception |
| 39 |
|
{ |
| 40 |
1 |
this.testRunnable.start(); |
| 41 |
1 |
this.testRunnable.start(); |
| 42 |
0 |
Assert.fail("exception was not thrown"); |
| 43 |
|
} |
| 44 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 45 |
1 |
@Test(expected = TransactionException.class)... |
| 46 |
|
public void rollbackAfterExceptionTest() throws Exception |
| 47 |
|
{ |
| 48 |
1 |
new TransactionRunnable() |
| 49 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
1 |
protected void onRun() throws Exception... |
| 51 |
|
{ |
| 52 |
1 |
throw new Exception(); |
| 53 |
|
} |
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 55 |
1 |
protected void onRollback()... |
| 56 |
|
{ |
| 57 |
1 |
itRan(); |
| 58 |
|
} |
| 59 |
|
} .runIn(this.testRunnable); |
| 60 |
|
|
| 61 |
1 |
try { |
| 62 |
1 |
this.testRunnable.start(); |
| 63 |
|
} catch (TransactionException e) { |
| 64 |
1 |
Assert.assertEquals("Wrong number of exceptions reported", 1, e.exceptionCount()); |
| 65 |
1 |
Assert.assertTrue("Rollback did not run after exception", hasRun()); |
| 66 |
1 |
throw e; |
| 67 |
|
} |
| 68 |
0 |
Assert.fail("exception was not thrown"); |
| 69 |
|
} |
| 70 |
|
|
| |
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
1PASS
|
|
| 71 |
1 |
@Test(expected = TransactionException.class)... |
| 72 |
|
public void exceptionInRollbackTest() throws Exception |
| 73 |
|
{ |
| 74 |
1 |
new TransactionRunnable() |
| 75 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
1 |
protected void onRun() throws Exception... |
| 77 |
|
{ |
| 78 |
1 |
throw new Exception(); |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
1 |
protected void onRollback() throws Exception... |
| 82 |
|
{ |
| 83 |
1 |
throw new Exception(); |
| 84 |
|
} |
| 85 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
1 |
protected void onComplete()... |
| 87 |
|
{ |
| 88 |
1 |
itRan(); |
| 89 |
|
} |
| 90 |
|
} .runIn(this.testRunnable); |
| 91 |
|
|
| 92 |
1 |
try { |
| 93 |
1 |
this.testRunnable.start(); |
| 94 |
|
} catch (TransactionException e) { |
| 95 |
1 |
Assert.assertEquals("Wrong number of exceptions reported", 2, e.exceptionCount()); |
| 96 |
1 |
Assert.assertTrue("Rollback failed and yet the exception did not warn of possible corruption.", |
| 97 |
|
e.isNonRecoverable()); |
| 98 |
1 |
Assert.assertTrue("Complete did not run after exception", hasRun()); |
| 99 |
1 |
throw e; |
| 100 |
|
} |
| 101 |
0 |
Assert.fail("exception was not thrown"); |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 107 |
1 |
@Test(expected = TransactionException.class)... |
| 108 |
|
public void exceptionInCompleteTest() throws Exception |
| 109 |
|
{ |
| 110 |
1 |
new TransactionRunnable() |
| 111 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 112 |
1 |
protected void onComplete() throws Exception... |
| 113 |
|
{ |
| 114 |
1 |
throw new Exception(); |
| 115 |
|
} |
| 116 |
|
} .runIn(this.testRunnable); |
| 117 |
|
|
| 118 |
1 |
this.testRunnable.start(); |
| 119 |
0 |
Assert.fail("exception was not thrown"); |
| 120 |
|
} |
| 121 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 122 |
2 |
public boolean hasRun()... |
| 123 |
|
{ |
| 124 |
2 |
return this.hasRun; |
| 125 |
|
} |
| 126 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
2 |
public void itRan()... |
| 128 |
|
{ |
| 129 |
2 |
this.hasRun = true; |
| 130 |
|
} |
| 131 |
|
} |