while (results.hasNext()) { final KeyValue<Long, Long> next = results.next();
/** * 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"); }
private boolean isDuplicate(final E eventId) { long eventTime = context.timestamp(); WindowStoreIterator<Long> timeIterator = eventIdStore.fetch( eventId, eventTime - leftDurationMs, eventTime + rightDurationMs); boolean isDuplicate = timeIterator.hasNext(); timeIterator.close(); return isDuplicate; }
@Override public boolean hasNext() { return iter.hasNext(); }
@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(); }