@Test public void randomServerFromMany() { Master master = EasyMock.createMock(Master.class); ZooReader reader = EasyMock.createMock(ZooReader.class); ServerContext context = EasyMock.createMock(ServerContext.class); EasyMock.expect(context.getConfiguration()).andReturn(config).anyTimes(); EasyMock.expect(context.getInstanceID()).andReturn("1234").anyTimes(); EasyMock.expect(context.getZooReaderWriter()).andReturn(null).anyTimes(); EasyMock.expect(master.getInstanceID()).andReturn("1234").anyTimes(); EasyMock.expect(master.getContext()).andReturn(context).anyTimes(); EasyMock.replay(master, context, reader); MasterReplicationCoordinator coordinator = new MasterReplicationCoordinator(master, reader); EasyMock.verify(master, reader); TreeSet<TServerInstance> instances = new TreeSet<>(); TServerInstance inst1 = new TServerInstance(HostAndPort.fromParts("host1", 1234), "session"); instances.add(inst1); TServerInstance inst2 = new TServerInstance(HostAndPort.fromParts("host2", 1234), "session"); instances.add(inst2); assertEquals(inst1, coordinator.getRandomTServer(instances, 0)); assertEquals(inst2, coordinator.getRandomTServer(instances, 1)); }
protected TServerInstance getRandomTServer(Set<TServerInstance> tservers, int offset) { checkArgument(tservers.size() > offset, "Must provide an offset less than the size of the set"); Iterator<TServerInstance> iter = tservers.iterator(); while (offset > 0) { iter.next(); offset--; } return iter.next(); }
MasterReplicationCoordinator implements ReplicationCoordinator.Iface { protected TServerInstance getRandomTServer(Set<TServerInstance> tservers, int offset) { checkArgument(tservers.size() > offset, "Must provide an offset less than the size of the set"); Iterator<TServerInstance> iter = tservers.iterator(); while (offset > 0) { iter.next(); offset--; } return iter.next(); } }
MasterReplicationCoordinator implements ReplicationCoordinator.Iface { protected TServerInstance getRandomTServer(Set<TServerInstance> tservers, int offset) { checkArgument(tservers.size() > offset, "Must provide an offset less than the size of the set"); Iterator<TServerInstance> iter = tservers.iterator(); while (offset > 0) { iter.next(); offset--; } return iter.next(); } MasterReplicationCoordinator(Master master); protected  MasterReplicationCoordinator(Master master, ZooReader reader); }
MasterReplicationCoordinator implements ReplicationCoordinator.Iface { protected TServerInstance getRandomTServer(Set<TServerInstance> tservers, int offset) { checkArgument(tservers.size() > offset, "Must provide an offset less than the size of the set"); Iterator<TServerInstance> iter = tservers.iterator(); while (offset > 0) { iter.next(); offset--; } return iter.next(); } MasterReplicationCoordinator(Master master); protected  MasterReplicationCoordinator(Master master, ZooReader reader); @Override String getServicerAddress(String remoteTableId, TCredentials creds); }
MasterReplicationCoordinator implements ReplicationCoordinator.Iface { protected TServerInstance getRandomTServer(Set<TServerInstance> tservers, int offset) { checkArgument(tservers.size() > offset, "Must provide an offset less than the size of the set"); Iterator<TServerInstance> iter = tservers.iterator(); while (offset > 0) { iter.next(); offset--; } return iter.next(); } MasterReplicationCoordinator(Master master); protected  MasterReplicationCoordinator(Master master, ZooReader reader); @Override String getServicerAddress(String remoteTableId, TCredentials creds);  }