DefaultMigrationEventManager implements MigrationEventManager, CrossDcLeaderAware { @VisibleForTesting protected boolean diff(MigrationEvent prev, MigrationEvent future) { for (MigrationCluster migrationCluster : prev.getMigrationClusters()) { for (MigrationCluster newMigrationCluster : future.getMigrationClusters()) { if (!migrationCluster.clusterName().equals(newMigrationCluster.clusterName())) { continue; } if (migrationCluster.getStatus().getPercent() < newMigrationCluster.getStatus().getPercent()) { return true; } } } return false; }  @PostConstruct void defaultMigrationEventManager(); @PreDestroy void shutdown(); @Override void addEvent(MigrationEvent event); @Override MigrationEvent getEvent(long eventId); void removeEvent(long id); @Override void update(Object args, Observable observable); @Override void isCrossDcLeader(); @Override void notCrossDcLeader();  }
@Test public void testDiffWithNoDiff() { MigrationEvent prev = mock(MigrationEvent.class); MigrationEvent future = mock(MigrationEvent.class); when(prev.isDone()).thenReturn(false); when(future.isDone()).thenReturn(false); MigrationCluster migrationCluster = mock(MigrationCluster.class); when(migrationCluster.clusterName()).thenReturn("cluster1"); when(migrationCluster.getStatus()).thenReturn(MigrationStatus.Migrating); when(prev.getMigrationClusters()).thenReturn(Lists.newArrayList(migrationCluster)); when(future.getMigrationClusters()).thenReturn(Lists.newArrayList(migrationCluster)); Assert.assertFalse(migrationEventManager.diff(prev, future)); }
@Test public void testDiffWithDiff() { MigrationEvent prev = mock(MigrationEvent.class); MigrationEvent future = mock(MigrationEvent.class); when(prev.isDone()).thenReturn(false); when(future.isDone()).thenReturn(false); MigrationCluster migrationCluster = mock(MigrationCluster.class); when(migrationCluster.clusterName()).thenReturn("cluster1"); when(migrationCluster.getStatus()).thenReturn(MigrationStatus.Migrating); MigrationCluster newMigrationCluster = mock(MigrationCluster.class); when(newMigrationCluster.clusterName()).thenReturn("cluster1"); when(newMigrationCluster.getStatus()).thenReturn(MigrationStatus.Success); when(prev.getMigrationClusters()).thenReturn(Lists.newArrayList(migrationCluster)); when(future.getMigrationClusters()).thenReturn(Lists.newArrayList(newMigrationCluster)); Assert.assertTrue(migrationEventManager.diff(prev, future)); }