1616
1717package io .aiven .kafka .tieredstorage .manifest ;
1818
19+ import javax .management .ObjectName ;
20+
1921import java .io .ByteArrayInputStream ;
2022import java .io .IOException ;
2123import java .io .InputStream ;
24+ import java .lang .management .ManagementFactory ;
2225import java .time .Duration ;
2326import java .util .Map ;
2427import java .util .Optional ;
4851import static org .assertj .core .api .Assertions .assertThatThrownBy ;
4952import static org .mockito .ArgumentMatchers .anyString ;
5053import static org .mockito .Mockito .doAnswer ;
54+ import static org .mockito .Mockito .times ;
5155import static org .mockito .Mockito .verify ;
5256import static org .mockito .Mockito .verifyNoMoreInteractions ;
5357import static org .mockito .Mockito .when ;
@@ -86,23 +90,23 @@ class SegmentManifestProviderTest {
8690 void setup () {
8791 provider = new SegmentManifestProvider (
8892 OBJECT_KEY , Optional .of (1000L ), Optional .empty (), storage , MAPPER ,
89- ForkJoinPool .commonPool ());
93+ ForkJoinPool .commonPool (), false );
9094 }
9195
9296 @ Test
9397 void unboundedShouldBeCreated () {
9498 assertThatNoException ()
9599 .isThrownBy (() -> new SegmentManifestProvider (
96100 OBJECT_KEY , Optional .empty (), Optional .of (Duration .ofMillis (1 )), storage , MAPPER ,
97- ForkJoinPool .commonPool ()));
101+ ForkJoinPool .commonPool (), false ));
98102 }
99103
100104 @ Test
101105 void withoutRetentionLimitsShouldBeCreated () {
102106 assertThatNoException ()
103107 .isThrownBy (() -> new SegmentManifestProvider (
104108 OBJECT_KEY , Optional .of (1L ), Optional .empty (), storage , MAPPER ,
105- ForkJoinPool .commonPool ()));
109+ ForkJoinPool .commonPool (), false ));
106110 }
107111
108112 @ Test
@@ -120,6 +124,40 @@ void shouldReturnAndCache() throws StorageBackendException, IOException {
120124 verifyNoMoreInteractions (storage );
121125 }
122126
127+ @ Test
128+ void invalidateCache_jmx () throws Exception {
129+ provider = new SegmentManifestProvider (
130+ OBJECT_KEY , Optional .of (1000L ), Optional .empty (), storage , MAPPER ,
131+ ForkJoinPool .commonPool (), true );
132+
133+ final String key = "topic-AAAAAAAAAAAAAAAAAAAAAQ/7/00000000000000000023-AAAAAAAAAAAAAAAAAAAAAA.rsm-manifest" ;
134+ final SegmentManifestV1 expectedManifest = new SegmentManifestV1 (
135+ new FixedSizeChunkIndex (100 , 1000 , 110 , 110 ),
136+ false , null
137+ );
138+ when (storage .fetch (key ))
139+ .thenReturn (new ByteArrayInputStream (MANIFEST .getBytes ()));
140+ assertThat (provider .get (REMOTE_LOG_METADATA )).isEqualTo (expectedManifest );
141+ verify (storage ).fetch (key );
142+
143+ final var mbeanName = new ObjectName (SegmentManifestCacheManager .MBEAN_NAME );
144+ final var mbeanServer = ManagementFactory .getPlatformMBeanServer ();
145+ assertThat (mbeanServer .isRegistered (mbeanName )).isTrue ();
146+
147+ final var sizeBefore = provider .cache ().estimatedSize ();
148+ assertThat (sizeBefore ).isEqualTo (1L );
149+
150+ mbeanServer .invoke (mbeanName , "clean" , new Object []{}, new String []{});
151+
152+ final var sizeAfter = provider .cache ().estimatedSize ();
153+ assertThat (sizeAfter ).isEqualTo (0L );
154+
155+ when (storage .fetch (key ))
156+ .thenReturn (new ByteArrayInputStream (MANIFEST .getBytes ()));
157+ assertThat (provider .get (REMOTE_LOG_METADATA )).isEqualTo (expectedManifest );
158+ verify (storage , times (2 )).fetch (key );
159+ }
160+
123161 @ Test
124162 void shouldPropagateStorageBackendException () throws StorageBackendException {
125163 when (storage .fetch (anyString ()))
0 commit comments