1818package org .apache .cassandra .service ;
1919
2020import org .apache .cassandra .config .DatabaseDescriptor ;
21- import org .junit .Assert ;
2221import org .junit .Before ;
2322import org .junit .BeforeClass ;
2423import org .junit .Test ;
2524
25+ import static org .junit .Assert .assertEquals ;
26+ import static org .junit .Assert .assertFalse ;
27+ import static org .junit .Assert .assertTrue ;
28+ import static org .junit .Assert .fail ;
29+
30+
2631public class GCInspectorTest
2732{
2833
@@ -43,49 +48,98 @@ public void before()
4348 @ Test
4449 public void ensureStaticFieldsHydrateFromConfig ()
4550 {
46- Assert .assertEquals (DatabaseDescriptor .getGCLogThreshold (), gcInspector .getGcLogThresholdInMs ());
47- Assert .assertEquals (DatabaseDescriptor .getGCWarnThreshold (), gcInspector .getGcWarnThresholdInMs ());
51+ assertEquals (DatabaseDescriptor .getGCLogThreshold (), gcInspector .getGcLogThresholdInMs ());
52+ assertEquals (DatabaseDescriptor .getGCWarnThreshold (), gcInspector .getGcWarnThresholdInMs ());
53+ assertEquals (DatabaseDescriptor .getGCConcurrentPhaseLogThreshold (), gcInspector .getGcConcurrentPhaseLogThresholdInMs ());
54+ assertEquals (DatabaseDescriptor .getGCConcurrentPhaseWarnThreshold (), gcInspector .getGcConcurrentPhaseWarnThresholdInMs ());
4855 }
4956
5057 @ Test
5158 public void ensureStatusIsCalculated ()
5259 {
53- Assert . assertTrue (gcInspector .getStatusThresholdInMs () > 0 );
60+ assertTrue (gcInspector .getStatusThresholdInMs () > 0 );
5461 }
5562
56- @ Test ( expected = IllegalArgumentException . class )
63+ @ Test
5764 public void ensureWarnGreaterThanLog ()
5865 {
59- gcInspector .setGcWarnThresholdInMs (gcInspector .getGcLogThresholdInMs ());
66+ try
67+ {
68+ gcInspector .setGcWarnThresholdInMs (gcInspector .getGcLogThresholdInMs ());
69+ fail ("Expect IllegalArgumentException" );
70+ }
71+ catch (IllegalArgumentException e )
72+ {
73+ // expected
74+ }
75+ try
76+ {
77+ gcInspector .setGcConcurrentPhaseWarnThresholdInMs (gcInspector .getGcConcurrentPhaseLogThresholdInMs ());
78+ fail ("Expect IllegalArgumentException" );
79+ }
80+ catch (IllegalArgumentException e )
81+ {
82+ // expected
83+ }
6084 }
6185
6286 @ Test
6387 public void ensureZeroIsOk ()
6488 {
6589 gcInspector .setGcWarnThresholdInMs (0 );
66- Assert .assertEquals (gcInspector .getStatusThresholdInMs (), gcInspector .getGcLogThresholdInMs ());
67- Assert .assertEquals (0 , DatabaseDescriptor .getGCWarnThreshold ());
68- Assert .assertEquals (200 , DatabaseDescriptor .getGCLogThreshold ());
90+ assertEquals (gcInspector .getStatusThresholdInMs (), gcInspector .getGcLogThresholdInMs ());
91+ assertEquals (0 , DatabaseDescriptor .getGCWarnThreshold ());
92+ assertEquals (200 , DatabaseDescriptor .getGCLogThreshold ());
93+ gcInspector .setGcConcurrentPhaseWarnThresholdInMs (0 );
94+ assertEquals (gcInspector .getGcConcurrentPhaseLogThresholdInMs (), gcInspector .getGcConcurrentPhaseWarnThresholdInMs ());
95+ assertEquals (0 , DatabaseDescriptor .getGCConcurrentPhaseWarnThreshold ());
96+ assertEquals (1000 , DatabaseDescriptor .getGCConcurrentPhaseLogThreshold ());
6997 }
7098
71- @ Test ( expected = IllegalArgumentException . class )
99+ @ Test
72100 public void ensureLogLessThanWarn ()
73101 {
74- Assert . assertEquals (200 , gcInspector .getGcLogThresholdInMs ());
102+ assertEquals (200 , gcInspector .getGcLogThresholdInMs ());
75103 gcInspector .setGcWarnThresholdInMs (1000 );
76- Assert .assertEquals (1000 , gcInspector .getGcWarnThresholdInMs ());
77- gcInspector .setGcLogThresholdInMs (gcInspector .getGcWarnThresholdInMs () + 1 );
104+ assertEquals (1000 , gcInspector .getGcWarnThresholdInMs ());
105+ try
106+ {
107+ gcInspector .setGcLogThresholdInMs (gcInspector .getGcWarnThresholdInMs () + 1 );
108+ fail ("Expect IllegalArgumentException" );
109+ }
110+ catch (IllegalArgumentException e )
111+ {
112+ // expected
113+ }
114+ assertEquals (1000 , gcInspector .getGcLogThresholdInMs ());
115+ gcInspector .setGcConcurrentPhaseWarnThresholdInMs (2000 );
116+ assertEquals (2000 , gcInspector .getGcConcurrentPhaseWarnThresholdInMs ());
117+ try
118+ {
119+ gcInspector .setGcConcurrentPhaseLogThresholdInMs (gcInspector .getGcConcurrentPhaseWarnThresholdInMs () + 1 );
120+ fail ("Expect IllegalArgumentException" );
121+ }
122+ catch (IllegalArgumentException e )
123+ {
124+ // expected
125+ }
78126 }
79127
80128 @ Test
81129 public void testDefaults ()
82130 {
83131 gcInspector .setGcLogThresholdInMs (200 );
84132 gcInspector .setGcWarnThresholdInMs (1000 );
85- Assert .assertEquals (200 , DatabaseDescriptor .getGCLogThreshold ());
86- Assert .assertEquals (200 , gcInspector .getGcLogThresholdInMs ());
87- Assert .assertEquals (1000 , DatabaseDescriptor .getGCWarnThreshold ());
88- Assert .assertEquals (1000 , gcInspector .getGcWarnThresholdInMs ());
133+ gcInspector .setGcConcurrentPhaseLogThresholdInMs (1000 );
134+ gcInspector .setGcConcurrentPhaseWarnThresholdInMs (2000 );
135+ assertEquals (200 , DatabaseDescriptor .getGCLogThreshold ());
136+ assertEquals (200 , gcInspector .getGcLogThresholdInMs ());
137+ assertEquals (1000 , DatabaseDescriptor .getGCWarnThreshold ());
138+ assertEquals (1000 , gcInspector .getGcWarnThresholdInMs ());
139+ assertEquals (1000 , DatabaseDescriptor .getGCConcurrentPhaseLogThreshold ());
140+ assertEquals (1000 , gcInspector .getGcConcurrentPhaseLogThresholdInMs ());
141+ assertEquals (2000 , DatabaseDescriptor .getGCConcurrentPhaseWarnThreshold ());
142+ assertEquals (2000 , gcInspector .getGcConcurrentPhaseWarnThresholdInMs ());
89143 }
90144
91145 @ Test (expected =IllegalArgumentException .class )
@@ -94,4 +148,20 @@ public void testMaxValue()
94148 gcInspector .setGcLogThresholdInMs (200 );
95149 gcInspector .setGcWarnThresholdInMs (Integer .MAX_VALUE +1L );
96150 }
151+
152+ @ Test
153+ public void testIsConcurrentPhase ()
154+ {
155+ assertTrue ("No GC cause should be considered concurrent" ,
156+ GCInspector .isConcurrentPhase ("No GC" , "SomeGCName" ));
157+ assertTrue ("Shenandoah Cycles should be considered concurrent" ,
158+ GCInspector .isConcurrentPhase ("SomeCause" , "Shenandoah Cycles" ));
159+ assertTrue ("ZGC Cycles should be considered concurrent" ,
160+ GCInspector .isConcurrentPhase ("SomeCause" , "ZGC Cycles" ));
161+
162+ assertFalse ("ParallelGC should not be considered concurrent" ,
163+ GCInspector .isConcurrentPhase ("Allocation Failure" , "PS Scavenge" ));
164+ assertFalse ("G1 Young Generation should not be considered concurrent" ,
165+ GCInspector .isConcurrentPhase ("G1 Evacuation Pause" , "G1 Young Generation" ));
166+ }
97167}
0 commit comments