@@ -20,7 +20,9 @@ public class MemoryPoolsExportsTest {
2020 private MemoryPoolMXBean mockPoolsBean2 = Mockito .mock (MemoryPoolMXBean .class );
2121 private MemoryMXBean mockMemoryBean = Mockito .mock (MemoryMXBean .class );
2222 private MemoryUsage mockUsage1 = Mockito .mock (MemoryUsage .class );
23+ private MemoryUsage mockCollectionUsage1 = Mockito .mock (MemoryUsage .class );
2324 private MemoryUsage mockUsage2 = Mockito .mock (MemoryUsage .class );
25+ private MemoryUsage mockCollectionUsage2 = Mockito .mock (MemoryUsage .class );
2426 private List <MemoryPoolMXBean > mockList = Arrays .asList (mockPoolsBean1 , mockPoolsBean2 );
2527 private CollectorRegistry registry = new CollectorRegistry ();
2628 private MemoryPoolsExports collectorUnderTest ;
@@ -29,18 +31,28 @@ public class MemoryPoolsExportsTest {
2931 public void setUp () {
3032 when (mockPoolsBean1 .getName ()).thenReturn ("PS Eden Space" );
3133 when (mockPoolsBean1 .getUsage ()).thenReturn (mockUsage1 );
34+ when (mockPoolsBean1 .getCollectionUsage ()).thenReturn (mockCollectionUsage1 );
3235 when (mockPoolsBean2 .getName ()).thenReturn ("PS Old Gen" );
3336 when (mockPoolsBean2 .getUsage ()).thenReturn (mockUsage2 );
37+ when (mockPoolsBean2 .getCollectionUsage ()).thenReturn (mockCollectionUsage2 );
3438 when (mockMemoryBean .getHeapMemoryUsage ()).thenReturn (mockUsage1 );
3539 when (mockMemoryBean .getNonHeapMemoryUsage ()).thenReturn (mockUsage2 );
3640 when (mockUsage1 .getUsed ()).thenReturn (500000L );
3741 when (mockUsage1 .getCommitted ()).thenReturn (1000000L );
3842 when (mockUsage1 .getMax ()).thenReturn (2000000L );
3943 when (mockUsage1 .getInit ()).thenReturn (1000L );
44+ when (mockCollectionUsage1 .getUsed ()).thenReturn (400000L );
45+ when (mockCollectionUsage1 .getCommitted ()).thenReturn (800000L );
46+ when (mockCollectionUsage1 .getMax ()).thenReturn (1600000L );
47+ when (mockCollectionUsage1 .getInit ()).thenReturn (2000L );
4048 when (mockUsage2 .getUsed ()).thenReturn (10000L );
4149 when (mockUsage2 .getCommitted ()).thenReturn (20000L );
4250 when (mockUsage2 .getMax ()).thenReturn (3000000L );
4351 when (mockUsage2 .getInit ()).thenReturn (2000L );
52+ when (mockCollectionUsage2 .getUsed ()).thenReturn (20000L );
53+ when (mockCollectionUsage2 .getCommitted ()).thenReturn (40000L );
54+ when (mockCollectionUsage2 .getMax ()).thenReturn (6000000L );
55+ when (mockCollectionUsage2 .getInit ()).thenReturn (4000L );
4456 collectorUnderTest = new MemoryPoolsExports (mockMemoryBean , mockList ).register (registry );
4557 }
4658
@@ -74,6 +86,34 @@ public void testMemoryPools() {
7486 new String []{"pool" },
7587 new String []{"PS Eden Space" }),
7688 .0000001 );
89+ assertEquals (
90+ 400000L ,
91+ registry .getSampleValue (
92+ "jvm_memory_pool_collection_bytes_used" ,
93+ new String []{"pool" },
94+ new String []{"PS Eden Space" }),
95+ .0000001 );
96+ assertEquals (
97+ 800000L ,
98+ registry .getSampleValue (
99+ "jvm_memory_pool_collection_bytes_committed" ,
100+ new String []{"pool" },
101+ new String []{"PS Eden Space" }),
102+ .0000001 );
103+ assertEquals (
104+ 1600000L ,
105+ registry .getSampleValue (
106+ "jvm_memory_pool_collection_bytes_max" ,
107+ new String []{"pool" },
108+ new String []{"PS Eden Space" }),
109+ .0000001 );
110+ assertEquals (
111+ 2000L ,
112+ registry .getSampleValue (
113+ "jvm_memory_pool_collection_bytes_init" ,
114+ new String []{"pool" },
115+ new String []{"PS Eden Space" }),
116+ .0000001 );
77117 assertEquals (
78118 10000L ,
79119 registry .getSampleValue (
@@ -102,6 +142,34 @@ public void testMemoryPools() {
102142 new String []{"pool" },
103143 new String []{"PS Old Gen" }),
104144 .0000001 );
145+ assertEquals (
146+ 20000L ,
147+ registry .getSampleValue (
148+ "jvm_memory_pool_collection_bytes_used" ,
149+ new String []{"pool" },
150+ new String []{"PS Old Gen" }),
151+ .0000001 );
152+ assertEquals (
153+ 40000L ,
154+ registry .getSampleValue (
155+ "jvm_memory_pool_collection_bytes_committed" ,
156+ new String []{"pool" },
157+ new String []{"PS Old Gen" }),
158+ .0000001 );
159+ assertEquals (
160+ 6000000L ,
161+ registry .getSampleValue (
162+ "jvm_memory_pool_collection_bytes_max" ,
163+ new String []{"pool" },
164+ new String []{"PS Old Gen" }),
165+ .0000001 );
166+ assertEquals (
167+ 4000L ,
168+ registry .getSampleValue (
169+ "jvm_memory_pool_collection_bytes_init" ,
170+ new String []{"pool" },
171+ new String []{"PS Old Gen" }),
172+ .0000001 );
105173 }
106174
107175 @ Test
0 commit comments