final WindowStoreIterator<Long> results = store.fetch(key, from, to);
@Override public KeyValueIterator<Windowed<K>, V> apply(final ReadOnlyWindowStore<K, V> store) { return store.all(); } };
@Override public KeyValueIterator<Windowed<K>, V> apply(final ReadOnlyWindowStore<K, V> store) { return store.fetchAll(timeFrom, timeTo); } };
/** * Asserts that the oldest available window in the window store contains the expected content. * * @param store the store to be validated * @param expected the expected contents of the store * @param <K> the store's key type * @param <V> the store's value type */ public static <K, V> void assertThatOldestWindowContains(ReadOnlyWindowStore<K, V> store, Map<K, V> expected) throws InterruptedException { final long fromBeginningOfTimeMs = 0; final long toNowInProcessingTimeMs = System.currentTimeMillis(); TestUtils.waitForCondition(() -> expected.keySet().stream().allMatch(k -> { try (WindowStoreIterator<V> iterator = store.fetch(k, fromBeginningOfTimeMs, toNowInProcessingTimeMs)) { if (iterator.hasNext()) { return expected.get(k).equals(iterator.next().value); } return false; } }), 30000, "Expected values not found in WindowStore"); }
@Override public KeyValueIterator<Windowed<K>, V> apply(final ReadOnlyWindowStore<K, V> store) { return store.fetch(from, to, timeFrom, timeTo); } };
@Override public V fetch(final K key, final long time) { Objects.requireNonNull(key, "key can't be null"); final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (final ReadOnlyWindowStore<K, V> windowStore : stores) { try { final V result = windowStore.fetch(key, time); if (result != null) { return result; } } catch (final 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; }
@Override @Deprecated public WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) { Objects.requireNonNull(key, "key can't be null"); final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType); for (final ReadOnlyWindowStore<K, V> windowStore : stores) { try { final WindowStoreIterator<V> result = windowStore.fetch(key, timeFrom, timeTo); if (!result.hasNext()) { result.close(); } else { return result; } } catch (final 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 KeyValueIterators.emptyWindowStoreIterator(); }