NodeAdminImpl implements NodeAdmin { @Override public boolean setFrozen(boolean wantFrozen) { if (wantFrozen != previousWantFrozen) { if (wantFrozen) { this.startOfFreezeConvergence = clock.instant(); } else { this.startOfFreezeConvergence = null; } previousWantFrozen = wantFrozen; } boolean allNodeAgentsConverged = nodeAgentWithSchedulerByHostname.values().parallelStream() .filter(nodeAgentScheduler -> !nodeAgentScheduler.setFrozen(wantFrozen, freezeTimeout)) .count() == 0; if (wantFrozen) { if (allNodeAgentsConverged) isFrozen = true; } else isFrozen = false; return allNodeAgentsConverged; } NodeAdminImpl(NodeAgentFactory nodeAgentFactory, Metrics metrics, Clock clock);  NodeAdminImpl(NodeAgentFactory nodeAgentFactory, Metrics metrics,
                         Clock clock, Duration freezeTimeout, Duration spread);   NodeAdminImpl(NodeAgentWithSchedulerFactory nodeAgentWithSchedulerFactory,
                  Metrics metrics, Clock clock, Duration freezeTimeout, Duration spread); @Override void refreshContainersToRun(Set<NodeAgentContext> nodeAgentContexts); @Override void updateMetrics(boolean isSuspended); @Override boolean setFrozen(boolean wantFrozen); @Override boolean isFrozen(); @Override Duration subsystemFreezeDuration(); @Override void stopNodeAgentServices(List<String> hostnames); @Override void start(); @Override void stop();  }
@Test public void testSetFrozen() { Set<NodeAgentContext> contexts = new HashSet<>(); List<NodeAgentWithScheduler> nodeAgents = new ArrayList<>(); for (int i = 0; i < 3; i++) { NodeAgentContext context = createNodeAgentContext("host" + i + ".test.yahoo.com"); NodeAgentWithScheduler nodeAgent = mockNodeAgentWithSchedulerFactory(context); contexts.add(context); nodeAgents.add(nodeAgent); } nodeAdmin.refreshContainersToRun(contexts); assertTrue(nodeAdmin.isFrozen()); mockNodeAgentSetFrozenResponse(nodeAgents, true, true, true); assertTrue(nodeAdmin.setFrozen(false)); mockNodeAgentSetFrozenResponse(nodeAgents, false, false, false); assertFalse(nodeAdmin.setFrozen(true)); mockNodeAgentSetFrozenResponse(nodeAgents, false, true, true); assertFalse(nodeAdmin.setFrozen(true)); assertFalse(nodeAdmin.isFrozen()); mockNodeAgentSetFrozenResponse(nodeAgents, true, true, true); assertTrue(nodeAdmin.setFrozen(true)); assertTrue(nodeAdmin.isFrozen()); mockNodeAgentSetFrozenResponse(nodeAgents, true, true, true); assertTrue(nodeAdmin.setFrozen(true)); assertTrue(nodeAdmin.isFrozen()); mockNodeAgentSetFrozenResponse(nodeAgents, false, false, false); assertFalse(nodeAdmin.setFrozen(false)); assertFalse(nodeAdmin.isFrozen()); mockNodeAgentSetFrozenResponse(nodeAgents, false, false, true); assertFalse(nodeAdmin.setFrozen(false)); assertFalse(nodeAdmin.isFrozen()); mockNodeAgentSetFrozenResponse(nodeAgents, true, true, true); assertTrue(nodeAdmin.setFrozen(false)); assertFalse(nodeAdmin.isFrozen()); }