Search in sources :

Example 21 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.

the class StreamThreadStateStoreProviderTest method shouldNotFindKeyValueStoresAsTimestampedStore.

@Test
public void shouldNotFindKeyValueStoresAsTimestampedStore() {
    mockThread(true);
    final InvalidStateStoreException exception = assertThrows(InvalidStateStoreException.class, () -> provider.stores(StoreQueryParameters.fromNameAndType("kv-store", QueryableStoreTypes.timestampedKeyValueStore())));
    assertThat(exception.getMessage(), is("Cannot get state store kv-store because the queryable store type " + "[class org.apache.kafka.streams.state.QueryableStoreTypes$TimestampedKeyValueStoreType] " + "does not accept the actual store type " + "[class org.apache.kafka.streams.state.internals.MeteredKeyValueStore]."));
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) Test(org.junit.Test)

Example 22 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.

the class CompositeReadOnlyWindowStoreTest method shouldThrowInvalidStateStoreExceptionOnRebalance.

@Test
public void shouldThrowInvalidStateStoreExceptionOnRebalance() {
    final StateStoreProvider storeProvider = EasyMock.createNiceMock(StateStoreProvider.class);
    EasyMock.expect(storeProvider.stores(anyString(), anyObject())).andThrow(new InvalidStateStoreException("store is unavailable"));
    EasyMock.replay(storeProvider);
    final CompositeReadOnlyWindowStore<Object, Object> store = new CompositeReadOnlyWindowStore<>(storeProvider, QueryableStoreTypes.windowStore(), "foo");
    assertThrows(InvalidStateStoreException.class, () -> store.fetch("key", ofEpochMilli(1), ofEpochMilli(10)));
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) EasyMock.anyObject(org.easymock.EasyMock.anyObject) Test(org.junit.Test)

Example 23 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.

the class RocksDBKeyValueStoreTest method shouldCloseOpenIteratorsWhenStoreClosedAndThrowInvalidStateStoreOnHasNextAndNext.

@Test
public void shouldCloseOpenIteratorsWhenStoreClosedAndThrowInvalidStateStoreOnHasNextAndNext() throws Exception {
    final KeyValueStoreTestDriver<Integer, String> driver = KeyValueStoreTestDriver.create(Integer.class, String.class);
    final MockProcessorContext context = (MockProcessorContext) driver.context();
    context.setTime(1L);
    final KeyValueStore<Integer, String> store = createStore(context, Integer.class, String.class, false, false);
    store.put(1, "hi");
    store.put(2, "goodbye");
    final KeyValueIterator<Integer, String> iteratorOne = store.range(1, 5);
    final KeyValueIterator<Integer, String> iteratorTwo = store.range(1, 4);
    assertTrue(iteratorOne.hasNext());
    assertTrue(iteratorTwo.hasNext());
    store.close();
    try {
        iteratorOne.hasNext();
        fail("should have thrown InvalidStateStoreException on closed store");
    } catch (InvalidStateStoreException e) {
    // ok
    }
    try {
        iteratorOne.next();
        fail("should have thrown InvalidStateStoreException on closed store");
    } catch (InvalidStateStoreException e) {
    // ok
    }
    try {
        iteratorTwo.hasNext();
        fail("should have thrown InvalidStateStoreException on closed store");
    } catch (InvalidStateStoreException e) {
    // ok
    }
    try {
        iteratorTwo.next();
        fail("should have thrown InvalidStateStoreException on closed store");
    } catch (InvalidStateStoreException e) {
    // ok
    }
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Test(org.junit.Test)

Example 24 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka-streams-examples by confluentinc.

the class OrdersService method fetchLocal.

/**
 * Fetch the order from the local materialized view
 *
 * @param id ID to fetch
 * @param asyncResponse the response to call once completed
 * @param predicate a filter that for this fetch, so for example we might fetch only VALIDATED
 * orders.
 */
private void fetchLocal(String id, AsyncResponse asyncResponse, Predicate<String, Order> predicate) {
    log.info("running GET on this node");
    try {
        Order order = ordersStore().get(id);
        if (order == null || !predicate.test(id, order)) {
            log.info("Delaying get as order not present for id " + id);
            outstandingRequests.put(id, new FilteredResponse<>(asyncResponse, predicate));
        } else {
            asyncResponse.resume(toBean(order));
        }
    } catch (InvalidStateStoreException e) {
        // Store not ready so delay
        outstandingRequests.put(id, new FilteredResponse<>(asyncResponse, predicate));
    }
}
Also used : Order(io.confluent.examples.streams.avro.microservices.Order) InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException)

Example 25 with InvalidStateStoreException

use of org.apache.kafka.streams.errors.InvalidStateStoreException in project apache-kafka-on-k8s by banzaicloud.

the class CompositeReadOnlyKeyValueStore method get.

@Override
public V get(final K key) {
    Objects.requireNonNull(key);
    final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType);
    for (ReadOnlyKeyValueStore<K, V> store : stores) {
        try {
            final V result = store.get(key);
            if (result != null) {
                return result;
            }
        } catch (InvalidStateStoreException e) {
            throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata.");
        }
    }
    return null;
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyKeyValueStore(org.apache.kafka.streams.state.ReadOnlyKeyValueStore)

Aggregations

InvalidStateStoreException (org.apache.kafka.streams.errors.InvalidStateStoreException)46 Windowed (org.apache.kafka.streams.kstream.Windowed)14 Test (org.junit.Test)14 ReadOnlyKeyValueStore (org.apache.kafka.streams.state.ReadOnlyKeyValueStore)13 ArrayList (java.util.ArrayList)12 KeyValue (org.apache.kafka.streams.KeyValue)10 TimeWindow (org.apache.kafka.streams.kstream.internals.TimeWindow)9 KeyValueIterator (org.apache.kafka.streams.state.KeyValueIterator)9 KafkaStreams (org.apache.kafka.streams.KafkaStreams)8 IntegrationTest (org.apache.kafka.test.IntegrationTest)7 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)6 ReadOnlySessionStore (org.apache.kafka.streams.state.ReadOnlySessionStore)6 Properties (java.util.Properties)4 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)4 KeyQueryMetadata (org.apache.kafka.streams.KeyQueryMetadata)4 ReadOnlyWindowStore (org.apache.kafka.streams.state.ReadOnlyWindowStore)4 Semaphore (java.util.concurrent.Semaphore)3 KafkaStreamsTest (org.apache.kafka.streams.KafkaStreamsTest)3 IOException (java.io.IOException)2 TreeMap (java.util.TreeMap)2