Skip to content

Commit 9a15907

Browse files
author
chengliefeng
committed
feature: add TCC three-phase hooks (apache#6731)
1 parent 6b2c5c6 commit 9a15907

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.integration.tx.api.fence.hook;
18+
19+
20+
import java.util.List;
21+
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
import static org.junit.jupiter.api.Assertions.assertThrows;
28+
import static org.mockito.Mockito.mock;
29+
30+
31+
public class TccHookManagerTest {
32+
33+
@BeforeEach
34+
public void setUp() {
35+
TccHookManager.clear();
36+
}
37+
38+
@Test
39+
public void testRegisterHook() {
40+
TccHook hook = mock(TccHook.class);
41+
TccHookManager.registerHook(hook);
42+
43+
List<TccHook> hooks = TccHookManager.getHooks();
44+
assertEquals(1, hooks.size());
45+
assertTrue(hooks.contains(hook));
46+
}
47+
48+
@Test
49+
public void testClear() {
50+
TccHook hook = mock(TccHook.class);
51+
TccHookManager.registerHook(hook);
52+
List<TccHook> hooks = TccHookManager.getHooks();
53+
assertEquals(1, hooks.size());
54+
assertTrue(hooks.contains(hook));
55+
56+
TccHookManager.clear();
57+
58+
assertTrue(TccHookManager.getHooks().isEmpty());
59+
}
60+
61+
@Test
62+
public void testGetHooks() {
63+
TccHook hook1 = mock(TccHook.class);
64+
TccHook hook2 = mock(TccHook.class);
65+
TccHookManager.registerHook(hook1);
66+
TccHookManager.registerHook(hook2);
67+
68+
List<TccHook> hooks = TccHookManager.getHooks();
69+
assertEquals(2, hooks.size());
70+
assertTrue(hooks.contains(hook1));
71+
assertTrue(hooks.contains(hook2));
72+
73+
// Check unmodifiable list
74+
assertThrows(UnsupportedOperationException.class, () -> hooks.add(mock(TccHook.class)));
75+
}
76+
}

0 commit comments

Comments
 (0)