当前位置: 首页>>代码示例>>Java>>正文


Java KeyValueStore.put方法代码示例

本文整理汇总了Java中org.apache.kafka.streams.state.KeyValueStore.put方法的典型用法代码示例。如果您正苦于以下问题:Java KeyValueStore.put方法的具体用法?Java KeyValueStore.put怎么用?Java KeyValueStore.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.kafka.streams.state.KeyValueStore的用法示例。


在下文中一共展示了KeyValueStore.put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldSupportRangeAcrossMultipleKVStores

import org.apache.kafka.streams.state.KeyValueStore; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void shouldSupportRangeAcrossMultipleKVStores() throws Exception {
    final KeyValueStore<String, String> cache = newStoreInstance();
    stubProviderTwo.addStore(storeName, cache);

    stubOneUnderlying.put("a", "a");
    stubOneUnderlying.put("b", "b");
    stubOneUnderlying.put("z", "z");

    cache.put("c", "c");
    cache.put("d", "d");
    cache.put("x", "x");

    final List<KeyValue<String, String>> results = toList(theStore.range("a", "e"));
    assertTrue(results.contains(new KeyValue<>("a", "a")));
    assertTrue(results.contains(new KeyValue<>("b", "b")));
    assertTrue(results.contains(new KeyValue<>("c", "c")));
    assertTrue(results.contains(new KeyValue<>("d", "d")));
    assertEquals(4, results.size());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:22,代码来源:CompositeReadOnlyKeyValueStoreTest.java

示例2: shouldSupportAllAcrossMultipleStores

import org.apache.kafka.streams.state.KeyValueStore; //导入方法依赖的package包/类
@Test
public void shouldSupportAllAcrossMultipleStores() throws Exception {
    final KeyValueStore<String, String> cache = newStoreInstance();
    stubProviderTwo.addStore(storeName, cache);

    stubOneUnderlying.put("a", "a");
    stubOneUnderlying.put("b", "b");
    stubOneUnderlying.put("z", "z");

    cache.put("c", "c");
    cache.put("d", "d");
    cache.put("x", "x");

    final List<KeyValue<String, String>> results = toList(theStore.all());
    assertTrue(results.contains(new KeyValue<>("a", "a")));
    assertTrue(results.contains(new KeyValue<>("b", "b")));
    assertTrue(results.contains(new KeyValue<>("c", "c")));
    assertTrue(results.contains(new KeyValue<>("d", "d")));
    assertTrue(results.contains(new KeyValue<>("x", "x")));
    assertTrue(results.contains(new KeyValue<>("z", "z")));
    assertEquals(6, results.size());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:23,代码来源:CompositeReadOnlyKeyValueStoreTest.java

示例3: shouldPeekNextKey

import org.apache.kafka.streams.state.KeyValueStore; //导入方法依赖的package包/类
@Test
public void shouldPeekNextKey() throws Exception {
    final KeyValueStore<Bytes, byte[]> kv = new InMemoryKeyValueStore<>("one", Serdes.Bytes(), Serdes.ByteArray());
    final ThreadCache cache = new ThreadCache("testCache", 1000000L, new MockStreamsMetrics(new Metrics()));
    byte[][] bytes = {{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}};
    final String namespace = "one";
    for (int i = 0; i < bytes.length - 1; i += 2) {
        kv.put(Bytes.wrap(bytes[i]), bytes[i]);
        cache.put(namespace, Bytes.wrap(bytes[i + 1]), new LRUCacheEntry(bytes[i + 1]));
    }

    final Bytes from = Bytes.wrap(new byte[]{2});
    final Bytes to = Bytes.wrap(new byte[]{9});
    final KeyValueIterator<Bytes, byte[]> storeIterator = kv.range(from, to);
    final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(namespace, from, to);

    final MergedSortedCacheKeyValueStoreIterator<byte[], byte[]> iterator =
            new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator,
                                                         storeIterator,
                                                         serdes);
    final byte[][] values = new byte[8][];
    int index = 0;
    int bytesIndex = 2;
    while (iterator.hasNext()) {
        final byte[] keys = iterator.peekNextKey();
        values[index++] = keys;
        assertArrayEquals(bytes[bytesIndex++], keys);
        iterator.next();
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:31,代码来源:MergedSortedCacheKeyValueStoreIteratorTest.java

示例4: shouldFindValueForKeyWhenMultiStores

import org.apache.kafka.streams.state.KeyValueStore; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void shouldFindValueForKeyWhenMultiStores() throws Exception {
    final KeyValueStore<String, String> cache = newStoreInstance();
    stubProviderTwo.addStore(storeName, cache);

    cache.put("key-two", "key-two-value");
    stubOneUnderlying.put("key-one", "key-one-value");

    assertEquals("key-two-value", theStore.get("key-two"));
    assertEquals("key-one-value", theStore.get("key-one"));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:13,代码来源:CompositeReadOnlyKeyValueStoreTest.java

示例5: shouldGetApproximateEntriesAcrossAllStores

import org.apache.kafka.streams.state.KeyValueStore; //导入方法依赖的package包/类
@Test
public void shouldGetApproximateEntriesAcrossAllStores() throws Exception {
    final KeyValueStore<String, String> cache = newStoreInstance();
    stubProviderTwo.addStore(storeName, cache);

    stubOneUnderlying.put("a", "a");
    stubOneUnderlying.put("b", "b");
    stubOneUnderlying.put("z", "z");

    cache.put("c", "c");
    cache.put("d", "d");
    cache.put("x", "x");

    assertEquals(6, theStore.approximateNumEntries());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:16,代码来源:CompositeReadOnlyKeyValueStoreTest.java

示例6: process

import org.apache.kafka.streams.state.KeyValueStore; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void process(K key, V value) {
    initializeIfNotAndGet(this.stages);
    if(value != null && checkHighWaterMarkAndUpdate()) {
        Event<K, V> event = new Event<>(key, value, context.timestamp(), context.topic(), context.partition(), context.offset());
        List<Sequence<K, V>> sequences = this.nfa.matchPattern(event);
        KeyValueStore<TopicAndPartition, NFAStateValue<K, V>> store = getNFAStore();
        store.put(new TopicAndPartition(context.topic(), context.partition()), new NFAStateValue<>(this.nfa.getComputationStages(), this.nfa.getRuns(), context.offset() + 1));
        sequences.forEach(seq -> this.context.forward(null, seq));
    }
}
 
开发者ID:fhussonnois,项目名称:kafkastreams-cep,代码行数:15,代码来源:CEPProcessor.java


注:本文中的org.apache.kafka.streams.state.KeyValueStore.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。