AbstractConditionStrategy extends AbstractShardingStrategy { @Override public void initialize(Map<String, String> settings) { super.initialize(settings); if(settings.containsKey(COLUMNS)) { dbShardColumns = parseNames(settings.get(COLUMNS)); setShardByDb(true); } if(settings.containsKey(TABLE_COLUMNS)) { tableShardColumns = parseNames(settings.get(TABLE_COLUMNS)); setShardByTable(true); } if(isShardByDb() == false && isShardByTable() == false) { throw new IllegalArgumentException("Property " + COLUMNS + " or " + TABLE_COLUMNS + " is required for the strategy"); } }  abstract Set<String> locateDbShardsByValue(ShardingContext ctx, Object shardValue); abstract Set<String> locateDbShards(ConditionContext ctx); abstract Set<String> locateTableShardsByValue(TableShardingContext ctx, Object tableShardValue); abstract Set<String> locateTableShards(TableConditionContext ctx); @Override void initialize(Map<String, String> settings); @Override Set<String> locateDbShards(ShardingContext ctx); @Override Set<String> locateTableShards(TableShardingContext ctx); static final String COLUMNS; static final String TABLE_COLUMNS; }
@Test public void testWrongDbTableConfig() throws Exception { Map<String, String> settings = new HashMap<>(); try { test.initialize(settings); fail(); } catch (Exception e) { assertEquals(e.getClass(), IllegalArgumentException.class); } }