@Test public void testDistributedMapCacheLookupService() throws InitializationException { final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class); final DistributedMapCacheLookupService service = new DistributedMapCacheLookupService(); final DistributedMapCacheClient client = new DistributedMapCacheClientImpl(); runner.addControllerService("client", client); runner.addControllerService("lookup-service", service); runner.setProperty(service, DistributedMapCacheLookupService.PROP_DISTRIBUTED_CACHE_SERVICE, "client"); runner.enableControllerService(client); runner.enableControllerService(service); runner.assertValid(service); assertThat(service, instanceOf(LookupService.class)); final Optional<String> get = service.lookup(Collections.singletonMap("key", "myKey")); assertEquals(Optional.of("myValue"), get); final Optional<String> absent = service.lookup(Collections.singletonMap("key", "absentKey")); assertEquals(EMPTY_STRING, absent); }
@Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } try { return Optional.ofNullable(cache.get(key, keySerializer, valueDeserializer)); } catch (IOException e) { getLogger().error("Error while trying to get the value from distributed map cache with key = " + key, e); return Optional.empty(); } }
DistributedMapCacheLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } try { return Optional.ofNullable(cache.get(key, keySerializer, valueDeserializer)); } catch (IOException e) { getLogger().error("Error while trying to get the value from distributed map cache with key = " + key, e); return Optional.empty(); } } }
DistributedMapCacheLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } try { return Optional.ofNullable(cache.get(key, keySerializer, valueDeserializer)); } catch (IOException e) { getLogger().error("Error while trying to get the value from distributed map cache with key = " + key, e); return Optional.empty(); } }  }
DistributedMapCacheLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } try { return Optional.ofNullable(cache.get(key, keySerializer, valueDeserializer)); } catch (IOException e) { getLogger().error("Error while trying to get the value from distributed map cache with key = " + key, e); return Optional.empty(); } }  @OnEnabled void onEnabled(final ConfigurationContext context); @Override Optional<String> lookup(final Map<String, Object> coordinates); @Override Set<String> getRequiredKeys(); }
DistributedMapCacheLookupService extends AbstractControllerService implements StringLookupService { @Override public Optional<String> lookup(final Map<String, Object> coordinates) { if (coordinates == null) { return Optional.empty(); } final String key = coordinates.get(KEY).toString(); if (key == null) { return Optional.empty(); } try { return Optional.ofNullable(cache.get(key, keySerializer, valueDeserializer)); } catch (IOException e) { getLogger().error("Error while trying to get the value from distributed map cache with key = " + key, e); return Optional.empty(); } }  @OnEnabled void onEnabled(final ConfigurationContext context); @Override Optional<String> lookup(final Map<String, Object> coordinates); @Override Set<String> getRequiredKeys(); static final PropertyDescriptor PROP_DISTRIBUTED_CACHE_SERVICE; static final PropertyDescriptor CHARACTER_ENCODING; }