public void testRangeShardMappingKeyLookup() throws Exception {
  final String globalGroupName="My global group";
  final int lowerBounds[]=new int[]{1,10000,1001,400,1000,470};
  final int lowestLowerBound=1;
  Set<ShardIndex> shardIndices=new HashSet<ShardIndex>();
  int shardId=0;
  for (  Integer lowerBound : lowerBounds) {
    ShardIndex i=new ShardIndex(String.valueOf(lowerBound),shardId,"shard_group_" + shardId);
    shardId++;
    shardIndices.add(i);
  }
  ShardMapping mapping=new RangeShardMapping(5000,ShardingType.RANGE,globalGroupName,null,shardIndices);
  try {
    mapping.getGroupNameForKey(String.valueOf(lowestLowerBound - 1));
    fail("Looking up a key with a value below the lowest bound is invalid");
  }
 catch (  Exception ex) {
  }
  try {
    mapping.getGroupNameForKey(String.valueOf(lowestLowerBound - 1000));
    fail("Looking up a key with a value below the lowest bound is invalid");
  }
 catch (  Exception ex) {
  }
  for (shardId=0; shardId < lowerBounds.length; ++shardId) {
    int lowerBound=lowerBounds[shardId];
    String groupName=mapping.getGroupNameForKey(String.valueOf(lowerBound));
    assertEquals("Exact lookup for key " + lowerBound,"shard_group_" + shardId,groupName);
  }
}

public void testRangeShardMappingKeyLookup ( ) throws Exception { final String globalGroupName = "My global group" ; final int lowerBounds [ ] = new int [ ] { 1 , 10000 , 1001 , 400 , 1000 , 470 } ; final int lowestLowerBound = 1 ; Set < ShardIndex > shardIndices = new HashSet < ShardIndex > ( ) ; int shardId = 0 ; for ( Integer lowerBound : lowerBounds ) { ShardIndex i = new ShardIndex ( String . valueOf ( lowerBound ) , shardId , "shard_group_" + shardId ) ; shardId ++ ; shardIndices . add ( i ) ; } ShardMapping mapping = new RangeShardMapping ( 5000 , ShardingType . RANGE , globalGroupName , null , shardIndices ) ; try { mapping . getGroupNameForKey ( String . valueOf ( lowestLowerBound - 1 ) ) ; fail ( "Looking up a key with a value below the lowest bound is invalid" ) ; } catch ( Exception ex ) { } try { mapping . getGroupNameForKey ( String . valueOf ( lowestLowerBound - 1000 ) ) ; fail ( "Looking up a key with a value below the lowest bound is invalid" ) ; } catch ( Exception ex ) { } for ( shardId = 0 ; shardId < lowerBounds . length ; ++ shardId ) { int lowerBound = lowerBounds [ shardId ] ; String groupName = mapping . getGroupNameForKey ( String . valueOf ( lowerBound ) ) ; assertEquals ( "Exact lookup for key " + lowerBound , "shard_group_" + shardId , groupName ) ; } }
test that a range based shard mapping looks up groups for keys correctly .
