use of com.tangosol.net.Session 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);
}
use of com.tangosol.net.Session in project micronaut-coherence by micronaut-projects.
the class CoherenceConfigurationClientTest method shouldCreateSession.
@Test
public void shouldCreateSession() {
ApplicationConfiguration applicationConfiguration = mock(ApplicationConfiguration.class);
CoherenceClientConfiguration coherenceClientConfiguration = new CoherenceClientConfiguration();
CoherenceConfigurationClient client = new CoherenceConfigurationClient(applicationConfiguration, coherenceClientConfiguration);
GrpcSessionConfiguration.Builder builder = mock(GrpcSessionConfiguration.Builder.class);
GrpcSessionConfiguration grpcSessionConfiguration = mock(GrpcSessionConfiguration.class);
when(builder.build()).thenReturn(grpcSessionConfiguration);
Session session = mock(Session.class);
try (MockedStatic<GrpcSessionConfiguration> grpcSessionConfigStaticMock = Mockito.mockStatic(GrpcSessionConfiguration.class);
MockedStatic<Session> sessionStaticMock = Mockito.mockStatic(Session.class)) {
grpcSessionConfigStaticMock.when(() -> GrpcSessionConfiguration.builder(any(Channel.class))).thenReturn(builder);
sessionStaticMock.when(() -> Session.create(eq(grpcSessionConfiguration))).thenReturn(Optional.of(session));
Session s = client.buildSession(coherenceClientConfiguration);
assertEquals(session, s);
verify(builder).build();
sessionStaticMock.verify(() -> Session.create(grpcSessionConfiguration), times(1));
}
}
use of com.tangosol.net.Session in project micronaut-coherence by micronaut-projects.
the class GrpcProxyTest method shouldHaveGrpcSession.
@Test
public void shouldHaveGrpcSession() {
Coherence coherence = context.findBean(Coherence.class).orElseThrow(() -> new AssertionError("Could not find Coherence bean"));
Session session = coherence.getSession("grpc-client");
assertThat(session, is(instanceOf(GrpcRemoteSession.class)));
NamedCache<String, String> cache = session.getCache("test");
cache.put("Key-1", "Value-1");
assertThat(cache.get("Key-1"), is("Value-1"));
}
use of com.tangosol.net.Session 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);
}
use of com.tangosol.net.Session in project coherence-hibernate by coherence-community.
the class AfterInsertProcessorTests method insertValue.
@Test
public void insertValue() throws ExecutionException, InterruptedException {
// Create the Coherence instance from the configuration
final Coherence coherence = Coherence.clusterMember();
coherence.start().get();
final Session coherenceSession = coherence.getSession();
final NamedCache<Long, CoherenceRegionValue> fooCache = coherenceSession.getCache("foo");
assertThat(fooCache.size()).isEqualTo(0);
final CoherenceRegionValue coherenceRegionValue = new CoherenceRegionValue("bar", 1, Instant.now().toEpochMilli());
final AfterInsertProcessor afterInsertProcessor = new AfterInsertProcessor(coherenceRegionValue);
Boolean result = fooCache.<Boolean>invoke(1L, afterInsertProcessor);
assertThat(result).isTrue();
assertThat(fooCache.size()).isEqualTo(1);
assertThat(fooCache.get(1L)).isEqualTo(coherenceRegionValue);
coherence.close();
}
Aggregations