/
ReaperMonitorTest.java
97 lines (72 loc) · 2.48 KB
/
ReaperMonitorTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Copyright The Narayana Authors
SPDX-License-Identifier: Apache-2.0
*/
package com.hp.mwtests.ts.arjuna.reaper;
import static org.junit.Assert.assertTrue;
import org.jboss.byteman.contrib.bmunit.BMScript;
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.arjuna.ats.arjuna.AtomicAction;
import com.arjuna.ats.arjuna.common.Uid;
import com.arjuna.ats.arjuna.coordinator.TransactionReaper;
import com.arjuna.ats.arjuna.coordinator.listener.ReaperMonitor;
@RunWith(BMUnitRunner.class)
@BMScript("reaper")
public class ReaperMonitorTest
{
class DummyMonitor implements ReaperMonitor
{
public synchronized void rolledBack (Uid txId)
{
success = true;
notify();
notified = true;
}
public synchronized void markedRollbackOnly (Uid txId)
{
success = false;
notify();
notified = true;
}
public boolean success = false;
public boolean notified = false;
public synchronized boolean checkSucceeded(int msecsTimeout)
{
if (!notified) {
try {
wait(msecsTimeout);
} catch (InterruptedException e) {
// ignore
}
}
return success;
}
}
@Test
public void test()
{
TransactionReaper reaper = TransactionReaper.transactionReaper();
DummyMonitor listener = new DummyMonitor();
reaper.addListener(listener);
AtomicAction A = new AtomicAction();
A.begin();
/*
* the reaper byteman script will make sure we synchronize with the reaper after this call
* just before it schedules the reapable for processing. the timout in the check method is
* there in case something is really wrong and the reapable does not get cancelled
*/
reaper.insert(A, 1);
assertTrue(listener.checkSucceeded(30 * 1000));
assertTrue(reaper.removeListener(listener));
// insert a new transaction with a longer timeout and check that we can find the remaining time
A = new AtomicAction();
reaper.insert(A, 1000);
long remaining = reaper.getRemainingTimeoutMills(A);
assertTrue(remaining != 0);
// ok now remove it
reaper.remove(A);
}
public static boolean success = false;
}