Search in sources :

Example 1 with SessionConfiguration

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

the class CoherencePropertiesTests method testCoherenceConfiguration.

@Test
void testCoherenceConfiguration() {
    final List<ServerSessionConfigurationBean> serverSessions = this.coherenceProperties.getSessions().getServer();
    assertThat(serverSessions.get(0).getConfiguration()).isNotNull();
    assertThat(serverSessions.get(1).getConfiguration()).isNotNull();
    assertThat(serverSessions.get(2).getConfiguration()).isNotNull();
    final SessionConfiguration sessionConfiguration1 = serverSessions.get(0).getConfiguration().get();
    final SessionConfiguration sessionConfiguration2 = serverSessions.get(1).getConfiguration().get();
    final SessionConfiguration sessionConfiguration3 = serverSessions.get(2).getConfiguration().get();
    assertThat(sessionConfiguration1.getName()).isEqualTo(Coherence.DEFAULT_NAME);
    validateConfigUri("coherence-cache-config.xml", sessionConfiguration1);
    assertThat(sessionConfiguration1.getScopeName()).isEqualTo("fooscope");
    assertThat(sessionConfiguration1.getPriority()).isEqualTo(1);
    assertThat(sessionConfiguration2.getName()).isEqualTo("test");
    validateConfigUri("test-coherence-config.xml", sessionConfiguration2);
    assertThat(sessionConfiguration2.getScopeName()).isEqualTo("barscope");
    assertThat(sessionConfiguration2.getPriority()).isEqualTo(2);
    assertThat(sessionConfiguration3.getName()).isEqualTo(Coherence.DEFAULT_NAME);
    validateConfigUri("test-coherence-config.xml", sessionConfiguration3);
    assertThat(sessionConfiguration3.getScopeName()).isEqualTo("myscope");
    assertThat(sessionConfiguration3.getPriority()).isEqualTo(SessionConfiguration.DEFAULT_PRIORITY);
}
Also used : ServerSessionConfigurationBean(com.oracle.coherence.spring.configuration.session.ServerSessionConfigurationBean) SessionConfiguration(com.tangosol.net.SessionConfiguration) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SessionConfiguration

use of com.tangosol.net.SessionConfiguration 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 SessionConfiguration

use of com.tangosol.net.SessionConfiguration in project coherence-hibernate by coherence-community.

the class CoherenceRegionFactory method prepareCoherenceSessionIfNeeded.

private void prepareCoherenceSessionIfNeeded(CoherenceHibernateProperties coherenceHibernateProperties) {
    if (this.coherenceSession == null) {
        final SessionConfiguration.Builder sessionConfigurationBuilder = SessionConfiguration.builder();
        if (coherenceHibernateProperties.getSessionName() != null) {
            sessionConfigurationBuilder.named(coherenceHibernateProperties.getSessionName());
        }
        sessionConfigurationBuilder.withConfigUri(coherenceHibernateProperties.getCacheConfigFilePath());
        final SessionConfiguration sessionConfiguration = sessionConfigurationBuilder.build();
        // GrpcSessionConfiguration.Builder
        final CoherenceConfiguration coherenceConfiguration = CoherenceConfiguration.builder().withSession(sessionConfiguration).build();
        final SessionType sessionType = coherenceHibernateProperties.getSessionType();
        this.coherence = this.createCoherenceInstance(sessionType, coherenceConfiguration);
        try {
            coherence.start().get();
        } catch (InterruptedException | ExecutionException ex) {
            throw new IllegalStateException("Unable to start Coherence instance.", ex);
        }
        if (coherenceHibernateProperties.getSessionName() != null) {
            this.setCoherenceSession(coherence.getSession(coherenceHibernateProperties.getSessionName()));
        } else {
            this.setCoherenceSession(coherence.getSession());
        }
    }
    this.coherenceSession.activate();
}
Also used : SessionType(com.oracle.coherence.hibernate.cache.v53.configuration.session.SessionType) ExecutionException(java.util.concurrent.ExecutionException) CoherenceConfiguration(com.tangosol.net.CoherenceConfiguration) SessionConfiguration(com.tangosol.net.SessionConfiguration)

Example 4 with SessionConfiguration

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

the class CoherenceServerJunitExtension method beforeAll.

@Override
public void beforeAll(ExtensionContext context) throws Exception {
    System.setProperty("coherence.log", "slf4j");
    if (logger.isInfoEnabled()) {
        logger.info("JunitExtension - Starting up Coherence...");
    }
    final SessionConfiguration.Builder sessionConfigurationBuilder = (SessionConfiguration.Builder) getFromTestClassloader(SessionConfiguration.class).getMethod("builder").invoke(null);
    final SessionConfiguration sessionConfiguration = sessionConfigurationBuilder.withConfigUri(this.configUri).build();
    final CoherenceConfiguration.Builder coherenceBuilder = (CoherenceConfiguration.Builder) getFromTestClassloader(CoherenceConfiguration.class).getMethod("builder").invoke(null);
    final CoherenceConfiguration cfg = coherenceBuilder.withSessions(sessionConfiguration).build();
    this.coherence = (Coherence) getFromTestClassloader(Coherence.class).getMethod("clusterMember", CoherenceConfiguration.class).invoke(null, cfg);
    this.coherence.start().join();
}
Also used : CoherenceConfiguration(com.tangosol.net.CoherenceConfiguration) SessionConfiguration(com.tangosol.net.SessionConfiguration)

Example 5 with SessionConfiguration

use of com.tangosol.net.SessionConfiguration in project coherence-hibernate by coherence-community.

the class CoherenceServerApplication method coherenceServer.

@Bean(destroyMethod = "close")
public Coherence coherenceServer() {
    final SessionConfiguration sessionConfiguration = SessionConfiguration.builder().withConfigUri("coherence-cache-config.xml").build();
    final CoherenceConfiguration cfg = CoherenceConfiguration.builder().withSessions(sessionConfiguration).build();
    final Coherence coherence = Coherence.clusterMember(cfg);
    coherence.start().join();
    return coherence;
}
Also used : Coherence(com.tangosol.net.Coherence) CoherenceConfiguration(com.tangosol.net.CoherenceConfiguration) SessionConfiguration(com.tangosol.net.SessionConfiguration) Bean(org.springframework.context.annotation.Bean)

Aggregations

SessionConfiguration (com.tangosol.net.SessionConfiguration)5 CoherenceConfiguration (com.tangosol.net.CoherenceConfiguration)3 Coherence (com.tangosol.net.Coherence)2 Test (org.junit.jupiter.api.Test)2 GrpcSessionConfiguration (com.oracle.coherence.client.GrpcSessionConfiguration)1 SessionType (com.oracle.coherence.hibernate.cache.v53.configuration.session.SessionType)1 ServerSessionConfigurationBean (com.oracle.coherence.spring.configuration.session.ServerSessionConfigurationBean)1 Serializer (com.tangosol.io.Serializer)1 Channel (io.grpc.Channel)1 SessionConfigurationProvider (io.micronaut.coherence.SessionConfigurationProvider)1 ApplicationContext (io.micronaut.context.ApplicationContext)1 Qualifiers (io.micronaut.inject.qualifiers.Qualifiers)1 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)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