### Question:
ShardIdPartitioner extends Partitioner<BulkIngestKey,Value> implements Configurable, DelegatePartitioner { @Override public synchronized int getPartition(BulkIngestKey key, Value value, int numReduceTasks) { String shardId = key.getKey().getRow().toString(); try { long shardIndex = generateNumberForShardId(shardId, getBaseTime()); return (int) (shardIndex % numReduceTasks); } catch (Exception e) { return (shardId.hashCode() & Integer.MAX_VALUE) % numReduceTasks; } }  @Override synchronized int getPartition(BulkIngestKey key, Value value, int numReduceTasks); @Override Configuration getConf(); @Override void setConf(Configuration conf); @Override void configureWithPrefix(String prefix); @Override int getNumPartitions(); @Override void initializeJob(Job job);  }### Answer:
@Test public void testShardIdScheme() throws ParseException { Map<String,Path> shardedTableMapFiles = new HashMap<>(); shardedTableMapFiles.put("shard", new Path("/path/that/is/fake/to/make/the/test/pass")); int shardCount = 0; int[] partitions = new int[58]; SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); Date date = format.parse("20100101"); Calendar c = Calendar.getInstance(); c.setTime(date); for (int dateCnt = 0; dateCnt < 348; dateCnt++) { for (int shard = 0; shard < 31; shard++) { shardCount++; StringBuilder shardId = new StringBuilder(); shardId.append(format.format(c.getTime())); shardId.append('_').append(shard); Key key = new Key(shardId.toString()); Value value = new Value(); int partition = partitioner.getPartition(new BulkIngestKey(new Text("shard"), key), value, 58); partitions[partition]++; } c.add(Calendar.DATE, 1); } int expected = shardCount / 58; boolean errored = false; for (int i = 0; i < 58; i++) { try { Assert.assertEquals("Unexpected distribution for partition " + i + ": ", expected, partitions[i]); } catch (Throwable e) { System.err.println(e.getMessage()); errored = true; } } if (errored) { Assert.fail("Failed to get expected distribution. See console for unexpected entries"); } }