ConsumerConfig extends AbstractConfig { public static Map<String, Object> addDeserializerToConfig(Map<String, Object> configs, Deserializer<?> keyDeserializer, Deserializer<?> valueDeserializer) { Map<String, Object> newConfigs = new HashMap<String, Object>(); newConfigs.putAll(configs); if (keyDeserializer != null) newConfigs.put(KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializer.getClass()); if (valueDeserializer != null) newConfigs.put(VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializer.getClass()); return newConfigs; } ConsumerConfig(Map<?, ?> props); static Map<String, Object> addDeserializerToConfig(Map<String, Object> configs,
                                                              Deserializer<?> keyDeserializer,
                                                              Deserializer<?> valueDeserializer); static Properties addDeserializerToConfig(Properties properties,
                                                     Deserializer<?> keyDeserializer,
                                                     Deserializer<?> valueDeserializer); static void main(String[] args); static final String GROUP_ID_CONFIG; static final String MAX_POLL_RECORDS_CONFIG; static final String SESSION_TIMEOUT_MS_CONFIG; static final String HEARTBEAT_INTERVAL_MS_CONFIG; static final String BOOTSTRAP_SERVERS_CONFIG; static final String ENABLE_AUTO_COMMIT_CONFIG; static final String AUTO_COMMIT_INTERVAL_MS_CONFIG; static final String PARTITION_ASSIGNMENT_STRATEGY_CONFIG; static final String AUTO_OFFSET_RESET_CONFIG; static final String AUTO_OFFSET_RESET_DOC; static final String FETCH_MIN_BYTES_CONFIG; static final String FETCH_MAX_WAIT_MS_CONFIG; static final String METADATA_MAX_AGE_CONFIG; static final String MAX_PARTITION_FETCH_BYTES_CONFIG; static final int DEFAULT_MAX_PARTITION_FETCH_BYTES; static final String SEND_BUFFER_CONFIG; static final String RECEIVE_BUFFER_CONFIG; static final String CLIENT_ID_CONFIG; static final String RECONNECT_BACKOFF_MS_CONFIG; static final String RETRY_BACKOFF_MS_CONFIG; static final String METRICS_SAMPLE_WINDOW_MS_CONFIG; static final String METRICS_NUM_SAMPLES_CONFIG; static final String METRIC_REPORTER_CLASSES_CONFIG; static final String CHECK_CRCS_CONFIG; static final String KEY_DESERIALIZER_CLASS_CONFIG; static final String KEY_DESERIALIZER_CLASS_DOC; static final String VALUE_DESERIALIZER_CLASS_CONFIG; static final String VALUE_DESERIALIZER_CLASS_DOC; static final String CONNECTIONS_MAX_IDLE_MS_CONFIG; static final String REQUEST_TIMEOUT_MS_CONFIG; static final String INTERCEPTOR_CLASSES_CONFIG; static final String INTERCEPTOR_CLASSES_DOC; static final String EXCLUDE_INTERNAL_TOPICS_CONFIG; static final boolean DEFAULT_EXCLUDE_INTERNAL_TOPICS; }
@Test public void testDeserializerToPropertyConfig() { Properties properties = new Properties(); properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializerClassName); properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializerClassName); Properties newProperties = ConsumerConfig.addDeserializerToConfig(properties, null, null); assertEquals(newProperties.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG), keyDeserializerClassName); assertEquals(newProperties.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG), valueDeserializerClassName); properties.clear(); properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializerClassName); newProperties = ConsumerConfig.addDeserializerToConfig(properties, keyDeserializer, null); assertEquals(newProperties.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG), keyDeserializerClassName); assertEquals(newProperties.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG), valueDeserializerClassName); properties.clear(); properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializerClassName); newProperties = ConsumerConfig.addDeserializerToConfig(properties, null, valueDeserializer); assertEquals(newProperties.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG), keyDeserializerClassName); assertEquals(newProperties.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG), valueDeserializerClassName); properties.clear(); newProperties = ConsumerConfig.addDeserializerToConfig(properties, keyDeserializer, valueDeserializer); assertEquals(newProperties.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG), keyDeserializerClassName); assertEquals(newProperties.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG), valueDeserializerClassName); }
@Test public void testDeserializerToMapConfig() { Map<String, Object> configs = new HashMap<>(); configs.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializerClass); configs.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializerClass); Map<String, Object> newConfigs = ConsumerConfig.addDeserializerToConfig(configs, null, null); assertEquals(newConfigs.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG), keyDeserializerClass); assertEquals(newConfigs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG), valueDeserializerClass); configs.clear(); configs.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializerClass); newConfigs = ConsumerConfig.addDeserializerToConfig(configs, keyDeserializer, null); assertEquals(newConfigs.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG), keyDeserializerClass); assertEquals(newConfigs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG), valueDeserializerClass); configs.clear(); configs.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializerClass); newConfigs = ConsumerConfig.addDeserializerToConfig(configs, null, valueDeserializer); assertEquals(newConfigs.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG), keyDeserializerClass); assertEquals(newConfigs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG), valueDeserializerClass); configs.clear(); newConfigs = ConsumerConfig.addDeserializerToConfig(configs, keyDeserializer, valueDeserializer); assertEquals(newConfigs.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG), keyDeserializerClass); assertEquals(newConfigs.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG), valueDeserializerClass); }