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


Java Cache类代码示例

本文整理汇总了Java中org.apache.kafka.common.cache.Cache的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Cache类属于org.apache.kafka.common.cache包,在下文中一共展示了Cache类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCacheSchemaToConnectConversion

import org.apache.kafka.common.cache.Cache; //导入依赖的package包/类
@Test
public void testCacheSchemaToConnectConversion() {
    Cache<JsonNode, Schema> cache = Whitebox.getInternalState(converter, "toConnectSchemaCache");
    assertEquals(0, cache.size());

    converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"boolean\" }, \"payload\": true }".getBytes());
    assertEquals(1, cache.size());

    converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"boolean\" }, \"payload\": true }".getBytes());
    assertEquals(1, cache.size());

    // Different schema should also get cached
    converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"boolean\", \"optional\": true }, \"payload\": true }".getBytes());
    assertEquals(2, cache.size());

    // Even equivalent, but different JSON encoding of schema, should get different cache entry
    converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"boolean\", \"optional\": false }, \"payload\": true }".getBytes());
    assertEquals(3, cache.size());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:JsonConverterTest.java

示例2: testCacheSchemaToJsonConversion

import org.apache.kafka.common.cache.Cache; //导入依赖的package包/类
@Test
public void testCacheSchemaToJsonConversion() {
    Cache<Schema, ObjectNode> cache = Whitebox.getInternalState(converter, "fromConnectSchemaCache");
    assertEquals(0, cache.size());

    // Repeated conversion of the same schema, even if the schema object is different should return the same Java
    // object
    converter.fromConnectData(TOPIC, SchemaBuilder.bool().build(), true);
    assertEquals(1, cache.size());

    converter.fromConnectData(TOPIC, SchemaBuilder.bool().build(), true);
    assertEquals(1, cache.size());

    // Validate that a similar, but different schema correctly returns a different schema.
    converter.fromConnectData(TOPIC, SchemaBuilder.bool().optional().build(), true);
    assertEquals(2, cache.size());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:JsonConverterTest.java


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