// Check that for the same prefix (number1, string1) we obtain the same partition
int partitionId = -N_PARTITIONS;
for(int i = 0; i < MAX_ITERATIONS_OVER_ONE_SCHEMA; i++) {
tuple.set("string2", TestUtils.randomString(10));
int thisPartitionId = partitioner.getPartition(new DatumWrapper(tuple), NullWritable.get(), N_PARTITIONS);
Assert.assertTrue(thisPartitionId >= 0);
Assert.assertTrue(thisPartitionId < N_PARTITIONS);
if(partitionId == -N_PARTITIONS) {
partitionId = thisPartitionId;
} else {
// Check that the returned partition is always the same even if "string2" field changes its value
Assert.assertEquals(thisPartitionId, partitionId);
}
}
// On the other hand, check that when we vary one of the group by fields, partition varies
int partitionMatches[] = new int[N_PARTITIONS];
for(int i = 0; i < MAX_ITERATIONS_OVER_ONE_SCHEMA; i++) {
tuple.set("string1", TestUtils.randomString(10));
int thisPartitionId = partitioner.getPartition(new DatumWrapper(tuple), NullWritable.get(), N_PARTITIONS);
Assert.assertTrue(thisPartitionId >= 0);
Assert.assertTrue(thisPartitionId < N_PARTITIONS);
partitionMatches[thisPartitionId]++;;
}