use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.
the class CompositeReadOnlyWindowStoreTest method shouldThrowInvalidStateStoreExceptionOnRebalanceWhenBackwards.
@Test
public void shouldThrowInvalidStateStoreExceptionOnRebalanceWhenBackwards() {
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.backwardFetch("key", ofEpochMilli(1), ofEpochMilli(10)));
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.
the class ReadOnlyWindowStoreStub method fetch.
@Override
public KeyValueIterator<Windowed<K>, V> fetch(final K keyFrom, final K keyTo, final Instant timeFrom, final Instant timeTo) {
if (!open) {
throw new InvalidStateStoreException("Store is not open");
}
final List<KeyValue<Windowed<K>, V>> results = new ArrayList<>();
for (long now = timeFrom.toEpochMilli(); now <= timeTo.toEpochMilli(); now++) {
final NavigableMap<K, V> kvMap = data.get(now);
if (kvMap != null) {
final NavigableMap<K, V> kvSubMap;
if (keyFrom == null && keyFrom == null) {
kvSubMap = kvMap;
} else if (keyFrom == null) {
kvSubMap = kvMap.headMap(keyTo, true);
} else if (keyTo == null) {
kvSubMap = kvMap.tailMap(keyFrom, true);
} else {
// keyFrom != null and KeyTo != null
kvSubMap = kvMap.subMap(keyFrom, true, keyTo, true);
}
for (final Entry<K, V> entry : kvSubMap.entrySet()) {
results.add(new KeyValue<>(new Windowed<>(entry.getKey(), new TimeWindow(now, now + windowSize)), entry.getValue()));
}
}
}
final Iterator<KeyValue<Windowed<K>, V>> iterator = results.iterator();
return new KeyValueIterator<Windowed<K>, V>() {
@Override
public void close() {
}
@Override
public Windowed<K> peekNextKey() {
throw new UnsupportedOperationException("peekNextKey() not supported in " + getClass().getName());
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public KeyValue<Windowed<K>, V> next() {
return iterator.next();
}
};
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.
the class ReadOnlyWindowStoreStub method backwardAll.
@Override
public KeyValueIterator<Windowed<K>, V> backwardAll() {
if (!open) {
throw new InvalidStateStoreException("Store is not open");
}
final List<KeyValue<Windowed<K>, V>> results = new ArrayList<>();
for (final long now : data.descendingKeySet()) {
final NavigableMap<K, V> kvMap = data.get(now);
if (kvMap != null) {
for (final Entry<K, V> entry : kvMap.descendingMap().entrySet()) {
results.add(new KeyValue<>(new Windowed<>(entry.getKey(), new TimeWindow(now, now + windowSize)), entry.getValue()));
}
}
}
final Iterator<KeyValue<Windowed<K>, V>> iterator = results.iterator();
return new KeyValueIterator<Windowed<K>, V>() {
@Override
public void close() {
}
@Override
public Windowed<K> peekNextKey() {
throw new UnsupportedOperationException("peekNextKey() not supported in " + getClass().getName());
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public KeyValue<Windowed<K>, V> next() {
return iterator.next();
}
};
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.
the class ReadOnlyWindowStoreStub method backwardFetchAll.
@Override
public KeyValueIterator<Windowed<K>, V> backwardFetchAll(final Instant timeFrom, final Instant timeTo) throws IllegalArgumentException {
final long timeFromTs = ApiUtils.validateMillisecondInstant(timeFrom, prepareMillisCheckFailMsgPrefix(timeFrom, "timeFrom"));
final long timeToTs = ApiUtils.validateMillisecondInstant(timeTo, prepareMillisCheckFailMsgPrefix(timeTo, "timeTo"));
if (!open) {
throw new InvalidStateStoreException("Store is not open");
}
final List<KeyValue<Windowed<K>, V>> results = new ArrayList<>();
for (final long now : data.descendingKeySet()) {
if (!(now >= timeFromTs && now <= timeToTs)) {
continue;
}
final NavigableMap<K, V> kvMap = data.get(now);
if (kvMap != null) {
for (final Entry<K, V> entry : kvMap.descendingMap().entrySet()) {
results.add(new KeyValue<>(new Windowed<>(entry.getKey(), new TimeWindow(now, now + windowSize)), entry.getValue()));
}
}
}
final Iterator<KeyValue<Windowed<K>, V>> iterator = results.iterator();
return new KeyValueIterator<Windowed<K>, V>() {
@Override
public void close() {
}
@Override
public Windowed<K> peekNextKey() {
throw new UnsupportedOperationException("peekNextKey() not supported in " + getClass().getName());
}
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public KeyValue<Windowed<K>, V> next() {
return iterator.next();
}
};
}
use of org.apache.kafka.streams.errors.InvalidStateStoreException in project kafka by apache.
the class QueryableStoreProviderTest method shouldThrowExceptionWhenKVStoreWithPartitionDoesntExists.
@Test
public void shouldThrowExceptionWhenKVStoreWithPartitionDoesntExists() {
final int partition = numStateStorePartitions + 1;
final InvalidStateStoreException thrown = assertThrows(InvalidStateStoreException.class, () -> storeProvider.getStore(StoreQueryParameters.fromNameAndType(keyValueStore, QueryableStoreTypes.keyValueStore()).withPartition(partition)).get("1"));
assertThat(thrown.getMessage(), equalTo(String.format("The specified partition %d for store %s does not exist.", partition, keyValueStore)));
}
Aggregations