@Test public void testGet() throws Exception { final CouchbaseMapCacheClient client = new CouchbaseMapCacheClient(); final CouchbaseClusterControllerService couchbaseService = mock(CouchbaseClusterControllerService.class); final Bucket bucket = mock(Bucket.class); final MockControllerServiceInitializationContext serviceInitializationContext = new MockControllerServiceInitializationContext(couchbaseService, "couchbaseService"); final Map<PropertyDescriptor, String> properties = new HashMap<>(); properties.put(COUCHBASE_CLUSTER_SERVICE, "couchbaseService"); properties.put(BUCKET_NAME, "bucketA"); final ByteBuf contents = Unpooled.copiedBuffer("value".getBytes(StandardCharsets.UTF_8)); final BinaryDocument doc = BinaryDocument.create("key", contents); when(couchbaseService.openBucket(eq("bucketA"))).thenReturn(bucket); when(bucket.get(any(BinaryDocument.class))).thenReturn(doc); final MockConfigurationContext context = new MockConfigurationContext(properties, serviceInitializationContext); client.configure(context); final String cacheEntry = client.get("key", stringSerializer, stringDeserializer); assertEquals("value", cacheEntry); }
@Override public <K, V> V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException { final String docId = toDocumentId(key, keySerializer); final BinaryDocument doc = bucket.get(BinaryDocument.create(docId)); return deserialize(doc, valueDeserializer); }
CouchbaseMapCacheClient extends AbstractControllerService implements AtomicDistributedMapCacheClient<Long> { @Override public <K, V> V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException { final String docId = toDocumentId(key, keySerializer); final BinaryDocument doc = bucket.get(BinaryDocument.create(docId)); return deserialize(doc, valueDeserializer); } }
CouchbaseMapCacheClient extends AbstractControllerService implements AtomicDistributedMapCacheClient<Long> { @Override public <K, V> V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException { final String docId = toDocumentId(key, keySerializer); final BinaryDocument doc = bucket.get(BinaryDocument.create(docId)); return deserialize(doc, valueDeserializer); }  }
CouchbaseMapCacheClient extends AbstractControllerService implements AtomicDistributedMapCacheClient<Long> { @Override public <K, V> V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException { final String docId = toDocumentId(key, keySerializer); final BinaryDocument doc = bucket.get(BinaryDocument.create(docId)); return deserialize(doc, valueDeserializer); }  @OnEnabled void configure(final ConfigurationContext context); @Override boolean putIfAbsent(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer); @Override AtomicCacheEntry<K, V, Long> fetch(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer); @Override V getAndPutIfAbsent(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer, Deserializer<V> valueDeserializer); @Override boolean replace(AtomicCacheEntry<K, V, Long> entry, Serializer<K> keySerializer, Serializer<V> valueSerializer); @Override boolean containsKey(K key, Serializer<K> keySerializer); @Override void put(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer); @Override V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer); @Override void close(); @Override boolean remove(K key, Serializer<K> serializer); @Override long removeByPattern(String regex); }
CouchbaseMapCacheClient extends AbstractControllerService implements AtomicDistributedMapCacheClient<Long> { @Override public <K, V> V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException { final String docId = toDocumentId(key, keySerializer); final BinaryDocument doc = bucket.get(BinaryDocument.create(docId)); return deserialize(doc, valueDeserializer); }  @OnEnabled void configure(final ConfigurationContext context); @Override boolean putIfAbsent(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer); @Override AtomicCacheEntry<K, V, Long> fetch(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer); @Override V getAndPutIfAbsent(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer, Deserializer<V> valueDeserializer); @Override boolean replace(AtomicCacheEntry<K, V, Long> entry, Serializer<K> keySerializer, Serializer<V> valueSerializer); @Override boolean containsKey(K key, Serializer<K> keySerializer); @Override void put(K key, V value, Serializer<K> keySerializer, Serializer<V> valueSerializer); @Override V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer); @Override void close(); @Override boolean remove(K key, Serializer<K> serializer); @Override long removeByPattern(String regex);  }