5252import org .opensearch .gateway .remote .ClusterMetadataManifest ;
5353import org .opensearch .gateway .remote .ClusterStateDiffManifest ;
5454import org .opensearch .gateway .remote .RemoteClusterStateService ;
55+ import org .opensearch .gateway .remote .RemoteDownloadStats ;
5556import org .opensearch .node .Node ;
5657import org .opensearch .telemetry .tracing .noop .NoopTracer ;
5758import org .opensearch .test .OpenSearchTestCase ;
6465import java .util .Collections ;
6566import java .util .Map ;
6667import java .util .Optional ;
68+ import java .util .concurrent .atomic .AtomicLong ;
6769import java .util .function .Function ;
6870
6971import org .mockito .Mockito ;
7072
73+ import static org .opensearch .gateway .remote .RemoteDownloadStats .INCOMING_PUBLICATION_FAILED_COUNT ;
7174import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY ;
7275import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY ;
7376import static org .hamcrest .Matchers .containsString ;
@@ -180,8 +183,8 @@ public void testHandleIncomingRemotePublishRequestWhenNoCurrentPublishRequest()
180183 () -> handler .handleIncomingRemotePublishRequest (remotePublishRequest )
181184 );
182185 assertThat (e .getMessage (), containsString ("publication to self failed" ));
183- verify (remoteClusterStateService , times (0 )).fullDownloadFailed ();
184- verify (remoteClusterStateService , times (1 )).diffDownloadFailed ();
186+ verify (remoteClusterStateService , times (0 )).fullIncomingPublicationFailed ();
187+ verify (remoteClusterStateService , times (1 )).diffIncomingPublicationFailed ();
185188 verifyNoMoreInteractions (remoteClusterStateService );
186189 }
187190
@@ -207,8 +210,8 @@ public void testHandleIncomingRemotePublishRequestWhenTermMismatch() {
207210 () -> handler .handleIncomingRemotePublishRequest (remotePublishRequest )
208211 );
209212 assertThat (e .getMessage (), containsString ("publication to self failed" ));
210- verify (remoteClusterStateService , times (0 )).fullDownloadFailed ();
211- verify (remoteClusterStateService , times (1 )).diffDownloadFailed ();
213+ verify (remoteClusterStateService , times (0 )).fullIncomingPublicationFailed ();
214+ verify (remoteClusterStateService , times (1 )).diffIncomingPublicationFailed ();
212215 verifyNoMoreInteractions (remoteClusterStateService );
213216 }
214217
@@ -234,8 +237,8 @@ public void testHandleIncomingRemotePublishRequestWhenVersionMismatch() {
234237 () -> handler .handleIncomingRemotePublishRequest (remotePublishRequest )
235238 );
236239 assertThat (e .getMessage (), containsString ("publication to self failed" ));
237- verify (remoteClusterStateService , times (1 )).diffDownloadFailed ();
238- verify (remoteClusterStateService , times (0 )).fullDownloadFailed ();
240+ verify (remoteClusterStateService , times (1 )).diffIncomingPublicationFailed ();
241+ verify (remoteClusterStateService , times (0 )).fullIncomingPublicationFailed ();
239242 verifyNoMoreInteractions (remoteClusterStateService );
240243 }
241244
@@ -263,20 +266,20 @@ public void testHandleIncomingRemotePublishRequestForLocalNode() throws IOExcept
263266
264267 public void testDownloadRemotePersistedFullStateFailedStats () throws IOException {
265268 RemoteClusterStateService remoteClusterStateService = mock (RemoteClusterStateService .class );
266- PersistedStateStats remoteFullDownloadStats = new PersistedStateStats ("dummy_full_stats" );
267- PersistedStateStats remoteDiffDownloadStats = new PersistedStateStats ("dummy_diff_stats" );
269+ PersistedStateStats remoteFullDownloadStats = new RemoteDownloadStats ("dummy_full_stats" );
270+ PersistedStateStats remoteDiffDownloadStats = new RemoteDownloadStats ("dummy_diff_stats" );
268271 when (remoteClusterStateService .getFullDownloadStats ()).thenReturn (remoteFullDownloadStats );
269272 when (remoteClusterStateService .getDiffDownloadStats ()).thenReturn (remoteDiffDownloadStats );
270273
271274 doAnswer ((i ) -> {
272- remoteFullDownloadStats .stateFailed ( );
275+ remoteFullDownloadStats .getExtendedFields (). put ( INCOMING_PUBLICATION_FAILED_COUNT , new AtomicLong ( 1 ) );
273276 return null ;
274- }).when (remoteClusterStateService ).fullDownloadFailed ();
277+ }).when (remoteClusterStateService ).fullIncomingPublicationFailed ();
275278
276279 doAnswer ((i ) -> {
277- remoteDiffDownloadStats .stateFailed ( );
280+ remoteDiffDownloadStats .getExtendedFields (). put ( INCOMING_PUBLICATION_FAILED_COUNT , new AtomicLong ( 1 ) );
278281 return null ;
279- }).when (remoteClusterStateService ).diffDownloadFailed ();
282+ }).when (remoteClusterStateService ).diffIncomingPublicationFailed ();
280283
281284 PublishWithJoinResponse expectedPublishResponse = new PublishWithJoinResponse (new PublishResponse (TERM , VERSION ), Optional .empty ());
282285 Function <PublishRequest , PublishWithJoinResponse > handlePublishRequest = p -> expectedPublishResponse ;
@@ -294,8 +297,8 @@ public void testDownloadRemotePersistedFullStateFailedStats() throws IOException
294297 handler .setCurrentPublishRequestToSelf (publishRequest );
295298
296299 assertThrows (IllegalStateException .class , () -> handler .handleIncomingRemotePublishRequest (remotePublishRequest ));
297- assertEquals (1 , remoteClusterStateService .getDiffDownloadStats ().getFailedCount ());
298- assertEquals (0 , remoteClusterStateService .getFullDownloadStats ().getFailedCount ());
300+ assertEquals (1 , remoteClusterStateService .getDiffDownloadStats ().getExtendedFields (). get ( INCOMING_PUBLICATION_FAILED_COUNT ). get ());
301+ assertEquals (0 , remoteClusterStateService .getFullDownloadStats ().getExtendedFields (). get ( INCOMING_PUBLICATION_FAILED_COUNT ). get ());
299302 }
300303
301304 public void testDownloadRemotePersistedDiffStateFailedStats () throws IOException {
@@ -309,9 +312,9 @@ public void testDownloadRemotePersistedDiffStateFailedStats() throws IOException
309312 when (remoteClusterStateService .getClusterMetadataManifestByFileName (any (), any ())).thenReturn (metadataManifest );
310313
311314 doAnswer ((i ) -> {
312- remoteDiffDownloadStats .stateFailed ( );
315+ remoteDiffDownloadStats .getExtendedFields (). put ( INCOMING_PUBLICATION_FAILED_COUNT , new AtomicLong ( 1 ) );
313316 return null ;
314- }).when (remoteClusterStateService ).diffDownloadFailed ();
317+ }).when (remoteClusterStateService ).diffIncomingPublicationFailed ();
315318
316319 PublishWithJoinResponse expectedPublishResponse = new PublishWithJoinResponse (new PublishResponse (TERM , VERSION ), Optional .empty ());
317320 Function <PublishRequest , PublishWithJoinResponse > handlePublishRequest = p -> expectedPublishResponse ;
@@ -333,7 +336,7 @@ public void testDownloadRemotePersistedDiffStateFailedStats() throws IOException
333336 handler .setCurrentPublishRequestToSelf (publishRequest );
334337
335338 assertThrows (NullPointerException .class , () -> handler .handleIncomingRemotePublishRequest (remotePublishRequest ));
336- assertEquals (1 , remoteClusterStateService .getDiffDownloadStats ().getFailedCount ());
339+ assertEquals (1 , remoteClusterStateService .getDiffDownloadStats ().getExtendedFields (). get ( INCOMING_PUBLICATION_FAILED_COUNT ). get ());
337340
338341 }
339342
0 commit comments