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


Java Bytes.wrap方法代码示例

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


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

示例1: shouldOnlyIterateOverSegmentsInRange

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Test
public void shouldOnlyIterateOverSegmentsInRange() throws Exception {
    iterator = new SegmentIterator(Arrays.asList(segmentOne, segmentTwo).iterator(),
            hasNextCondition,
            Bytes.wrap("a".getBytes()),
            Bytes.wrap("b".getBytes()));

    assertTrue(iterator.hasNext());
    assertEquals("a", new String(iterator.peekNextKey().get()));
    assertEquals(KeyValue.pair("a", "1"), toStringKeyValue(iterator.next()));

    assertTrue(iterator.hasNext());
    assertEquals("b", new String(iterator.peekNextKey().get()));
    assertEquals(KeyValue.pair("b", "2"), toStringKeyValue(iterator.next()));

    assertFalse(iterator.hasNext());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:SegmentIteratorTest.java

示例2: lowerRange

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
static Bytes lowerRange(Bytes key, byte[] minSuffix) {
    final byte[] bytes = key.get();
    ByteBuffer rangeStart = ByteBuffer.allocate(bytes.length + minSuffix.length);
    // any key in the range would start at least with the given prefix to be
    // in the range, and have at least SUFFIX_SIZE number of trailing zero bytes.

    // unless there is a maximum key length, you can keep appending more zero bytes
    // to keyFrom to create a key that will match the range, yet that would precede
    // WindowStoreUtils.toBinaryKey(keyFrom, from, 0) in byte order
    return Bytes.wrap(
        rangeStart
            .put(bytes)
            .put(minSuffix)
            .array()
    );
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:17,代码来源:OrderedBytes.java

示例3: shouldIterateOverAllSegments

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Test
public void shouldIterateOverAllSegments() throws Exception {
    iterator = new SegmentIterator(Arrays.asList(segmentOne, segmentTwo).iterator(),
            hasNextCondition,
            Bytes.wrap("a".getBytes()),
            Bytes.wrap("z".getBytes()));

    assertTrue(iterator.hasNext());
    assertEquals("a", new String(iterator.peekNextKey().get()));
    assertEquals(KeyValue.pair("a", "1"), toStringKeyValue(iterator.next()));

    assertTrue(iterator.hasNext());
    assertEquals("b", new String(iterator.peekNextKey().get()));
    assertEquals(KeyValue.pair("b", "2"), toStringKeyValue(iterator.next()));

    assertTrue(iterator.hasNext());
    assertEquals("c", new String(iterator.peekNextKey().get()));
    assertEquals(KeyValue.pair("c", "3"), toStringKeyValue(iterator.next()));

    assertTrue(iterator.hasNext());
    assertEquals("d", new String(iterator.peekNextKey().get()));
    assertEquals(KeyValue.pair("d", "4"), toStringKeyValue(iterator.next()));

    assertFalse(iterator.hasNext());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:SegmentIteratorTest.java

示例4: fetch

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Override
public synchronized WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) {
    // since this function may not access the underlying inner store, we need to validate
    // if store is open outside as well.
    validateStoreOpen();

    final Bytes keyBytes = Bytes.wrap(serdes.rawKey(key));
    final WindowStoreIterator<byte[]> underlyingIterator = underlying.fetch(keyBytes, timeFrom, timeTo);

    final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(keyBytes, timeFrom));
    final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(keyBytes, timeTo));
    final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(name, cacheKeyFrom, cacheKeyTo);

    final HasNextCondition hasNextCondition = keySchema.hasNextCondition(keyBytes,
                                                                         keyBytes,
                                                                         timeFrom,
                                                                         timeTo);
    final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(
        cacheIterator, hasNextCondition, cacheFunction
    );

    return new MergedSortedCacheWindowStoreIterator<>(filteredCacheIterator,
                                                      underlyingIterator,
                                                      new StateSerdes<>(serdes.topic(), Serdes.Long(), serdes.valueSerde()));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:26,代码来源:CachingWindowStore.java

示例5: findSessions

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
public KeyValueIterator<Windowed<K>, AGG> findSessions(final K key,
                                                       final long earliestSessionEndTime,
                                                       final long latestSessionStartTime) {
    validateStoreOpen();
    final Bytes binarySessionId = Bytes.wrap(serdes.rawKey(key));

    final Bytes cacheKeyFrom = cacheFunction.cacheKey(keySchema.lowerRangeFixedSize(binarySessionId, earliestSessionEndTime));
    final Bytes cacheKeyTo = cacheFunction.cacheKey(keySchema.upperRangeFixedSize(binarySessionId, latestSessionStartTime));
    final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, cacheKeyFrom, cacheKeyTo);

    final KeyValueIterator<Windowed<Bytes>, byte[]> storeIterator = bytesStore.findSessions(
        binarySessionId, earliestSessionEndTime, latestSessionStartTime
    );
    final HasNextCondition hasNextCondition = keySchema.hasNextCondition(binarySessionId,
                                                                         binarySessionId,
                                                                         earliestSessionEndTime,
                                                                         latestSessionStartTime);
    final PeekingKeyValueIterator<Bytes, LRUCacheEntry> filteredCacheIterator = new FilteredCacheIterator(cacheIterator, hasNextCondition, cacheFunction);
    return new MergedSortedCacheSessionStoreIterator<>(filteredCacheIterator, storeIterator, serdes, cacheFunction);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:21,代码来源:CachingSessionStore.java

示例6: shouldIterateOverRange

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Test
public void shouldIterateOverRange() throws Exception {
    final byte[][] bytes = {{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}};
    for (int i = 0; i < bytes.length; i += 2) {
        store.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 = new DelegatingPeekingKeyValueIterator<>("store", store.range(from, to));
    final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(namespace, from, to);

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

示例7: shouldIterateCacheAndStoreKeyRange

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Test
public void shouldIterateCacheAndStoreKeyRange() throws Exception {
    final Bytes key = Bytes.wrap("1" .getBytes());
    underlying.put(WindowStoreUtils.toBinaryKey(key, DEFAULT_TIMESTAMP, 0, WindowStoreUtils.getInnerStateSerde("app-id")), "a".getBytes());
    cachingStore.put("1", "b", DEFAULT_TIMESTAMP + WINDOW_SIZE);

    final KeyValueIterator<Windowed<String>, String> fetchRange =
        cachingStore.fetch("1", "2", DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE);
    assertEquals(KeyValue.pair(new Windowed<>("1", new TimeWindow(DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE)), "a"), fetchRange.next());
    assertEquals(KeyValue.pair(new Windowed<>("1", new TimeWindow(DEFAULT_TIMESTAMP + WINDOW_SIZE, DEFAULT_TIMESTAMP + WINDOW_SIZE + WINDOW_SIZE)), "b"), fetchRange.next());
    assertFalse(fetchRange.hasNext());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:13,代码来源:CachingWindowStoreTest.java

示例8: cacheKey

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Override
public Bytes cacheKey(Bytes key) {
    final byte[] keyBytes = key.get();
    ByteBuffer buf = ByteBuffer.allocate(SEGMENT_ID_BYTES + keyBytes.length);
    buf.putLong(segmentId(key)).put(keyBytes);
    return Bytes.wrap(buf.array());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:8,代码来源:SegmentedCacheFunction.java

示例9: toBinaryKey

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
static Bytes toBinaryKey(byte[] serializedKey, final long timestamp, final int seqnum) {
    ByteBuffer buf = ByteBuffer.allocate(serializedKey.length + TIMESTAMP_SIZE + SEQNUM_SIZE);
    buf.put(serializedKey);
    buf.putLong(timestamp);
    buf.putInt(seqnum);

    return Bytes.wrap(buf.array());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:9,代码来源:WindowStoreUtils.java

示例10: shouldFetchAndIterateOverExactBinaryKeys

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void shouldFetchAndIterateOverExactBinaryKeys() throws Exception {
    final RocksDBWindowStoreSupplier<Bytes, String> supplier =
            new RocksDBWindowStoreSupplier<>(
                    "window",
                    60000, 2,
                    true,
                    Serdes.Bytes(),
                    Serdes.String(),
                    60000,
                    true,
                    Collections.<String, String>emptyMap(),
                    false);

    windowStore = supplier.get();
    windowStore.init(context, windowStore);

    final Bytes key1 = Bytes.wrap(new byte[]{0});
    final Bytes key2 = Bytes.wrap(new byte[]{0, 0});
    final Bytes key3 = Bytes.wrap(new byte[]{0, 0, 0});
    windowStore.put(key1, "1", 0);
    windowStore.put(key2, "2", 0);
    windowStore.put(key3, "3", 0);
    windowStore.put(key1, "4", 1);
    windowStore.put(key2, "5", 1);
    windowStore.put(key3, "6", 59999);
    windowStore.put(key1, "7", 59999);
    windowStore.put(key2, "8", 59999);
    windowStore.put(key3, "9", 59999);

    final List expectedKey1 = Utils.mkList("1", "4", "7");
    assertThat(toList(windowStore.fetch(key1, 0, Long.MAX_VALUE)), equalTo(expectedKey1));
    final List expectedKey2 = Utils.mkList("2", "5", "8");
    assertThat(toList(windowStore.fetch(key2, 0, Long.MAX_VALUE)), equalTo(expectedKey2));
    final List expectedKey3 = Utils.mkList("3", "6", "9");
    assertThat(toList(windowStore.fetch(key3, 0, Long.MAX_VALUE)), equalTo(expectedKey3));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:39,代码来源:RocksDBWindowStoreTest.java

示例11: shouldIterateCacheAndStore

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Test
public void shouldIterateCacheAndStore() throws Exception {
    final Bytes key = Bytes.wrap("1" .getBytes());
    underlying.put(WindowStoreUtils.toBinaryKey(key, DEFAULT_TIMESTAMP, 0, WindowStoreUtils.getInnerStateSerde("app-id")), "a".getBytes());
    cachingStore.put("1", "b", DEFAULT_TIMESTAMP + WINDOW_SIZE);
    final WindowStoreIterator<String> fetch = cachingStore.fetch("1", DEFAULT_TIMESTAMP, DEFAULT_TIMESTAMP + WINDOW_SIZE);
    assertEquals(KeyValue.pair(DEFAULT_TIMESTAMP, "a"), fetch.next());
    assertEquals(KeyValue.pair(DEFAULT_TIMESTAMP + WINDOW_SIZE, "b"), fetch.next());
    assertFalse(fetch.hasNext());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:11,代码来源:CachingWindowStoreTest.java

示例12: shouldNotClashWithOverlappingNames

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Test
public void shouldNotClashWithOverlappingNames() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
    final Bytes nameByte = Bytes.wrap(new byte[]{0});
    final Bytes name1Byte = Bytes.wrap(new byte[]{1});
    cache.put("name", nameByte, dirtyEntry(nameByte.get()));
    cache.put("name1", nameByte, dirtyEntry(name1Byte.get()));

    assertArrayEquals(nameByte.get(), cache.get("name", nameByte).value);
    assertArrayEquals(name1Byte.get(), cache.get("name1", nameByte).value);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:12,代码来源:ThreadCacheTest.java

示例13: range

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Override
public KeyValueIterator<K, V> range(final K from, final K to) {
    validateStoreOpen();
    final Bytes origFrom = Bytes.wrap(serdes.rawKey(from));
    final Bytes origTo = Bytes.wrap(serdes.rawKey(to));
    final KeyValueIterator<Bytes, byte[]> storeIterator = underlying.range(origFrom, origTo);
    final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(cacheName, origFrom, origTo);
    return new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:CachingKeyValueStore.java

示例14: shouldPeekNextKey

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Test
public void shouldPeekNextKey() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
    final Bytes theByte = Bytes.wrap(new byte[]{0});
    final String namespace = "streams";
    cache.put(namespace, theByte, dirtyEntry(theByte.get()));
    final ThreadCache.MemoryLRUCacheBytesIterator iterator = cache.range(namespace, theByte, Bytes.wrap(new byte[]{1}));
    assertEquals(theByte, iterator.peekNextKey());
    assertEquals(theByte, iterator.peekNextKey());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:11,代码来源:ThreadCacheTest.java

示例15: shouldThrowNoSuchElementOnPeekNextKeyIfNoNext

import org.apache.kafka.common.utils.Bytes; //导入方法依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void shouldThrowNoSuchElementOnPeekNextKeyIfNoNext() throws Exception {
    iterator = new SegmentIterator(Arrays.asList(segmentOne, segmentTwo).iterator(),
            hasNextCondition,
            Bytes.wrap("f".getBytes()),
            Bytes.wrap("h".getBytes()));

    iterator.peekNextKey();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:SegmentIteratorTest.java


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