Search in sources :

Example 1 with Session

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();
}
Also used : CoherenceRegionValue(com.oracle.coherence.hibernate.cache.v53.region.CoherenceRegionValue) Coherence(com.tangosol.net.Coherence) Session(com.tangosol.net.Session) Test(org.junit.Test)

Example 2 with Session

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

the class AbstractCoherenceIndexedSessionRepositoryTests method createAndDestroyCoherenceSession.

@Test
void createAndDestroyCoherenceSession() {
    final CoherenceSpringSession sessionToSave = this.repository.createSession();
    final String sessionId = sessionToSave.getId();
    this.repository.save(sessionToSave);
    final Session coherenceSession = StringUtils.hasText(this.sessionName) ? this.coherenceInstance.getSession(this.sessionName) : this.coherenceInstance.getSession();
    final CacheMap<String, MapSession> cacheMap = coherenceSession.getCache(CoherenceIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
    assertThat(cacheMap.get(sessionId)).isEqualTo(sessionToSave.getDelegate());
    this.repository.deleteById(sessionId);
    assertThat(cacheMap.get(sessionId)).isNull();
}
Also used : MapSession(org.springframework.session.MapSession) Session(com.tangosol.net.Session) MapSession(org.springframework.session.MapSession) Test(org.junit.jupiter.api.Test)

Example 3 with Session

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

the class CoherenceGrpcClientTests method testDefaultCacheManagerExists.

@Test
public void testDefaultCacheManagerExists() throws Exception {
    final CoherenceConfigClientProperties coherenceConfigClientProperties = new CoherenceConfigClientProperties();
    coherenceConfigClientProperties.getClient().setHost("localhost");
    coherenceConfigClientProperties.getClient().setPort(1408);
    coherenceConfigClientProperties.getClient().setEnableTls(false);
    final CoherenceGrpcClient coherenceGrpcClient = new CoherenceGrpcClient(coherenceConfigClientProperties);
    final Session grpcCoherenceSession = coherenceGrpcClient.getCoherenceSession();
    final NamedCache cache = grpcCoherenceSession.getCache("test");
    cache.put("foo2", "bar2");
    coherenceGrpcClient.close();
    final Session coherenceSession = this.coherence.getSession();
    assertThat(coherenceSession.getCache("test")).hasSize(1);
    assertThat(coherenceSession.getCache("test").get("foo2")).isEqualTo("bar2");
}
Also used : Session(com.tangosol.net.Session) NamedCache(com.tangosol.net.NamedCache) Test(org.junit.jupiter.api.Test)

Example 4 with Session

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

the class SpringDataAutoConfigurationTests method testSpringDataRepositoryAutoConfiguration.

@Test
public void testSpringDataRepositoryAutoConfiguration() {
    this.contextRunner.withUserConfiguration(ConfigWithAutoConfigurationOfCoherenceRepositories.class).run((context) -> {
        final Coherence coherence = context.getBean(Coherence.class);
        final Session session = coherence.getSession();
        assertThat(context).hasSingleBean(CoherenceServer.class);
        assertThat(context).hasSingleBean(SpringDataTaskRepository.class);
        final NamedMap<String, Task> tasks = session.getMap("tasks");
        assertThat(tasks).hasSize(0);
        final SpringDataTaskRepository repository = context.getBean(SpringDataTaskRepository.class);
        final Task task = new Task("Write some code.");
        repository.save(task);
        assertThat(tasks).hasSize(1);
        repository.deleteAll();
        assertThat(tasks).hasSize(0);
    });
}
Also used : Coherence(com.tangosol.net.Coherence) Session(com.tangosol.net.Session) Test(org.junit.jupiter.api.Test)

Example 5 with Session

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

the class CoherenceCacheManager method getCache.

/**
 * {@inheritDoc}
 */
@Override
public Cache getCache(String name) {
    final CoherenceCache cache = this.coherenceCacheMap.get(name);
    if (cache == null) {
        final Session session = this.coherence.getSession();
        final String cacheNameToUse = this.defaultCacheConfiguration.getCacheName(name);
        final NamedCache<Object, Object> namedCache = session.getCache(cacheNameToUse);
        final CoherenceCache coherenceCache = new CoherenceCache(namedCache, this.defaultCacheConfiguration);
        final CoherenceCache preExistingCoherenceCache = this.coherenceCacheMap.putIfAbsent(name, coherenceCache);
        return (preExistingCoherenceCache != null) ? preExistingCoherenceCache : coherenceCache;
    } else {
        return cache;
    }
}
Also used : Session(com.tangosol.net.Session)

Aggregations

Session (com.tangosol.net.Session)28 Test (org.junit.jupiter.api.Test)14 GrpcSessionConfiguration (com.oracle.coherence.client.GrpcSessionConfiguration)5 Coherence (com.tangosol.net.Coherence)5 Filter (com.tangosol.util.Filter)5 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)4 Platform (com.oracle.bedrock.runtime.Platform)4 GetClusterSize (com.oracle.bedrock.runtime.coherence.callables.GetClusterSize)4 GetLocalMemberId (com.oracle.bedrock.runtime.coherence.callables.GetLocalMemberId)4 AbstractTest (com.oracle.bedrock.testsupport.junit.AbstractTest)4 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)4 SessionName (com.oracle.coherence.spring.annotation.SessionName)3 NamedCache (com.tangosol.net.NamedCache)3 ValueExtractor (com.tangosol.util.ValueExtractor)3 Channel (io.grpc.Channel)3 Name (com.oracle.coherence.spring.annotation.Name)2 NamedMap (com.tangosol.net.NamedMap)2 Publisher (com.tangosol.net.topic.Publisher)2 MapEventTransformer (com.tangosol.util.MapEventTransformer)2 MapEventFilter (com.tangosol.util.filter.MapEventFilter)2