@Override public Host addHost(PartitionServerAddress address, List<String> flags) throws IOException { MockHost host = new MockHost(address); hosts.add(host); return host; }
@Override public void removeDomain(Domain domain) throws IOException { removedDomains.add(domain); HostDomain hostDomain = getHostDomain(domain); if (hostDomain != null) { hostDomains.remove(hostDomain); } }
@Override public HostCommand nextCommand() throws IOException { if (commandQueue.size() > 0) { setCurrentCommand(commandQueue.remove(0)); notifyCommandQueueChangeListeners(); } else { setCurrentCommand(null); } return currentCommand; }
@Test public void testGetHostsInState() throws Exception { final MockHost h1 = new MockHost(new PartitionServerAddress("localhost", 1)); final MockHost h2 = new MockHost(new PartitionServerAddress("localhost", 2)); final MockHost h3 = new MockHost(new PartitionServerAddress("localhost", 3)); SlightlyLessAbstractRing rc = new SlightlyLessAbstractRing(1, null) { @Override public Set<Host> getHosts() { return new HashSet<Host>(Arrays.asList(h1, h2, h3)); } }; h1.setState(HostState.IDLE); h2.setState(HostState.SERVING); h3.setState(HostState.OFFLINE); assertEquals(Collections.singleton(h1), Rings.getHostsInState(rc, HostState.IDLE)); assertEquals(Collections.singleton(h2), Rings.getHostsInState(rc, HostState.SERVING)); assertEquals(Collections.singleton(h3), Rings.getHostsInState(rc, HostState.OFFLINE)); } }
@Override public void clearCommandQueue() throws IOException { commandQueue.clear(); notifyCommandQueueChangeListeners(); }
@Override public void setState(HostState state) throws IOException { this.state = state; notifyHostStateChangeListeners(); }
public void setCurrentCommand(HostCommand command) { currentCommand = command; notifyCurrentCommandChangeListeners(); }
@Override public void enqueueCommand(HostCommand command) throws IOException { commandQueue.add(command); lastEnqueuedCommand = command; notifyCommandQueueChangeListeners(); }
@Test public void testCommandAll() throws IOException { final Host hc = new MockHost(LOCALHOST); SlightlyLessAbstractRing rc = new SlightlyLessAbstractRing(1, null) { @Override public Set<Host> getHosts() { return Collections.singleton(hc); } }; assertNull(hc.getCurrentCommand()); assertTrue(hc.getCommandQueue().isEmpty()); Rings.commandAll(rc, HostCommand.SERVE_DATA); assertNull(hc.getCurrentCommand()); assertEquals(Arrays.asList(HostCommand.SERVE_DATA), hc.getCommandQueue()); }