クラス KafkaTestUtils
java.lang.ObjectSE
org.springframework.kafka.test.utils.KafkaTestUtils
Kafka テストユーティリティ。
- 作成者:
- Gary Russell, Hugo Wood, Artem Bilan, Sanghyeok An, Mikhail Polivakha
方法の概要
修飾子と型メソッド説明consumerProps(StringSE brokers, StringSE group) <Integer, String>コンシューマーのテストプロパティを設定します。consumerProps(StringSE brokers, StringSE group, boolean autoCommit) <Integer, String>コンシューマーのテストプロパティを設定します。consumerProps(StringSE brokers, StringSE group, StringSE autoCommit) 非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。consumerProps(StringSE group, StringSE autoCommit, EmbeddedKafkaBroker embeddedKafka) 非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。代わりにconsumerProps(EmbeddedKafkaBroker, String, boolean)を使用してくださいconsumerProps(EmbeddedKafkaBroker embeddedKafka, StringSE group, boolean autoCommit) <Integer, String>コンシューマーのテストプロパティを設定します。static PropertiesSEデフォルトのコンシューマープロパティのオーバーライドに等しいPropertiesSE オブジェクトを返します。static @Nullable org.apache.kafka.clients.consumer.OffsetAndMetadatagetCurrentOffset(StringSE brokerAddresses, StringSE group, StringSE topic, int partition) 提供されたグループ / トピック / パーティションの現在のオフセットとメタデータを取得します。static @Nullable org.apache.kafka.clients.consumer.OffsetAndMetadatagetCurrentOffset(org.apache.kafka.clients.admin.AdminClient adminClient, StringSE group, StringSE topic, int partition) 提供されたグループ / トピック / パーティションの現在のオフセットとメタデータを取得します。getEndOffsets(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, StringSE topic, IntegerSE @Nullable... partitions) リクエストされたトピック / パーティションの終了オフセットを返しますstatic @Nullable org.apache.kafka.clients.consumer.ConsumerRecord<?, ?> getOneRecord(StringSE brokerAddresses, StringSE group, StringSE topic, int partition, boolean seekToLast, boolean commit, DurationSE timeout) トピック / パーティションからグループの単一のレコードを取得します。static @Nullable ObjectSEgetPropertyValue(ObjectSE root, StringSE propertyPath) ネストされたDirectFieldAccessorを使用して、ドット表記を使用してプロパティを取得し、フィールドをトラバースします。たとえばstatic <T> @Nullable TgetPropertyValue(ObjectSE root, StringSE propertyPath, ClassSE<T> type) getPropertyValue(Object, String)の型付きバージョン。static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords <K, V> getRecords(org.apache.kafka.clients.consumer.Consumer<K, V> consumer) 記録のためにコンシューマーをポーリングします。static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords <K, V> getRecords(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, DurationSE timeout) 記録のためにコンシューマーをポーリングします。static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords <K, V> getRecords(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, DurationSE timeout, int minRecords) 記録のためにコンシューマーをポーリングします。static <K,V> org.apache.kafka.clients.consumer.ConsumerRecord <K, V> getSingleRecord(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, StringSE topic) 指定されたトピックの単一のレコードを期待して、コンシューマーをポーリングします。static <K,V> org.apache.kafka.clients.consumer.ConsumerRecord <K, V> getSingleRecord(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, StringSE topic, DurationSE timeout) 指定されたトピックの単一のレコードを期待して、コンシューマーをポーリングします。producerProps(StringSE brokers) <Integer, String>プロデューサーのテストプロパティを設定します。producerProps(EmbeddedKafkaBroker embeddedKafka) <Integer, String>プロデューサーのテストプロパティを設定します。streamsProps(StringSE applicationId, StringSE brokers) Kafka ストリームのテストプロパティを設定します。
メソッドの詳細
consumerProps
@DeprecatedSE(forRemoval=true, since="4.0.0") public static MapSE<StringSE,ObjectSE> consumerProps(StringSE group, StringSE autoCommit, EmbeddedKafkaBroker embeddedKafka) 非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。代わりにconsumerProps(EmbeddedKafkaBroker, String, boolean)を使用してください<Integer, String>コンシューマーのテストプロパティを設定します。- パラメーター:
group- グループ ID。autoCommit- 自動コミット。embeddedKafka-EmbeddedKafkaBrokerインスタンス。- 戻り値:
- プロパティ。
consumerProps
public static MapSE<StringSE,ObjectSE> consumerProps(EmbeddedKafkaBroker embeddedKafka, StringSE group, boolean autoCommit) <Integer, String>コンシューマーのテストプロパティを設定します。- パラメーター:
embeddedKafka-EmbeddedKafkaBrokerインスタンス。group- グループ ID。autoCommit- 自動コミット。- 戻り値:
- プロパティ。
- 導入:
- 4.0
consumerProps
producerProps
<Integer, String>プロデューサーのテストプロパティを設定します。- パラメーター:
embeddedKafka-EmbeddedKafkaBrokerインスタンス。- 戻り値:
- プロパティ。
consumerProps
@DeprecatedSE(forRemoval=true, since="4.0.0") public static MapSE<StringSE,ObjectSE> consumerProps(StringSE brokers, StringSE group, StringSE autoCommit) 非推奨、削除予定: この API 要素は、将来のバージョンで削除される可能性があります。代わりにconsumerProps(String, String, boolean)を使用してください。<Integer, String>コンシューマーのテストプロパティを設定します。- パラメーター:
brokers- bootstrapServers プロパティ。group- グループ ID。autoCommit- 自動コミット。- 戻り値:
- プロパティ。
consumerProps
producerProps
streamsProps
getSingleRecord
public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecord<K,V> getSingleRecord(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, StringSE topic) 指定されたトピックの単一のレコードを期待して、コンシューマーをポーリングします。- 型パラメーター:
K- 鍵の型。V- 値の型。- パラメーター:
consumer- コンシューマー。topic- トピック。- 戻り値:
- レコード。
- 例外:
IllegalStateExceptionSE- 正確に 1 つのレコードが受信されない場合。- 関連事項:
getSingleRecord
public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecord<K,V> getSingleRecord(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, StringSE topic, DurationSE timeout) 指定されたトピックの単一のレコードを期待して、コンシューマーをポーリングします。- 型パラメーター:
K- 鍵の型。V- 値の型。- パラメーター:
consumer- コンシューマー。topic- トピック。timeout- レコードを待機する最大期間。Consumer.poll(Duration)に転送されます。- 戻り値:
- レコード。
- 例外:
IllegalStateExceptionSE- 正確に 1 つのレコードが受信されない場合。- 導入:
- 2.9.3
getOneRecord
public static @Nullable org.apache.kafka.clients.consumer.ConsumerRecord<?,?> getOneRecord(StringSE brokerAddresses, StringSE group, StringSE topic, int partition, boolean seekToLast, boolean commit, DurationSE timeout) トピック / パーティションからグループの単一のレコードを取得します。オプションで、現在の最後のレコードを探します。- パラメーター:
brokerAddresses- ブローカーの住所。group- グループ。topic- トピック。partition- パーティション。seekToLast- 存在する場合、既存の最後のレコードをフェッチする場合は true。commit- ポーリング後にオフセットをコミットするかどうか。timeout- タイムアウト。- 戻り値:
- レコード。レコードを受信しなかった場合は null。
- 導入:
- 2.9.3
getCurrentOffset
public static @Nullable org.apache.kafka.clients.consumer.OffsetAndMetadata getCurrentOffset(StringSE brokerAddresses, StringSE group, StringSE topic, int partition) throws ExceptionSE 提供されたグループ / トピック / パーティションの現在のオフセットとメタデータを取得します。- パラメーター:
brokerAddresses- ブローカーの住所。group- グループ。topic- トピック。partition- パーティション。- 戻り値:
- オフセットとメタデータ。
- 例外:
ExceptionSE- 例外が発生した場合。- 導入:
- 2.3
getCurrentOffset
public static @Nullable org.apache.kafka.clients.consumer.OffsetAndMetadata getCurrentOffset(org.apache.kafka.clients.admin.AdminClient adminClient, StringSE group, StringSE topic, int partition) throws ExceptionSE 提供されたグループ / トピック / パーティションの現在のオフセットとメタデータを取得します。- パラメーター:
adminClient- AdminClient インスタンス。group- グループ。topic- トピック。partition- パーティション。- 戻り値:
- オフセットとメタデータ。
- 例外:
ExceptionSE- 例外が発生した場合。- 導入:
- 3.0
getEndOffsets
public static MapSE<org.apache.kafka.common.TopicPartition, LongSE> getEndOffsets(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, StringSE topic, IntegerSE @Nullable ... partitions) リクエストされたトピック / パーティションの終了オフセットを返します- パラメーター:
consumer- コンシューマー。topic- トピック。partitions- パーティション、またはすべてのパーティションの場合は null。- 戻り値:
- エンドオフセットのマップ。
- 導入:
- 2.6.5
- 関連事項:
getRecords
public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> getRecords(org.apache.kafka.clients.consumer.Consumer<K, V> consumer) 記録のためにコンシューマーをポーリングします。- 型パラメーター:
K- 鍵の型。V- 値の型。- パラメーター:
consumer- コンシューマー。- 戻り値:
- 記録。
- 関連事項:
getRecords
public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> getRecords(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, DurationSE timeout) 記録のためにコンシューマーをポーリングします。- 型パラメーター:
K- 鍵の型。V- 値の型。- パラメーター:
consumer- コンシューマー。timeout- レコードを待機する最大時間(ミリ秒単位)。Consumer.poll(Duration)に転送されます。- 戻り値:
- 記録。
- 例外:
IllegalStateExceptionSE- ポーリングが null を返した場合(2.3.4 以降)。- 導入:
- 2.9.3
getRecords
public static <K,V> org.apache.kafka.clients.consumer.ConsumerRecords<K,V> getRecords(org.apache.kafka.clients.consumer.Consumer<K, V> consumer, DurationSE timeout, int minRecords) 記録のためにコンシューマーをポーリングします。- 型パラメーター:
K- 鍵の型。V- 値の型。- パラメーター:
consumer- コンシューマー。timeout- レコードを待機する最大時間(ミリ秒単位)。Consumer.poll(Duration)に転送されます。minRecords- タイムアウトになるまで、または少なくともこの数のレコードが受信されるまで待ちます。- 戻り値:
- 記録。
- 例外:
IllegalStateExceptionSE- ポーリングが null を返した場合。- 導入:
- 2.9.3
getPropertyValue
ネストされたDirectFieldAccessorを使用して、ドット表記を使用してプロパティを取得し、フィールドをトラバースします。たとえば "foo.bar.baz" は、foo の bar フィールドの baz フィールドへの参照を取得します。Spring Integration から採用。- パラメーター:
root- オブジェクト。propertyPath- パス。- 戻り値:
- フィールド。
getPropertyValue
public static <T> @Nullable T getPropertyValue(ObjectSE root, StringSE propertyPath, ClassSE<T> type) getPropertyValue(Object, String)の型付きバージョン。- 型パラメーター:
T- 型。- パラメーター:
root- オブジェクト。propertyPath- パス。type- オブジェクトをキャストする型。- 戻り値:
- フィールド値。
- 関連事項:
defaultPropertyOverrides
デフォルトのコンシューマープロパティのオーバーライドに等しいPropertiesSE オブジェクトを返します。Mockito テストで引数を照合するときに役立ちます。- 戻り値:
- デフォルトのプロパティ。
- 導入:
- 2.2.5
consumerProps(String, String, boolean)を使用してください。