Search in sources :

Example 1 with NamedMap

use of com.tangosol.net.NamedMap in project coherence-spring by coherence-community.

the class CoherenceGenericConverterTests method testNamedCacheConversion.

@Test
public void testNamedCacheConversion() {
    final Map map = this.conversionService.convert(this.mockedNamedCache, Map.class);
    assertThat(map).isSameAs(this.mockedNamedCache);
    final NamedCache namedCache = this.conversionService.convert(this.mockedNamedCache, NamedCache.class);
    assertThat(namedCache).isSameAs(this.mockedNamedCache);
    final NamedMap namedMap = this.conversionService.convert(this.mockedNamedCache, NamedMap.class);
    assertThat(namedMap).isSameAs(this.mockedNamedCache);
    final CacheMap cacheMap = this.conversionService.convert(this.mockedNamedCache, CacheMap.class);
    assertThat(cacheMap).isSameAs(this.mockedNamedCache);
    final NamedCollection namedCollection = this.conversionService.convert(this.mockedNamedCache, NamedCollection.class);
    assertThat(namedCollection).isSameAs(this.mockedNamedCache);
    final ObservableMap observableMap = this.conversionService.convert(this.mockedNamedCache, ObservableMap.class);
    assertThat(observableMap).isSameAs(this.mockedNamedCache);
    final ConcurrentMap concurrentMap = this.conversionService.convert(this.mockedNamedCache, ConcurrentMap.class);
    assertThat(concurrentMap).isSameAs(this.mockedNamedCache);
    final QueryMap queryMap = this.conversionService.convert(this.mockedNamedCache, QueryMap.class);
    assertThat(queryMap).isSameAs(this.mockedNamedCache);
    final InvocableMap invocableMap = this.conversionService.convert(this.mockedNamedCache, InvocableMap.class);
    assertThat(invocableMap).isSameAs(this.mockedNamedCache);
    final Releasable releasable = this.conversionService.convert(this.mockedNamedCache, Releasable.class);
    assertThat(releasable).isSameAs(this.mockedNamedCache);
}
Also used : InvocableMap(com.tangosol.util.InvocableMap) QueryMap(com.tangosol.util.QueryMap) NamedMap(com.tangosol.net.NamedMap) NamedCollection(com.tangosol.net.NamedCollection) ConcurrentMap(com.tangosol.util.ConcurrentMap) CacheMap(com.tangosol.net.cache.CacheMap) Releasable(com.tangosol.net.Releasable) ObservableMap(com.tangosol.util.ObservableMap) InvocableMap(com.tangosol.util.InvocableMap) CacheMap(com.tangosol.net.cache.CacheMap) AbstractKeySetBasedMap(com.tangosol.util.AbstractKeySetBasedMap) QueryMap(com.tangosol.util.QueryMap) Map(java.util.Map) ObservableMap(com.tangosol.util.ObservableMap) AbstractKeyBasedMap(com.tangosol.util.AbstractKeyBasedMap) ConcurrentMap(com.tangosol.util.ConcurrentMap) NamedMap(com.tangosol.net.NamedMap) NamedCache(com.tangosol.net.NamedCache) Test(org.junit.jupiter.api.Test)

Example 2 with NamedMap

use of com.tangosol.net.NamedMap in project micronaut-coherence by micronaut-projects.

the class CoherenceConfigurationClientTest method shouldProvidePropertySources.

