Search in sources :

Example 11 with StreamsMetadataImpl

use of org.apache.kafka.streams.state.internals.StreamsMetadataImpl in project kafka by apache.

the class NamedTopologyIntegrationTest method verifyMetadataForTopology.

/**
 * Validates that each metadata object has only partitions & state stores for its specific topology name and
 * asserts that {@code left} and {@code right} differ only by {@link StreamsMetadata#hostInfo()}
 */
private void verifyMetadataForTopology(final String topologyName, final Collection<StreamsMetadata> left, final Collection<StreamsMetadata> right) {
    assertThat(left.size(), equalTo(right.size()));
    final Iterator<StreamsMetadata> leftIter = left.iterator();
    final Iterator<StreamsMetadata> rightIter = right.iterator();
    while (leftIter.hasNext()) {
        final StreamsMetadataImpl leftMetadata = (StreamsMetadataImpl) leftIter.next();
        final StreamsMetadataImpl rightMetadata = (StreamsMetadataImpl) rightIter.next();
        verifyPartitionsAndStoresForTopology(topologyName, leftMetadata);
        verifyPartitionsAndStoresForTopology(topologyName, rightMetadata);
        assertThat(verifyEquivalentMetadataForHost(leftMetadata, rightMetadata), is(true));
    }
}
Also used : StreamsMetadata(org.apache.kafka.streams.StreamsMetadata) StreamsMetadataImpl(org.apache.kafka.streams.state.internals.StreamsMetadataImpl)

Example 12 with StreamsMetadataImpl

use of org.apache.kafka.streams.state.internals.StreamsMetadataImpl in project kafka by apache.

the class StreamsMetadataState method getAllMetadataForTopology.

public synchronized Collection<StreamsMetadata> getAllMetadataForTopology(final String topologyName) {
    Objects.requireNonNull(topologyName, "topologyName cannot be null");
    if (!isInitialized()) {
        return Collections.emptyList();
    }
    final ArrayList<StreamsMetadata> results = new ArrayList<>();
    for (final StreamsMetadata metadata : allMetadata) {
        final String metadataTopologyName = ((StreamsMetadataImpl) metadata).topologyName();
        if (metadataTopologyName != null && metadataTopologyName.equals(topologyName)) {
            results.add(metadata);
        }
    }
    return results;
}
Also used : StreamsMetadata(org.apache.kafka.streams.StreamsMetadata) StreamsMetadataImpl(org.apache.kafka.streams.state.internals.StreamsMetadataImpl) ArrayList(java.util.ArrayList)

Example 13 with StreamsMetadataImpl

use of org.apache.kafka.streams.state.internals.StreamsMetadataImpl in project kafka by apache.

the class StreamsMetadataTest method shouldNotBeEqualIfDifferInHostInfo.

@Test
public void shouldNotBeEqualIfDifferInHostInfo() {
    final StreamsMetadata differHostInfo = new StreamsMetadataImpl(new HostInfo("different", 122), STATE_STORE_NAMES, TOPIC_PARTITIONS, STAND_BY_STORE_NAMES, STANDBY_TOPIC_PARTITIONS);
    assertThat(streamsMetadata, not(equalTo(differHostInfo)));
    assertThat(streamsMetadata.hashCode(), not(equalTo(differHostInfo.hashCode())));
}
Also used : StreamsMetadata(org.apache.kafka.streams.StreamsMetadata) StreamsMetadataImpl(org.apache.kafka.streams.state.internals.StreamsMetadataImpl) Test(org.junit.Test)

Example 14 with StreamsMetadataImpl

use of org.apache.kafka.streams.state.internals.StreamsMetadataImpl in project kafka by apache.

the class StreamsMetadataTest method shouldNotBeEqualIfDifferInStandByTopicPartitions.

@Test
public void shouldNotBeEqualIfDifferInStandByTopicPartitions() {
    final StreamsMetadata differStandByTopicPartitions = new StreamsMetadataImpl(HOST_INFO, STATE_STORE_NAMES, TOPIC_PARTITIONS, STAND_BY_STORE_NAMES, mkSet(TP_0));
    assertThat(streamsMetadata, not(equalTo(differStandByTopicPartitions)));
    assertThat(streamsMetadata.hashCode(), not(equalTo(differStandByTopicPartitions.hashCode())));
}
Also used : StreamsMetadata(org.apache.kafka.streams.StreamsMetadata) StreamsMetadataImpl(org.apache.kafka.streams.state.internals.StreamsMetadataImpl) Test(org.junit.Test)

Example 15 with StreamsMetadataImpl

use of org.apache.kafka.streams.state.internals.StreamsMetadataImpl in project kafka by apache.

the class StreamsMetadataTest method shouldNotBeEqualIfDifferStateStoreNames.

@Test
public void shouldNotBeEqualIfDifferStateStoreNames() {
    final StreamsMetadata differStateStoreNames = new StreamsMetadataImpl(HOST_INFO, mkSet("store1"), TOPIC_PARTITIONS, STAND_BY_STORE_NAMES, STANDBY_TOPIC_PARTITIONS);
    assertThat(streamsMetadata, not(equalTo(differStateStoreNames)));
    assertThat(streamsMetadata.hashCode(), not(equalTo(differStateStoreNames.hashCode())));
}
Also used : StreamsMetadata(org.apache.kafka.streams.StreamsMetadata) StreamsMetadataImpl(org.apache.kafka.streams.state.internals.StreamsMetadataImpl) Test(org.junit.Test)

Aggregations

StreamsMetadataImpl (org.apache.kafka.streams.state.internals.StreamsMetadataImpl)15 StreamsMetadata (org.apache.kafka.streams.StreamsMetadata)14 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)5 HostInfo (org.apache.kafka.streams.state.HostInfo)4 List (java.util.List)3 TopicPartition (org.apache.kafka.common.TopicPartition)3 HashSet (java.util.HashSet)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Cluster (org.apache.kafka.common.Cluster)1 Node (org.apache.kafka.common.Node)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 Serdes (org.apache.kafka.common.serialization.Serdes)1