1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.batch.retry.support;
18
19 import junit.framework.TestCase;
20
21 import org.springframework.batch.retry.RetryCallback;
22 import org.springframework.batch.retry.RetryContext;
23 import org.springframework.batch.retry.context.RetryContextSupport;
24
25
26
27
28 public class RetrySynchronizationManagerTests extends TestCase {
29
30 RetryTemplate template = new RetryTemplate();
31
32 protected void setUp() throws Exception {
33 super.setUp();
34 RetrySynchronizationManagerTests.clearAll();
35 RetryContext status = RetrySynchronizationManager.getContext();
36 assertNull(status);
37 }
38
39 public void testStatusIsStoredByTemplate() throws Exception {
40
41 RetryContext status = RetrySynchronizationManager.getContext();
42 assertNull(status);
43
44 template.execute(new RetryCallback<Object>() {
45 public Object doWithRetry(RetryContext status) throws Exception {
46 RetryContext global = RetrySynchronizationManager.getContext();
47 assertNotNull(status);
48 assertEquals(global, status);
49 return null;
50 }
51 });
52
53 status = RetrySynchronizationManager.getContext();
54 assertNull(status);
55 }
56
57 public void testStatusRegistration() throws Exception {
58 RetryContext status = new RetryContextSupport(null);
59 RetryContext value = RetrySynchronizationManager.register(status);
60 assertNull(value);
61 value = RetrySynchronizationManager.register(status);
62 assertEquals(status, value);
63 }
64
65 public void testClear() throws Exception {
66 RetryContext status = new RetryContextSupport(null);
67 RetryContext value = RetrySynchronizationManager.register(status);
68 assertNull(value);
69 RetrySynchronizationManager.clear();
70 value = RetrySynchronizationManager.register(status);
71 assertNull(value);
72 }
73
74 public void testParent() throws Exception {
75 RetryContext parent = new RetryContextSupport(null);
76 RetryContext child = new RetryContextSupport(parent);
77 assertSame(parent, child.getParent());
78 }
79
80
81
82
83
84 public static RetryContext clearAll() {
85 RetryContext result = null;
86 RetryContext context = RetrySynchronizationManager.clear();
87 while (context != null) {
88 result = context;
89 context = RetrySynchronizationManager.clear();
90 }
91 return result;
92 }
93 }