@Test
public void shouldProvidePropertySources() {
    NamedMap<String, Object> applicationMap = session.getMap("application");
    applicationMap.put("hello", "app hello");
    applicationMap.put("foo", "app foo");
    applicationMap.put("my-app", "app my-app");
    applicationMap.put("test", "app test");
    applicationMap.put("backend", "app backend");
    NamedMap<String, Object> applicationFooMap = session.getMap("application-foo");
    applicationFooMap.put("bar", "app foo bar");
    NamedMap<String, Object> applicationTestMap = session.getMap("application-test");
    applicationTestMap.put("foo", "app test foo");
    NamedMap<String, Object> applicationBackendMap = session.getMap("application-backend");
    applicationBackendMap.put("foo", "app backend foo");
    applicationBackendMap.put("bar", "app backend bar");
    NamedMap<String, Object> myAppMap = session.getMap("my-app");
    myAppMap.put("hello", "my-app hello");
    myAppMap.put("foo", "my-app foo");
    NamedMap<String, Object> myAppTestMap = session.getMap("my-app-test");
    myAppTestMap.put("hello", "my-app test hello");
    NamedMap<String, Object> myAppBackendMap = session.getMap("my-app-backend");
    myAppBackendMap.put("hello", "my-app backend hello");
    myAppBackendMap.put("hello/bar", "my-app backend hello/bar");
    NamedMap<String, Object> otherAppBackendMap = session.getMap("other-app");
    otherAppBackendMap.put("hello", "other-app hello");
    ApplicationConfiguration applicationConfiguration = new ApplicationConfiguration();
    applicationConfiguration.setName("my-app");
    CoherenceClientConfiguration clientConfig = new CoherenceClientConfiguration();
    clientConfig.setEnabled(true);
    CoherenceConfigurationClient client = new CoherenceConfigurationClient(applicationConfiguration, clientConfig) {

        @Override
        protected Session buildSession(CoherenceClientConfiguration coherenceClientConfiguration) {
            Session session = mock(Session.class);
            when(session.<String, Object>getMap("application")).thenReturn(applicationMap);
            when(session.<String, Object>getMap("application-foo")).thenReturn(applicationFooMap);
            when(session.<String, Object>getMap("application-test")).thenReturn(applicationTestMap);
            when(session.<String, Object>getMap("application-backend")).thenReturn(applicationBackendMap);
            when(session.<String, Object>getMap("my-app")).thenReturn(myAppMap);
            when(session.<String, Object>getMap("my-app-test")).thenReturn(myAppTestMap);
            when(session.<String, Object>getMap("my-app-backend")).thenReturn(myAppBackendMap);
            when(session.<String, Object>getMap("other-app")).thenReturn(otherAppBackendMap);
            return session;
        }
    };
    Publisher<PropertySource> propertySourcePublisher = client.getPropertySources(context.getEnvironment());
    Iterable<PropertySource> propsIt = Flux.from(propertySourcePublisher).toIterable();
    Map<String, PropertySource> propertySources = StreamSupport.stream(propsIt.spliterator(), false).collect(Collectors.toMap(PropertySource::getName, Function.identity()));
    assertThat(propertySources.keySet().toArray(), arrayContainingInAnyOrder("application", "application-test", "application-backend", "my-app", "my-app-test", "my-app-backend"));
    PropertySource appPs = propertySources.get("application");
    assertEquals(-99, appPs.getOrder());
    Map<String, String> props = StreamSupport.stream(appPs.spliterator(), false).collect(Collectors.toMap(Function.identity(), key -> (String) appPs.get(key)));
    Map<String, String> expected = new HashMap<>();
    expected.put("hello", "app hello");
    expected.put("foo", "app foo");
    expected.put("my-app", "app my-app");
    expected.put("test", "app test");
    expected.put("backend", "app backend");
    assertEquals(expected, props);
    PropertySource appTestPs = propertySources.get("application-test");
    assertEquals(-47, appTestPs.getOrder());
    props = StreamSupport.stream(appTestPs.spliterator(), false).collect(Collectors.toMap(Function.identity(), key -> (String) appTestPs.get(key)));
    expected = new HashMap<>();
    expected.put("foo", "app test foo");
    assertEquals(expected, props);
    PropertySource appBackendPs = propertySources.get("application-backend");
    assertEquals(-45, appBackendPs.getOrder());
    props = StreamSupport.stream(appBackendPs.spliterator(), false).collect(Collectors.toMap(Function.identity(), key -> (String) appBackendPs.get(key)));
    expected = new HashMap<>();
    expected.put("foo", "app backend foo");
    expected.put("bar", "app backend bar");
    assertEquals(expected, props);
    PropertySource myAppPs = propertySources.get("my-app");
    assertEquals(-98, myAppPs.getOrder());
    props = StreamSupport.stream(myAppPs.spliterator(), false).collect(Collectors.toMap(Function.identity(), key -> (String) myAppPs.get(key)));
    expected = new HashMap<>();
    expected.put("hello", "my-app hello");
    expected.put("foo", "my-app foo");
    assertEquals(expected, props);
    PropertySource myAppTestPs = propertySources.get("my-app-test");
    assertEquals(-46, myAppTestPs.getOrder());
    props = StreamSupport.stream(myAppTestPs.spliterator(), false).collect(Collectors.toMap(Function.identity(), key -> (String) myAppTestPs.get(key)));
    expected = new HashMap<>();
    expected.put("hello", "my-app test hello");
    assertEquals(expected, props);
    PropertySource myAppBackendPs = propertySources.get("my-app-backend");
    assertEquals(-44, myAppBackendPs.getOrder());
    props = StreamSupport.stream(myAppBackendPs.spliterator(), false).collect(Collectors.toMap(Function.identity(), key -> (String) myAppBackendPs.get(key)));
    expected = new HashMap<>();
    expected.put("hello", "my-app backend hello");
    expected.put("hello/bar", "my-app backend hello/bar");
    assertEquals(expected, props);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) HashMap(java.util.HashMap) Session(com.tangosol.net.Session) Channel(io.grpc.Channel) Function(java.util.function.Function) Matchers.arrayContainingInAnyOrder(org.hamcrest.Matchers.arrayContainingInAnyOrder) Inject(javax.inject.Inject) ApplicationContext(io.micronaut.context.ApplicationContext) TestInstance(org.junit.jupiter.api.TestInstance) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) ApplicationConfiguration(io.micronaut.runtime.ApplicationConfiguration) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) NamedMap(com.tangosol.net.NamedMap) PropertySource(io.micronaut.context.env.PropertySource) Name(io.micronaut.coherence.annotation.Name) Publisher(org.reactivestreams.Publisher) GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) Mockito(org.mockito.Mockito) Flux(reactor.core.publisher.Flux) MockedStatic(org.mockito.MockedStatic) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) PropertySource(io.micronaut.context.env.PropertySource) ApplicationConfiguration(io.micronaut.runtime.ApplicationConfiguration) Session(com.tangosol.net.Session) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) Test(org.junit.jupiter.api.Test)

