public class BootStrapperTest
{
@Test
public void testGuessToken() throws IOException
{
StorageService ss = StorageService.instance;
generateFakeEndpoints(3);
InetAddress one = InetAddress.getByName("127.0.0.2");
InetAddress two = InetAddress.getByName("127.0.0.3");
InetAddress three = InetAddress.getByName("127.0.0.4");
Map<InetAddress, Double> load = new HashMap<InetAddress, Double>();
load.put(one, 1.0);
load.put(two, 2.0);
load.put(three, 3.0);
TokenMetadata tmd = ss.getTokenMetadata();
InetAddress source = BootStrapper.getBootstrapSource(tmd, load);
assert three.equals(source);
InetAddress myEndpoint = InetAddress.getByName("127.0.0.1");
Range range3 = ss.getPrimaryRangeForEndPoint(three);
Token fakeToken = ((IPartitioner)StorageService.getPartitioner()).midpoint(range3.left, range3.right);
assert range3.contains(fakeToken);
ss.onChange(myEndpoint, StorageService.MOVE_STATE, new ApplicationState(StorageService.STATE_BOOTSTRAPPING + StorageService.Delimiter + ss.getPartitioner().getTokenFactory().toString(fakeToken)));
tmd = ss.getTokenMetadata();
InetAddress source2 = BootStrapper.getBootstrapSource(tmd, load);
assert two.equals(source2) : source2;
}