@Test(expected = ConfigException.class) public void testConfigInvalidFormat() { TimestampConverter<SourceRecord> xform = new TimestampConverter.Value<>(); Map<String, String> config = new HashMap<>(); config.put(TimestampConverter.TARGET_TYPE_CONFIG, "string"); config.put(TimestampConverter.FORMAT_CONFIG, "bad-format"); xform.configure(config); }
@Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); }
TimestampConverter implements Transformation<R> { @Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); } }
TimestampConverter implements Transformation<R> { @Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); }  }
TimestampConverter implements Transformation<R> { @Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); }  @Override void configure(Map<String, ?> configs); @Override R apply(R record); @Override ConfigDef config(); @Override void close(); }
TimestampConverter implements Transformation<R> { @Override public void configure(Map<String, ?> configs) { final SimpleConfig simpleConfig = new SimpleConfig(CONFIG_DEF, configs); final String field = simpleConfig.getString(FIELD_CONFIG); final String type = simpleConfig.getString(TARGET_TYPE_CONFIG); String formatPattern = simpleConfig.getString(FORMAT_CONFIG); schemaUpdateCache = new SynchronizedCache<>(new LRUCache<Schema, Schema>(16)); if (!VALID_TYPES.contains(type)) { throw new ConfigException("Unknown timestamp type in TimestampConverter: " + type + ". Valid values are " + Utils.join(VALID_TYPES, ", ") + "."); } if (type.equals(TYPE_STRING) && formatPattern.trim().isEmpty()) { throw new ConfigException("TimestampConverter requires format option to be specified when using string timestamps"); } SimpleDateFormat format = null; if (formatPattern != null && !formatPattern.trim().isEmpty()) { try { format = new SimpleDateFormat(formatPattern); format.setTimeZone(UTC); } catch (IllegalArgumentException e) { throw new ConfigException("TimestampConverter requires a SimpleDateFormat-compatible pattern for string timestamps: " + formatPattern, e); } } config = new Config(field, type, format); }  @Override void configure(Map<String, ?> configs); @Override R apply(R record); @Override ConfigDef config(); @Override void close(); static final String OVERVIEW_DOC; static final String FIELD_CONFIG; static final String TARGET_TYPE_CONFIG; static final String FORMAT_CONFIG; static final ConfigDef CONFIG_DEF; }