Example 3 with NamedMap

use of com.tangosol.net.NamedMap in project micronaut-coherence by micronaut-projects.

the class CoherenceConfigurationClient method getPropertySources.

@Override
public Publisher<PropertySource> getPropertySources(Environment environment) {
    if (!coherenceClientConfiguration.isEnabled()) {
        return Flux.empty();
    }
    Session session = buildSession(coherenceClientConfiguration);
    Map<Integer, String> keys = buildSourceNames(applicationConfiguration, environment);
    for (Map.Entry<Integer, String> entry : keys.entrySet()) {
        final Integer priority = entry.getKey();
        final String propertySource = entry.getValue();
        NamedMap<String, Object> configMap = session.getMap(propertySource);
        Flux<PropertySource> propertySourceFlux = Flux.just(PropertySource.of(propertySource, configMap, priority));
        propertySources.add(propertySourceFlux);
    }
    return Flux.merge(propertySources);
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) NamedMap(com.tangosol.net.NamedMap) Session(com.tangosol.net.Session) PropertySource(io.micronaut.context.env.PropertySource) EnvironmentPropertySource(io.micronaut.context.env.EnvironmentPropertySource)

Example 4 with NamedMap

use of com.tangosol.net.NamedMap in project coherence-spring by coherence-community.

the class CoherenceGenericConverterTests method testContinuousQueryCacheConversion.

