use of org.apache.kafka.streams.KeyQueryMetadata in project kafka by apache.
the class StreamsMetadataStateTest method shouldGetInstanceWithKeyAndCustomPartitioner.
@Test
public void shouldGetInstanceWithKeyAndCustomPartitioner() {
final TopicPartition tp4 = new TopicPartition("topic-three", 1);
hostToActivePartitions.put(hostTwo, mkSet(topic2P0, tp4));
metadataState.onChange(hostToActivePartitions, hostToStandbyPartitions, cluster.withPartitions(Collections.singletonMap(tp4, new PartitionInfo("topic-three", 1, null, null, null))));
final KeyQueryMetadata expected = new KeyQueryMetadata(hostTwo, Collections.emptySet(), 1);
final KeyQueryMetadata actual = metadataState.getKeyQueryMetadataForKey("table-three", "the-key", partitioner);
assertEquals(expected, actual);
assertEquals(1, actual.partition());
}
use of org.apache.kafka.streams.KeyQueryMetadata in project kafka by apache.
the class StreamsMetadataStateTest method shouldReturnNotAvailableWhenClusterIsEmpty.
@Test
public void shouldReturnNotAvailableWhenClusterIsEmpty() {
metadataState.onChange(Collections.emptyMap(), Collections.emptyMap(), Cluster.empty());
final KeyQueryMetadata result = metadataState.getKeyQueryMetadataForKey("table-one", "a", Serdes.String().serializer());
assertEquals(KeyQueryMetadata.NOT_AVAILABLE, result);
}
use of org.apache.kafka.streams.KeyQueryMetadata in project kafka by apache.
the class StreamsMetadataStateTest method shouldGetQueryMetadataForGlobalStoreWithKeyAndPartitioner.
@Test
public void shouldGetQueryMetadataForGlobalStoreWithKeyAndPartitioner() {
final KeyQueryMetadata metadata = metadataState.getKeyQueryMetadataForKey(globalTable, "key", partitioner);
assertEquals(hostOne, metadata.activeHost());
assertTrue(metadata.standbyHosts().isEmpty());
}
use of org.apache.kafka.streams.KeyQueryMetadata in project kafka by apache.
the class StreamsMetadataStateTest method shouldGetQueryMetadataForGlobalStoreWithKey.
@Test
public void shouldGetQueryMetadataForGlobalStoreWithKey() {
final KeyQueryMetadata metadata = metadataState.getKeyQueryMetadataForKey(globalTable, "key", Serdes.String().serializer());
assertEquals(hostOne, metadata.activeHost());
assertTrue(metadata.standbyHosts().isEmpty());
}
use of org.apache.kafka.streams.KeyQueryMetadata in project kafka by apache.
the class QueryableStateIntegrationTest method verifyAllKVKeys.
private void verifyAllKVKeys(final List<KafkaStreams> streamsList, final KafkaStreams streams, final KafkaStreamsTest.StateListenerStub stateListener, final Set<String> keys, final String storeName, final long timeout, final boolean pickInstanceByPort) throws Exception {
retryOnExceptionWithTimeout(timeout, () -> {
final List<String> noMetadataKeys = new ArrayList<>();
final List<String> nullStoreKeys = new ArrayList<>();
final List<String> nullValueKeys = new ArrayList<>();
final Map<String, Exception> exceptionalKeys = new TreeMap<>();
final StringSerializer serializer = new StringSerializer();
for (final String key : keys) {
try {
final KeyQueryMetadata queryMetadata = streams.queryMetadataForKey(storeName, key, serializer);
if (queryMetadata == null || queryMetadata.equals(KeyQueryMetadata.NOT_AVAILABLE)) {
noMetadataKeys.add(key);
continue;
}
if (!pickInstanceByPort) {
assertThat("Should have standbys to query from", !queryMetadata.standbyHosts().isEmpty());
}
final int index = queryMetadata.activeHost().port();
final KafkaStreams streamsWithKey = pickInstanceByPort ? streamsList.get(index) : streams;
final ReadOnlyKeyValueStore<String, Long> store = IntegrationTestUtils.getStore(storeName, streamsWithKey, true, keyValueStore());
if (store == null) {
nullStoreKeys.add(key);
continue;
}
if (store.get(key) == null) {
nullValueKeys.add(key);
}
} catch (final InvalidStateStoreException e) {
if (stateListener.mapStates.get(KafkaStreams.State.REBALANCING) < 1) {
throw new NoRetryException(new AssertionError(String.format("Received %s for key %s and expected at least one rebalancing state, but had none", e.getClass().getName(), key)));
}
} catch (final Exception e) {
exceptionalKeys.put(key, e);
}
}
assertNoKVKeyFailures(storeName, timeout, noMetadataKeys, nullStoreKeys, nullValueKeys, exceptionalKeys);
});
}
Aggregations