File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
core/src/test/java/com/taobao/arthas/core/shell/command/internal Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .taobao .arthas .core .shell .command .internal ;
2+
3+ import com .taobao .arthas .core .shell .term .Term ;
4+ import io .netty .util .internal .InternalThreadLocalMap ;
5+ import org .junit .Assert ;
6+ import org .junit .Test ;
7+ import org .mockito .Mockito ;
8+
9+ public class TermHandlerTest {
10+
11+ @ Test
12+ public void testShouldRemoveNettyInternalThreadLocalMapAfterWrite () {
13+ InternalThreadLocalMap .remove ();
14+
15+ Term term = Mockito .mock (Term .class );
16+ Mockito .when (term .write (Mockito .anyString ())).thenAnswer (invocation -> {
17+ InternalThreadLocalMap .get ();
18+ return term ;
19+ });
20+
21+ new TermHandler (term ).apply ("hello\n " );
22+
23+ Assert .assertNull (InternalThreadLocalMap .getIfSet ());
24+ }
25+
26+ @ Test
27+ public void testShouldRemoveNettyInternalThreadLocalMapWhenWriteThrows () {
28+ InternalThreadLocalMap .remove ();
29+
30+ Term term = Mockito .mock (Term .class );
31+ Mockito .when (term .write (Mockito .anyString ())).thenAnswer (invocation -> {
32+ InternalThreadLocalMap .get ();
33+ throw new RuntimeException ("boom" );
34+ });
35+
36+ try {
37+ new TermHandler (term ).apply ("hello\n " );
38+ Assert .fail ("should throw" );
39+ } catch (RuntimeException e ) {
40+ Assert .assertEquals ("boom" , e .getMessage ());
41+ }
42+
43+ Assert .assertNull (InternalThreadLocalMap .getIfSet ());
44+ }
45+ }
46+
You can’t perform that action at this time.
0 commit comments