@Test
  public void testRegisterRackChange() throws Exception {
    // member state mocks
    Injector injector = createStrictMock(Injector.class);
    Cluster cluster = createNiceMock(Cluster.class);
    Service service = createNiceMock(Service.class);
    ServiceComponent serviceComponent = createNiceMock(ServiceComponent.class);
    ServiceComponentHost serviceComponentHost = createNiceMock(ServiceComponentHost.class);
    StackId stackId = createNiceMock(StackId.class);
    Capture<AmbariManagementController> controllerCapture = EasyMock.newCapture();

    // expectations
    // constructor init
    constructorInit(injector, controllerCapture, createNiceMock(KerberosHelper.class));

    RepositoryInfo dummyRepoInfo = new RepositoryInfo();
    dummyRepoInfo.setRepoName("repo_name");

    expect(clusters.getCluster("c1")).andReturn(cluster).anyTimes();
    expect(service.getName()).andReturn("HDFS").anyTimes();

    Map<String, ServiceComponent> serviceComponents = new HashMap<>();
    serviceComponents.put("NAMENODE", serviceComponent);
    expect(service.getServiceComponents()).andReturn(serviceComponents).anyTimes();


    Map<String, ServiceComponentHost> schMap = new HashMap<>();
    schMap.put("host1", serviceComponentHost);
    expect(serviceComponent.getServiceComponentHosts()).andReturn(schMap).anyTimes();

    serviceComponentHost.setRestartRequired(true);

    Set<String> services = new HashSet<>();
    services.add("HDFS");

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setRestartRequiredAfterRackChange(true);
    expect(ambariMetaInfo.getService(service)).andReturn(serviceInfo);

    Map<String, Service> serviceMap = new HashMap<>();

    serviceMap.put("HDFS", service);
    expect(cluster.getServices()).andReturn(serviceMap).anyTimes();

    // replay mocks
    replay(injector, cluster, clusters, ambariMetaInfo, service, serviceComponent, serviceComponentHost, stackId);

    // test
    AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector);
    setAmbariMetaInfo(ambariMetaInfo, controller);

    controller.registerRackChange("c1");

    verify(injector, cluster, clusters, ambariMetaInfo, service, serviceComponent, serviceComponentHost, stackId);
  }
Ensure that RollbackException is thrown outside the updateClusters method
when a unique constraint violation occurs.
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java