### Question:
DbNodeServiceImpl extends AbstractBaseService<DbNodeEntity> implements CacheUpdateService, DbNodeService, TimerService, PortalTimerService { @Override public DataSource getDataSource(long id, boolean isMaster) { Map<String, DataSource> cache = cacheDataMap.get(); Map<Long, DbNodeEntity> data = cacheNodeMap.get(); if (!isPortal) { isMaster = true; } if (!isMaster && data.containsKey(id) && !hasSlave(data.get(id))) { isMaster = true; } if (!isMaster && "0".equals(soaConfig.getDbMasterSlave())) { isMaster = true; } Transaction transaction = null; if (data.containsKey(id)) { if ("1".equals(soaConfig.getDbIpCat())) { transaction = Tracer.newTransaction("Db", isMaster ? data.get(id).getIp() : data.get(id).getIpBak()); transaction.setStatus(Transaction.SUCCESS); transaction.complete(); } String key = getConKey(data.get(id), isMaster); if (cache.containsKey(key)) { return cache.get(key); } else { key = getConKey(data.get(id), true); if (cache.containsKey(key)) { return cache.get(key); } } } log.error("dbNode_is_" + id + "_and_datasource_is_null_and_datasources_is_" + JsonUtil.toJson(cache.keySet())); return null; }  @Override void start(); @Override void updateCache(); @Override void checkDataSource(DbNodeEntity dbNodeEntity); @Override boolean hasSlave(DbNodeEntity dbNodeEntity); @Override void createDataSource(DbNodeEntity t1); void initDataSource(DbNodeEntity t1, String key, Map<String, DataSource> dataMap, boolean isMaster,
							   Transaction transaction); @Override Map<Long, DbNodeEntity> getCache(); @Override Map<String, List<DbNodeEntity>> getCacheByIp(); @Override void forceUpdateCache(); @PreDestroy @Override void stop(); @Override DataSource getDataSource(long id, boolean isMaster); @Override String info(); @Override Map<String, DataSource> getDataSource(); @Override void startPortal(); @Override void stopPortal(); @Override String getCacheJson();  }### Answer:
@Test public void getDataSourceTest() { setProperty("mq.db.ip.cat", "1"); Map<Long, DbNodeEntity> data = new HashMap<Long, DbNodeEntity>(); DbNodeEntity dbNodeEntity = new DbNodeEntity(); dbNodeEntity.setIp("fasaf"); dbNodeEntity.setDbUserName("faf"); dbNodeEntity.setDbPass("aff"); dbNodeEntity.setPort(2342); dbNodeEntity.setIpBak("faf"); dbNodeEntity.setDbUserNameBak("fa"); dbNodeEntity.setDbPassBak("faf"); dbNodeEntity.setPortBak(3); dbNodeEntity.setId(1); data.put(1L, dbNodeEntity); Map<String, DataSource> datasourceMap = new HashMap<String, DataSource>(); datasourceMap.put(dbNodeServiceImpl.getConKey(dbNodeEntity, true), new DruidDataSource()); datasourceMap.put(dbNodeServiceImpl.getConKey(dbNodeEntity, false), new DruidDataSource()); dbNodeServiceImpl.cacheDataMap.set(datasourceMap); dbNodeServiceImpl.cacheNodeMap.set(data); assertEquals(true, dbNodeServiceImpl.getDataSource(1, true) != null); assertEquals(true, dbNodeServiceImpl.getDataSource(1, false) != null); }