@Test public void test_getShardingItemParameters_withInvalidNonnumericKey() { JobConfiguration jobConfiguration = mock(JobConfiguration.class); when(jobConfiguration.getShardingItemParameters()).thenReturn("0=1,1=2,1={aa},2=a,a="); JobScheduler jobScheduler = mock(JobScheduler.class); when(jobScheduler.getCurrentConf()).thenReturn(jobConfiguration); ConfigurationService configurationService = new ConfigurationService(jobScheduler); Map parameters = configurationService.getShardingItemParameters(); assertNull(parameters.get("a")); }
public Map<Integer, String> getShardingItemParameters() { Map<Integer, String> result = new HashMap<>(); String value = jobConfiguration.getShardingItemParameters(); if (Strings.isNullOrEmpty(value)) { return result; } String[] shardingItemParameters = value.split(PATTERN); Map<String, String> result0 = new HashMap<>(shardingItemParameters.length); for (String each : shardingItemParameters) { String item = ""; String exec = ""; int index = each.indexOf('='); if (index > -1) { item = each.substring(0, index).trim(); exec = each.substring(index + 1, each.length()).trim(); if (exec.startsWith(DOUBLE_QUOTE)) { exec = exec.substring(1); } if (exec.endsWith(DOUBLE_QUOTE)) { exec = exec.substring(0, exec.length() - 1); } } else { throw new ShardingItemParametersException("Sharding item parameters '%s' format error", value); } result0.put(item, exec); } if (isLocalMode()) { if (result0.containsKey("*")) { result.put(-1, result0.get("*")); } else { throw new ShardingItemParametersException( "Sharding item parameters '%s' format error with local mode job, should be *=xx", value); } } else { Iterator<Map.Entry<String, String>> iterator = result0.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, String> next = iterator.next(); String item = next.getKey(); String exec = next.getValue(); try { result.put(Integer.valueOf(item), exec); } catch (final NumberFormatException ex) { LogUtils.warn(LOGGER, LogEvents.ExecutorEvent.COMMON, "Sharding item key '%s' is invalid, it should be an integer, key '%s' will be dropped", item, item, ex); } } } return result; }
ConfigurationService extends AbstractSaturnService { public Map<Integer, String> getShardingItemParameters() { Map<Integer, String> result = new HashMap<>(); String value = jobConfiguration.getShardingItemParameters(); if (Strings.isNullOrEmpty(value)) { return result; } String[] shardingItemParameters = value.split(PATTERN); Map<String, String> result0 = new HashMap<>(shardingItemParameters.length); for (String each : shardingItemParameters) { String item = ""; String exec = ""; int index = each.indexOf('='); if (index > -1) { item = each.substring(0, index).trim(); exec = each.substring(index + 1, each.length()).trim(); if (exec.startsWith(DOUBLE_QUOTE)) { exec = exec.substring(1); } if (exec.endsWith(DOUBLE_QUOTE)) { exec = exec.substring(0, exec.length() - 1); } } else { throw new ShardingItemParametersException("Sharding item parameters '%s' format error", value); } result0.put(item, exec); } if (isLocalMode()) { if (result0.containsKey("*")) { result.put(-1, result0.get("*")); } else { throw new ShardingItemParametersException( "Sharding item parameters '%s' format error with local mode job, should be *=xx", value); } } else { Iterator<Map.Entry<String, String>> iterator = result0.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, String> next = iterator.next(); String item = next.getKey(); String exec = next.getValue(); try { result.put(Integer.valueOf(item), exec); } catch (final NumberFormatException ex) { LogUtils.warn(LOGGER, LogEvents.ExecutorEvent.COMMON, "Sharding item key '%s' is invalid, it should be an integer, key '%s' will be dropped", item, item, ex); } } } return result; } }
ConfigurationService extends AbstractSaturnService { public Map<Integer, String> getShardingItemParameters() { Map<Integer, String> result = new HashMap<>(); String value = jobConfiguration.getShardingItemParameters(); if (Strings.isNullOrEmpty(value)) { return result; } String[] shardingItemParameters = value.split(PATTERN); Map<String, String> result0 = new HashMap<>(shardingItemParameters.length); for (String each : shardingItemParameters) { String item = ""; String exec = ""; int index = each.indexOf('='); if (index > -1) { item = each.substring(0, index).trim(); exec = each.substring(index + 1, each.length()).trim(); if (exec.startsWith(DOUBLE_QUOTE)) { exec = exec.substring(1); } if (exec.endsWith(DOUBLE_QUOTE)) { exec = exec.substring(0, exec.length() - 1); } } else { throw new ShardingItemParametersException("Sharding item parameters '%s' format error", value); } result0.put(item, exec); } if (isLocalMode()) { if (result0.containsKey("*")) { result.put(-1, result0.get("*")); } else { throw new ShardingItemParametersException( "Sharding item parameters '%s' format error with local mode job, should be *=xx", value); } } else { Iterator<Map.Entry<String, String>> iterator = result0.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, String> next = iterator.next(); String item = next.getKey(); String exec = next.getValue(); try { result.put(Integer.valueOf(item), exec); } catch (final NumberFormatException ex) { LogUtils.warn(LOGGER, LogEvents.ExecutorEvent.COMMON, "Sharding item key '%s' is invalid, it should be an integer, key '%s' will be dropped", item, item, ex); } } } return result; } ConfigurationService(JobScheduler jobScheduler); }
ConfigurationService extends AbstractSaturnService { public Map<Integer, String> getShardingItemParameters() { Map<Integer, String> result = new HashMap<>(); String value = jobConfiguration.getShardingItemParameters(); if (Strings.isNullOrEmpty(value)) { return result; } String[] shardingItemParameters = value.split(PATTERN); Map<String, String> result0 = new HashMap<>(shardingItemParameters.length); for (String each : shardingItemParameters) { String item = ""; String exec = ""; int index = each.indexOf('='); if (index > -1) { item = each.substring(0, index).trim(); exec = each.substring(index + 1, each.length()).trim(); if (exec.startsWith(DOUBLE_QUOTE)) { exec = exec.substring(1); } if (exec.endsWith(DOUBLE_QUOTE)) { exec = exec.substring(0, exec.length() - 1); } } else { throw new ShardingItemParametersException("Sharding item parameters '%s' format error", value); } result0.put(item, exec); } if (isLocalMode()) { if (result0.containsKey("*")) { result.put(-1, result0.get("*")); } else { throw new ShardingItemParametersException( "Sharding item parameters '%s' format error with local mode job, should be *=xx", value); } } else { Iterator<Map.Entry<String, String>> iterator = result0.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, String> next = iterator.next(); String item = next.getKey(); String exec = next.getValue(); try { result.put(Integer.valueOf(item), exec); } catch (final NumberFormatException ex) { LogUtils.warn(LOGGER, LogEvents.ExecutorEvent.COMMON, "Sharding item key '%s' is invalid, it should be an integer, key '%s' will be dropped", item, item, ex); } } } return result; } ConfigurationService(JobScheduler jobScheduler); @Override void start(); @Override void shutdown(); void notifyJobEnabledOrNot(); void notifyJobEnabledIfNecessary(); void notifyJobDisabled(); int getShardingTotalCount(); boolean isLocalMode(); Map<Integer, String> getShardingItemParameters(); String getJobParameter(); String getTimeZoneStr(); TimeZone getTimeZone(); String getCron(); int getProcessCountIntervalSeconds(); boolean isInPausePeriod(); boolean isInPausePeriod(Date date); boolean isFailover(); boolean isJobEnabled(); boolean isEnabledReport(); int getTimeoutSeconds(); boolean showNormalLog(); Map<String, String> getCustomContext(); JobType getJobType(); String getQueueName(); String getChannelName(); List<String> getPreferList(); boolean isUseDispreferList(); List<String> getDownStream(); }
ConfigurationService extends AbstractSaturnService { public Map<Integer, String> getShardingItemParameters() { Map<Integer, String> result = new HashMap<>(); String value = jobConfiguration.getShardingItemParameters(); if (Strings.isNullOrEmpty(value)) { return result; } String[] shardingItemParameters = value.split(PATTERN); Map<String, String> result0 = new HashMap<>(shardingItemParameters.length); for (String each : shardingItemParameters) { String item = ""; String exec = ""; int index = each.indexOf('='); if (index > -1) { item = each.substring(0, index).trim(); exec = each.substring(index + 1, each.length()).trim(); if (exec.startsWith(DOUBLE_QUOTE)) { exec = exec.substring(1); } if (exec.endsWith(DOUBLE_QUOTE)) { exec = exec.substring(0, exec.length() - 1); } } else { throw new ShardingItemParametersException("Sharding item parameters '%s' format error", value); } result0.put(item, exec); } if (isLocalMode()) { if (result0.containsKey("*")) { result.put(-1, result0.get("*")); } else { throw new ShardingItemParametersException( "Sharding item parameters '%s' format error with local mode job, should be *=xx", value); } } else { Iterator<Map.Entry<String, String>> iterator = result0.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, String> next = iterator.next(); String item = next.getKey(); String exec = next.getValue(); try { result.put(Integer.valueOf(item), exec); } catch (final NumberFormatException ex) { LogUtils.warn(LOGGER, LogEvents.ExecutorEvent.COMMON, "Sharding item key '%s' is invalid, it should be an integer, key '%s' will be dropped", item, item, ex); } } } return result; } ConfigurationService(JobScheduler jobScheduler); @Override void start(); @Override void shutdown(); void notifyJobEnabledOrNot(); void notifyJobEnabledIfNecessary(); void notifyJobDisabled(); int getShardingTotalCount(); boolean isLocalMode(); Map<Integer, String> getShardingItemParameters(); String getJobParameter(); String getTimeZoneStr(); TimeZone getTimeZone(); String getCron(); int getProcessCountIntervalSeconds(); boolean isInPausePeriod(); boolean isInPausePeriod(Date date); boolean isFailover(); boolean isJobEnabled(); boolean isEnabledReport(); int getTimeoutSeconds(); boolean showNormalLog(); Map<String, String> getCustomContext(); JobType getJobType(); String getQueueName(); String getChannelName(); List<String> getPreferList(); boolean isUseDispreferList(); List<String> getDownStream();  }