use of com.oracle.coherence.client.GrpcSessionConfiguration 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.oracle.coherence.client.GrpcSessionConfiguration in project micronaut-coherence by micronaut-projects.
the class GrpcSessionConfigurationBeanTest method shouldConfigureSessions.
@Test
void shouldConfigureSessions() {
Map<String, SessionConfiguration> beans = ctx.getBeansOfType(GrpcSessionConfigurationBean.class).stream().map(SessionConfigurationProvider::getConfiguration).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toMap(SessionConfiguration::getName, cfg -> cfg));
Optional<Channel> optional = ctx.findBean(Channel.class, Qualifiers.byName("default"));
assertThat(optional.isPresent(), is(true));
assertThat(beans.size(), is(2));
GrpcSessionConfiguration beanBar = (GrpcSessionConfiguration) beans.get("bar");
assertThat(beanBar, is(notNullValue()));
assertThat(beanBar.getName(), is("bar"));
assertThat(beanBar.getScopeName(), is(Coherence.DEFAULT_SCOPE));
assertThat(beanBar.getSerializer().orElseThrow(AssertionFailedError::new), notNullValue());
assertThat(beanBar.getFormat().orElseThrow(AssertionFailedError::new), is("java"));
assertThat(beanBar.enableTracing(), is(true));
GrpcSessionConfiguration beanBaz = (GrpcSessionConfiguration) beans.get("baz");
assertThat(beanBaz, is(notNullValue()));
assertThat(beanBaz.getName(), is("baz"));
assertThat(beanBaz.getScopeName(), is("scoped"));
assertThat(beanBaz.getSerializer().isPresent(), is(false));
assertThat(beanBaz.getFormat().orElseThrow(AssertionFailedError::new), is("binary"));
assertThat(beanBaz.enableTracing(), is(false));
}
use of com.oracle.coherence.client.GrpcSessionConfiguration in project coherence-spring by coherence-community.
the class CoherenceGrpcClient method buildSession.
/**
* Builds Coherence session.
* @param grpcChannel mMust not be null
* @param coherenceConfigClientProperties must not be null
* @return a Coherence Session
*/
protected Session buildSession(Channel grpcChannel, CoherenceConfigClientProperties coherenceConfigClientProperties) {
Assert.notNull(grpcChannel, "grpcChannel must not be null");
Assert.notNull(coherenceConfigClientProperties, "coherenceConfigClientProperties must not be null");
final GrpcSessionConfiguration.Builder builder = GrpcSessionConfiguration.builder(grpcChannel);
if (StringUtils.hasText(coherenceConfigClientProperties.getSessionName())) {
builder.named(coherenceConfigClientProperties.getSessionName());
}
if (StringUtils.hasText(coherenceConfigClientProperties.getScopeName())) {
builder.withScopeName(coherenceConfigClientProperties.getScopeName());
}
final GrpcSessionConfiguration grpcSessionConfiguration = builder.build();
final Optional<Session> optional = Session.create(grpcSessionConfiguration);
return optional.orElseGet(() -> {
throw new IllegalStateException("Unable to create session.");
});
}
use of com.oracle.coherence.client.GrpcSessionConfiguration in project micronaut-coherence by micronaut-projects.
the class CoherenceConfigurationClient method buildSession.
/**
* Builds Coherence session.
*
* @param coherenceClientConfiguration configuration
* @return Coherence session
*/
protected Session buildSession(CoherenceClientConfiguration coherenceClientConfiguration) {
Channel channel = buildChannel(coherenceClientConfiguration);
GrpcSessionConfiguration.Builder builder = GrpcSessionConfiguration.builder(channel);
GrpcSessionConfiguration grpcSessionConfiguration = builder.build();
Optional<Session> optional = Session.create(grpcSessionConfiguration);
return optional.orElseThrow(() -> new IllegalStateException("Unable to create session"));
}
Aggregations