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]."));
}
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)));
}
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
}
}
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));
}
}
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;
}
Aggregations