@Override public boolean claimRingGroupConductor(RingGroupConductorMode mode) { ringGroupConductorMode = mode; notifyRingGroupConductorModeListeners(); return true; }
@Override public void setState(HostState state) throws IOException { this.state = state; notifyHostStateChangeListeners(); }
public void setCurrentCommand(HostCommand command) { currentCommand = command; notifyCurrentCommandChangeListeners(); }
@Override public HostDomain addDomain(Domain domain) throws IOException { HostDomain hostDomain = new MockHostDomain(domain); hostDomains.add(hostDomain); return hostDomain; }
@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 Host addHost(PartitionServerAddress address, List<String> flags) throws IOException { MockHost host = new MockHost(address); hosts.add(host); return host; }
@Override public HostCommand nextCommand() throws IOException { if (commandQueue.size() > 0) { setCurrentCommand(commandQueue.remove(0)); notifyCommandQueueChangeListeners(); } else { setCurrentCommand(null); } return currentCommand; }
public MockHostDomain(Domain domain, int... partitionNumberAndVersionPairs) { this.domain = domain; for (int i = 0; i < partitionNumberAndVersionPairs.length; i += 2) { partitions.add(new MockHostDomainPartition(partitionNumberAndVersionPairs[i], partitionNumberAndVersionPairs[i + 1])); } }
@Override public void enqueueCommand(HostCommand command) throws IOException { commandQueue.add(command); lastEnqueuedCommand = command; notifyCommandQueueChangeListeners(); }
@Override public boolean removeHost(PartitionServerAddress address) { return hosts.remove(getHostByAddress(address)); }
@Override public void removeDomain(Domain domain) throws IOException { removedDomains.add(domain); HostDomain hostDomain = getHostDomain(domain); if (hostDomain != null) { hostDomains.remove(hostDomain); } }
@Override public Ring addRing(int ringNum) throws IOException { MockRing newRing = new MockRing(Sets.newHashSet(), this, ringNum); ringConfigs.put(ringNum, newRing); return newRing; }
public MockHostDomain addMockDomain(Domain domain, int... partitionNumberAndVersionPairs) throws IOException { MockHostDomain hostDomain = new MockHostDomain(domain, partitionNumberAndVersionPairs); hostDomains.add(hostDomain); return hostDomain; }
@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()); }
@Override public void releaseRingGroupConductor() { ringGroupConductorMode = null; notifyRingGroupConductorModeListeners(); }
@Override public HostDomainPartition addPartition(int partitionNumber) { MockHostDomainPartition result = new MockHostDomainPartition(partitionNumber, null); partitions.add(result); return result; }
@Override public void clearCommandQueue() throws IOException { commandQueue.clear(); notifyCommandQueueChangeListeners(); }
@Test public void testGetHostsForDomainPartition() throws Exception { final Domain d0 = new MockDomain("d0"); final Host hc = new MockHost(LOCALHOST) { HostDomain hd1 = new MockHostDomain(d0, 1, 1, 2, 2); HostDomain hd2 = new MockHostDomain(null, 1, 2, 2, 2); @Override public Set<HostDomain> getAssignedDomains() throws IOException { return new HashSet<HostDomain>(Arrays.asList(hd1, hd2)); } @Override public HostDomain getHostDomain(Domain domain) { return hd1; } }; SlightlyLessAbstractRing ring = new SlightlyLessAbstractRing(1, null) { @Override public Set<Host> getHosts() { return Collections.singleton(hc); } }; assertEquals(Collections.singleton(hc), Rings.getHostsForDomainPartition(ring, d0, 1)); assertEquals(Collections.singleton(hc), Rings.getHostsForDomainPartition(ring, d0, 2)); assertEquals(Collections.EMPTY_SET, Rings.getHostsForDomainPartition(ring, d0, 3)); }
@Override public void setRingGroupConductorMode(RingGroupConductorMode mode) throws IOException { ringGroupConductorMode = mode; notifyRingGroupConductorModeListeners(); }