Search in sources :

Example 1 with GrpcSessionConfiguration

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));
    }
}
Also used : GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) Channel(io.grpc.Channel) 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 2 with GrpcSessionConfiguration

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));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Coherence(com.tangosol.net.Coherence) SessionConfigurationProvider(io.micronaut.coherence.SessionConfigurationProvider) GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) Qualifiers(io.micronaut.inject.qualifiers.Qualifiers) Channel(io.grpc.Channel) Collectors(java.util.stream.Collectors) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) ApplicationContext(io.micronaut.context.ApplicationContext) AssertionFailedError(org.opentest4j.AssertionFailedError) Map(java.util.Map) Serializer(com.tangosol.io.Serializer) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest) SessionConfiguration(com.tangosol.net.SessionConfiguration) GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) Optional(java.util.Optional) Channel(io.grpc.Channel) GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) SessionConfiguration(com.tangosol.net.SessionConfiguration) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Example 3 with GrpcSessionConfiguration

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.");
    });
}
Also used : GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) Session(com.tangosol.net.Session)

Example 4 with GrpcSessionConfiguration

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"));
}
Also used : GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) Channel(io.grpc.Channel) Session(com.tangosol.net.Session)

Aggregations

GrpcSessionConfiguration (com.oracle.coherence.client.GrpcSessionConfiguration)4 Session (com.tangosol.net.Session)3 Channel (io.grpc.Channel)3 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)2 Test (org.junit.jupiter.api.Test)2 Serializer (com.tangosol.io.Serializer)1 Coherence (com.tangosol.net.Coherence)1 SessionConfiguration (com.tangosol.net.SessionConfiguration)1 SessionConfigurationProvider (io.micronaut.coherence.SessionConfigurationProvider)1 ApplicationContext (io.micronaut.context.ApplicationContext)1 Qualifiers (io.micronaut.inject.qualifiers.Qualifiers)1 ApplicationConfiguration (io.micronaut.runtime.ApplicationConfiguration)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 AssertionFailedError (org.opentest4j.AssertionFailedError)1