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();
}
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();
}
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");
}
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);
});
}
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;
}
}
Aggregations