HintsStrategy extends AbstractShardingStrategy { @Override public Set<String> locateDbShards(ShardingContext ctx) { return toSet(ctx.getHints().getShard()); }  @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 testLocateDbShards() { HintsStrategy test = new HintsStrategy(); Map<String, String> settings = new HashMap<>(); settings.put(HintsStrategy.SHARD_BY_DB, "true"); test.initialize(settings); assertTrue(test.isShardByDb()); assertTrue(test.locateDbShards(new ShardingContext("appId", "logicDbName", set("1", "2", "3"), new Hints(), ConditionList.andList())).size() == 0); assertEquals(set("1"), test.locateDbShards(new ShardingContext("appId", "logicDbName", set("1", "2", "3"), new Hints().inShard(1), ConditionList.andList()))); assertEquals(set("1"), test.locateDbShards(new ShardingContext("appId", "logicDbName", set("1", "2", "3"), new Hints().inShard("1"), ConditionList.andList()))); }