當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。