クラス KafkaTestUtils

java.lang.ObjectSE
org.springframework.kafka.test.utils.KafkaTestUtils

public final class KafkaTestUtils extends ObjectSE
Kafka テストユーティリティ。
作成者:
Gary Russell, Hugo Wood, Artem Bilan
  • メソッドのサマリー

    修飾子と型
    メソッド
    説明
    consumerProps(StringSE brokers, StringSE group, StringSE autoCommit)
    <Integer, String> コンシューマーのテストプロパティを設定します。
    consumerProps(StringSE group, StringSE autoCommit, EmbeddedKafkaBroker embeddedKafka)
    <Integer, String> コンシューマーのテストプロパティを設定します。
    デフォルトのコンシューマープロパティのオーバーライドに等しい PropertiesSE オブジェクトを返します。
    static org.apache.kafka.clients.consumer.OffsetAndMetadata
    getCurrentOffset(StringSE brokerAddresses, StringSE group, StringSE topic, int partition)
    提供されたグループ / トピック / パーティションの現在のオフセットとメタデータを取得します。
    static org.apache.kafka.clients.consumer.OffsetAndMetadata
    getCurrentOffset(org.apache.kafka.clients.admin.AdminClient adminClient, StringSE group, StringSE topic, int partition)
    提供されたグループ / トピック / パーティションの現在のオフセットとメタデータを取得します。
    static MapSE<org.apache.kafka.common.TopicPartition,LongSE>
    getEndOffsets(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, StringSE topic, IntegerSE... partitions)
    リクエストされたトピック / パーティションの終了オフセットを返します
    static org.apache.kafka.clients.consumer.ConsumerRecord<?,?>
    getOneRecord(StringSE brokerAddresses, StringSE group, StringSE topic, int partition, boolean seekToLast, boolean commit, DurationSE timeout)
    トピック / パーティションからグループの単一のレコードを取得します。
    static ObjectSE
    getPropertyValue(ObjectSE root, StringSE propertyPath)
    ネストされた DirectFieldAccessor を使用して、ドット表記を使用してプロパティを取得し、フィールドをトラバースします。たとえば
    static <T> T
    getPropertyValue(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)
    指定されたトピックの単一のレコードを期待して、コンシューマーをポーリングします。
    <Integer, String> プロデューサーのテストプロパティを設定します。
    <Integer, String> プロデューサーのテストプロパティを設定します。

    クラス java.lang.ObjectSE から継承されたメソッド

    clone, equalsSE, finalize, getClass, hashCode, notify, notifyAll, toString, wait, waitSE, waitSE
  • メソッドの詳細

    • consumerProps

      public static MapSE<StringSE,ObjectSE> consumerProps(StringSE group, StringSE autoCommit, EmbeddedKafkaBroker embeddedKafka)
      <Integer, String> コンシューマーのテストプロパティを設定します。
      パラメーター:
      group - グループ ID。
      autoCommit - 自動コミット。
      embeddedKafka - EmbeddedKafkaBroker インスタンス。
      戻り値:
      プロパティ。
    • producerProps

      public static MapSE<StringSE,ObjectSE> producerProps(EmbeddedKafkaBroker embeddedKafka)
      <Integer, String> プロデューサーのテストプロパティを設定します。
      パラメーター:
      embeddedKafka - EmbeddedKafkaBroker インスタンス。
      戻り値:
      プロパティ。
    • consumerProps

      public static MapSE<StringSE,ObjectSE> consumerProps(StringSE brokers, StringSE group, StringSE autoCommit)
      <Integer, String> コンシューマーのテストプロパティを設定します。
      パラメーター:
      brokers - bootstrapServers プロパティ。
      group - グループ ID。
      autoCommit - 自動コミット。
      戻り値:
      プロパティ。
    • producerProps

      public static MapSE<StringSE,ObjectSE> producerProps(StringSE brokers)
      <Integer, String> プロデューサーのテストプロパティを設定します。
      パラメーター:
      brokers - bootstrapServers プロパティ。
      戻り値:
      プロパティ。
      導入:
      2.3.5
    • 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

      @Nullable public static 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 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 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... partitions)
      リクエストされたトピック / パーティションの終了オフセットを返します
      パラメーター:
      consumer - コンシューマー。
      topic - トピック。
      partitions - パーティション、またはすべてのパーティションの場合は null。
      戻り値:
      エンドオフセットのマップ。
      導入:
      2.6.5
      関連事項:
      • Consumer.endOffsets(Collection, Duration)
    • 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

      public static ObjectSE getPropertyValue(ObjectSE root, StringSE propertyPath)
      ネストされた DirectFieldAccessor を使用して、ドット表記を使用してプロパティを取得し、フィールドをトラバースします。たとえば "foo.bar.baz" は、foo の bar フィールドの baz フィールドへの参照を取得します。Spring Integration から採用。
      パラメーター:
      root - オブジェクト。
      propertyPath - パス。
      戻り値:
      フィールド。
    • getPropertyValue

      public static <T> T getPropertyValue(ObjectSE root, StringSE propertyPath, ClassSE<T> type)
      getPropertyValue(Object, String) の型付きバージョン。
      型パラメーター:
      T - 型。
      パラメーター:
      root - オブジェクト。
      propertyPath - パス。
      type - オブジェクトをキャストする型。
      戻り値:
      フィールド値。
      関連事項:
    • defaultPropertyOverrides

      public static PropertiesSE defaultPropertyOverrides()
      デフォルトのコンシューマープロパティのオーバーライドに等しい PropertiesSE オブジェクトを返します。Mockito テストで引数を照合するときに役立ちます。
      戻り値:
      デフォルトのプロパティ。
      導入:
      2.2.5