Source:
public void testGenerateAndUpdateJobCoordinatorMetadata() { Config jobConfig = new MapConfig(configMap); when(CoordinatorStreamUtil.readConfigFromCoordinatorStream(anyObject())).thenReturn(jobConfig); ClusterBasedJobCoordinator clusterBasedJobCoordinator = spy(ClusterBasedJobCoordinatorRunner.createFromMetadataStore(jobConfig)); JobCoordinatorMetadata previousMetadata = mock(JobCoordinatorMetadata.class); JobCoordinatorMetadata newMetadata = mock(JobCoordinatorMetadata.class); JobCoordinatorMetadataManager jobCoordinatorMetadataManager = mock(JobCoordinatorMetadataManager.class); JobModel mockJobModel = mock(JobModel.class); when(jobCoordinatorMetadataManager.readJobCoordinatorMetadata()).thenReturn(previousMetadata); when(jobCoordinatorMetadataManager.generateJobCoordinatorMetadata(any(), any())).thenReturn(newMetadata); when(jobCoordinatorMetadataManager.checkForMetadataChanges(newMetadata, previousMetadata)).thenReturn(false); when(clusterBasedJobCoordinator.createJobCoordinatorMetadataManager()).thenReturn(jobCoordinatorMetadataManager); clusterBasedJobCoordinator.generateAndUpdateJobCoordinatorMetadata(mockJobModel); assertFalse("JC metadata should remain unchanged", clusterBasedJobCoordinator.isMetadataChangedAcrossAttempts()); verify(jobCoordinatorMetadataManager, times(0)).writeJobCoordinatorMetadata(any()); when(jobCoordinatorMetadataManager.checkForMetadataChanges(newMetadata, previousMetadata)).thenReturn(true); clusterBasedJobCoordinator.generateAndUpdateJobCoordinatorMetadata(mockJobModel); assertTrue("JC metadata should be true", clusterBasedJobCoordinator.isMetadataChangedAcrossAttempts()); verify(jobCoordinatorMetadataManager, times(1)).writeJobCoordinatorMetadata(newMetadata); }

Target:
public void testGenerateAndUpdateJobCoordinatorMetadata() { Config jobConfig = new MapConfig(configMap); when(CoordinatorStreamUtil.readConfigFromCoordinatorStream(anyObject())).thenReturn(jobConfig); ClusterBasedJobCoordinator clusterBasedJobCoordinator = spy(ClusterBasedJobCoordinatorRunner.createFromMetadataStore(jobConfig)); JobCoordinatorMetadata previousMetadata = mock(JobCoordinatorMetadata.class); JobCoordinatorMetadata newMetadata = mock(JobCoordinatorMetadata.class); JobCoordinatorMetadataManager jobCoordinatorMetadataManager = mock(JobCoordinatorMetadataManager.class); JobModel mockJobModel = mock(JobModel.class); when(jobCoordinatorMetadataManager.readJobCoordinatorMetadata()).thenReturn(previousMetadata); when(jobCoordinatorMetadataManager.generateJobCoordinatorMetadata(any(), any())).thenReturn(newMetadata); when(jobCoordinatorMetadataManager.checkForMetadataChanges(newMetadata, previousMetadata)).thenReturn(false); when(clusterBasedJobCoordinator.createJobCoordinatorMetadataManager()).thenReturn(jobCoordinatorMetadataManager); clusterBasedJobCoordinator.generateAndUpdateJobCoordinatorMetadata(mockJobModel); assertFalse("JC metadata changed should remain unchanged", clusterBasedJobCoordinator.isMetadataChangedAcrossAttempts()); verify(jobCoordinatorMetadataManager, times(0)).writeJobCoordinatorMetadata(any()); when(jobCoordinatorMetadataManager.checkForMetadataChanges(newMetadata, previousMetadata)).thenReturn(true); clusterBasedJobCoordinator.generateAndUpdateJobCoordinatorMetadata(mockJobModel); assertTrue("JC metadata changed should be true", clusterBasedJobCoordinator.isMetadataChangedAcrossAttempts()); verify(jobCoordinatorMetadataManager, times(1)).writeJobCoordinatorMetadata(newMetadata); }