@Test
public void testContinuousQueryCacheConversion() {
    final Map map = this.conversionService.convert(this.mockedContinuousQueryCache, Map.class);
    assertThat(map).isSameAs(this.mockedContinuousQueryCache);
    final ContinuousQueryCache continuousQueryCache = this.conversionService.convert(this.mockedContinuousQueryCache, ContinuousQueryCache.class);
    assertThat(continuousQueryCache).isSameAs(this.mockedContinuousQueryCache);
    final AbstractKeySetBasedMap abstractKeySetBasedMap = this.conversionService.convert(this.mockedContinuousQueryCache, AbstractKeySetBasedMap.class);
    assertThat(abstractKeySetBasedMap).isSameAs(this.mockedContinuousQueryCache);
    final AbstractKeyBasedMap abstractKeyBasedMap = this.conversionService.convert(this.mockedContinuousQueryCache, AbstractKeyBasedMap.class);
    assertThat(abstractKeyBasedMap).isSameAs(this.mockedContinuousQueryCache);
    final NamedCache namedCache = this.conversionService.convert(this.mockedContinuousQueryCache, NamedCache.class);
    assertThat(namedCache).isSameAs(this.mockedContinuousQueryCache);
    final NamedMap namedMap = this.conversionService.convert(this.mockedContinuousQueryCache, NamedMap.class);
    assertThat(namedMap).isSameAs(this.mockedContinuousQueryCache);
    final CacheMap cacheMap = this.conversionService.convert(this.mockedContinuousQueryCache, CacheMap.class);
    assertThat(cacheMap).isSameAs(this.mockedContinuousQueryCache);
    final NamedCollection namedCollection = this.conversionService.convert(this.mockedContinuousQueryCache, NamedCollection.class);
    assertThat(namedCollection).isSameAs(this.mockedContinuousQueryCache);
    final ObservableMap observableMap = this.conversionService.convert(this.mockedContinuousQueryCache, ObservableMap.class);
    assertThat(observableMap).isSameAs(this.mockedContinuousQueryCache);
    final ConcurrentMap concurrentMap = this.conversionService.convert(this.mockedContinuousQueryCache, ConcurrentMap.class);
    assertThat(concurrentMap).isSameAs(this.mockedContinuousQueryCache);
    final QueryMap queryMap = this.conversionService.convert(this.mockedContinuousQueryCache, QueryMap.class);
    assertThat(queryMap).isSameAs(this.mockedContinuousQueryCache);
    final InvocableMap invocableMap = this.conversionService.convert(this.mockedContinuousQueryCache, InvocableMap.class);
    assertThat(invocableMap).isSameAs(this.mockedContinuousQueryCache);
    final Releasable releasable = this.conversionService.convert(this.mockedContinuousQueryCache, Releasable.class);
    assertThat(releasable).isSameAs(this.mockedContinuousQueryCache);
}
Also used : InvocableMap(com.tangosol.util.InvocableMap) QueryMap(com.tangosol.util.QueryMap) AbstractKeyBasedMap(com.tangosol.util.AbstractKeyBasedMap) ConcurrentMap(com.tangosol.util.ConcurrentMap) NamedCache(com.tangosol.net.NamedCache) AbstractKeySetBasedMap(com.tangosol.util.AbstractKeySetBasedMap) NamedMap(com.tangosol.net.NamedMap) NamedCollection(com.tangosol.net.NamedCollection) ContinuousQueryCache(com.tangosol.net.cache.ContinuousQueryCache) CacheMap(com.tangosol.net.cache.CacheMap) Releasable(com.tangosol.net.Releasable) ObservableMap(com.tangosol.util.ObservableMap) InvocableMap(com.tangosol.util.InvocableMap) CacheMap(com.tangosol.net.cache.CacheMap) AbstractKeySetBasedMap(com.tangosol.util.AbstractKeySetBasedMap) QueryMap(com.tangosol.util.QueryMap) Map(java.util.Map) ObservableMap(com.tangosol.util.ObservableMap) AbstractKeyBasedMap(com.tangosol.util.AbstractKeyBasedMap) ConcurrentMap(com.tangosol.util.ConcurrentMap) NamedMap(com.tangosol.net.NamedMap) Test(org.junit.jupiter.api.Test)

Aggregations

NamedMap (com.tangosol.net.NamedMap)4 Map (java.util.Map)4 Test (org.junit.jupiter.api.Test)3 NamedCache (com.tangosol.net.NamedCache)2 NamedCollection (com.tangosol.net.NamedCollection)2 Releasable (com.tangosol.net.Releasable)2 Session (com.tangosol.net.Session)2 CacheMap (com.tangosol.net.cache.CacheMap)2 AbstractKeyBasedMap (com.tangosol.util.AbstractKeyBasedMap)2 AbstractKeySetBasedMap (com.tangosol.util.AbstractKeySetBasedMap)2 ConcurrentMap (com.tangosol.util.ConcurrentMap)2 InvocableMap (com.tangosol.util.InvocableMap)2 ObservableMap (com.tangosol.util.ObservableMap)2 QueryMap (com.tangosol.util.QueryMap)2 PropertySource (io.micronaut.context.env.PropertySource)2 HashMap (java.util.HashMap)2 GrpcSessionConfiguration (com.oracle.coherence.client.GrpcSessionConfiguration)1 ContinuousQueryCache (com.tangosol.net.cache.ContinuousQueryCache)1 Channel (io.grpc.Channel)1 ManagedChannelBuilder (io.grpc.ManagedChannelBuilder)1