### Question:
ShardingConfig { public List<Schema> getSchemas() { return schemas; }  static ShardingConfig load(String path); static void initShardingCfg(); List<Schema> getSchemas(); void setSchemas(List<Schema> schemas); boolean isHasInvalidSchema(); void setHasInvalidSchema(boolean hasInvalidSchema); static String longestCommonPrefix(Collection<String> strs); static final String SHARDING_ID_DELIMITER; static volatile Map<String, Set<me.ele.jarch.athena.util.deploy.dalgroupcfg.ShardingTable>> shardingTableMap; }### Answer:
@Test public void mappingKey() { for (int i = 0; i < 1; i++) { assertTrue(cfg.getSchemas().get(i).getMapping_key() == null); } assertTrue(cfg.getSchemas().get(1).getMapping_key() != null); ShardingConfig.MappingKey mappingKey = cfg.getSchemas().get(1).getMapping_key(); List<ShardingConfig.MappingRule> mappingRuleList = mappingKey.getMappingRuleValues(); assertEquals(mappingRuleList.size(), 1); Iterator<ShardingConfig.MappingRule> iterator = mappingRuleList.iterator(); ShardingConfig.MappingRule entry = iterator.next(); assertEquals(entry.getSepColumnName(), "platform_tracking_id"); assertEquals(entry.getTablePrefix(), "tb_shipping_order_tracking_id_mapping_dal_"); assertEquals(mappingKey.getColumn(), "retailer_id"); }
@Test public void testNewOrderShardingRules() { final String group = "new_eos_main_group"; final ShardingConfig.Schema schema = cfg.getSchemas().get(3); assertTrue(Objects.nonNull(schema.getComposed_key())); assertEquals(schema.getMapping_key(), null); ShardingRouter shardingRouter = ShardingRouter.getShardingRouter(group); final String table = "eleme_order"; LinkedHashMap<String, ShardingConfig.MappingKey> ruleNameWithMappingKey = shardingRouter.getMappingKey(table); Set<String> ruleNames = new LinkedHashSet<>(); ruleNames.add("user_id"); ruleNames.add("restaurant_id"); assertEquals(ruleNameWithMappingKey.keySet(), ruleNames); assertTrue(shardingRouter.isShardingTable("dal_mapping_order_id_user_id_")); assertTrue(shardingRouter.isShardingTable("dal_mapping_order_id_restaurant_id_")); String value4OrderId = "123"; String name4OrderId = "order_id"; ShardingTable uIdDimMappingTable = shardingRouter .getMappingTableByMappingKey(table, ruleNameWithMappingKey.get("user_id"), name4OrderId, value4OrderId); assertEquals(uIdDimMappingTable.database, "new_eos_eleme-zeus_eos_group2"); assertEquals(uIdDimMappingTable.table, "dal_mapping_order_id_user_id_4"); ShardingTable rIdDimMappingTable = shardingRouter .getMappingTableByMappingKey(table, ruleNameWithMappingKey.get("restaurant_id"), name4OrderId, value4OrderId); assertEquals(rIdDimMappingTable.database, "new_eos_eleme-zeus_eos_group4"); assertEquals(rIdDimMappingTable.table, "dal_mapping_order_id_restaurant_id_4"); }
@Test public void hashRange() { assertEquals(cfg.getSchemas().get(5).getRules().get(0).getHash_range(), 1024); }