HintsStrategy extends AbstractShardingStrategy { @Override public Set<String> locateTableShards(TableShardingContext ctx) { return toSet(ctx.getHints().getTableShard()); }  @Override void initialize(Map<String, String> settings); @Override Set<String> locateDbShards(ShardingContext ctx); @Override Set<String> locateTableShards(TableShardingContext ctx); static final String SHARD_BY_DB; static final String SHARD_BY_TABLE; }
@Test public void testLocateTableShards() { HintsStrategy test = new HintsStrategy(); Map<String, String> settings = new HashMap<>(); settings.put(HintsStrategy.SHARD_BY_TABLE, "true"); Set<String> shardedTables = new HashSet<>(); shardedTables.add("t1"); shardedTables.add("t2"); shardedTables.add("T1"); shardedTables.add("T2"); test.initialize(settings); assertTrue(test.isShardByTable()); assertEquals(0, test.locateTableShards(new TableShardingContext("appId", "logicDbName", "t1", set("1", "2", "3"), new Hints(), ConditionList.andList())).size()); assertEquals(set("1"), test.locateTableShards(new TableShardingContext("appId", "logicDbName", "t1", set("1", "2", "3"), new Hints().inTableShard(1), ConditionList.andList()))); assertEquals(set("1"), test.locateTableShards(new TableShardingContext("appId", "logicDbName", "t1", set("1", "2", "3"), new Hints().inTableShard("1"), ConditionList.andList()))); }