MonitorRunningInstance implements Closeable { @VisibleForTesting boolean serverListHasChanged(InstanceState instanceState, InstanceState localCurrentInstanceState) { if ( localCurrentInstanceState == null ) { return false; } ServerList serverList = instanceState.getServerList().filterOutObservers(); ServerList localServerList = localCurrentInstanceState.getServerList().filterOutObservers(); if ( !serverList.equals(localServerList) ) { return true; } ServerSpec us = UsState.findUs(exhibitor, instanceState.getServerList().getSpecs()); ServerSpec localUs = UsState.findUs(exhibitor, localCurrentInstanceState.getServerList().getSpecs()); return (us == null) || !us.equals(localUs); } MonitorRunningInstance(Exhibitor exhibitor); void start(); @Override void close(); InstanceStateTypes getCurrentInstanceState(); boolean isCurrentlyLeader(); int getRestartCount();  }
@Test public void testServerListHasChanged() throws Exception { InstanceConfig config = new InstanceConfig() { @Override public String getString(StringConfigs config) { switch ( config ) { case SERVERS_SPEC: { return "S:1:foo,S:2:bar"; } } return null; } @Override public int getInt(IntConfigs config) { return 0; } }; Exhibitor mockExhibitor = makeMockExhibitor(config, "foo"); MonitorRunningInstance monitor = new MonitorRunningInstance(mockExhibitor); StateAndLeader stateAndLeader = monitor.getStateAndLeader(); InstanceState localCurrentInstanceState = new InstanceState(new ServerList(config.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(config)); InstanceConfig newConfig = new InstanceConfig() { @Override public String getString(StringConfigs config) { switch ( config ) { case SERVERS_SPEC: { return "S:1:foo,S:2:bar,O:3:snafu"; } } return null; } @Override public int getInt(IntConfigs config) { return 0; } }; InstanceState instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig)); Assert.assertFalse(monitor.serverListHasChanged(instanceState, localCurrentInstanceState)); newConfig = new InstanceConfig() { @Override public String getString(StringConfigs config) { switch ( config ) { case SERVERS_SPEC: { return "S:1:foo,S:2:bar,S:3:snafu"; } } return null; } @Override public int getInt(IntConfigs config) { return 0; } }; instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig)); Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState)); newConfig = new InstanceConfig() { @Override public String getString(StringConfigs config) { switch ( config ) { case SERVERS_SPEC: { return "O:1:foo,S:2:bar"; } } return null; } @Override public int getInt(IntConfigs config) { return 0; } }; instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig)); Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState)); newConfig = new InstanceConfig() { @Override public String getString(StringConfigs config) { switch ( config ) { case SERVERS_SPEC: { return "S:1:foo,O:2:bar"; } } return null; } @Override public int getInt(IntConfigs config) { return 0; } }; instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig)); Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState)); }