Search in sources :

Example 16 with Session

use of com.tangosol.net.Session 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 17 with Session

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

the class CoherenceConfigDataLoader method getPropertySources.

public List<PropertySource<?>> getPropertySources(CoherenceConfigDataResource resource) {
    try (CoherenceGrpcClient coherenceGrpcClient = new CoherenceGrpcClient(resource.getProperties())) {
        final List<String> keys = this.buildSourceNames(resource);
        final List<PropertySource<?>> composite = new ArrayList<>();
        final Session session = coherenceGrpcClient.getCoherenceSession();
        for (String propertySourceName : keys) {
            final NamedMap<String, Object> configMap = session.getMap(propertySourceName);
            final Map<String, Object> results = new HashMap<>(configMap);
            final MapPropertySource propertySource = new MapPropertySource(propertySourceName, results);
            composite.add(propertySource);
        }
        return composite;
    }
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) ArrayList(java.util.ArrayList) PropertySource(org.springframework.core.env.PropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) Session(com.tangosol.net.Session)

Example 18 with Session

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

the class SpringDataAutoConfigurationTests method testInitializationOfSpringDataRepository.

@Test
public void testInitializationOfSpringDataRepository() {
    this.contextRunner.withUserConfiguration(ConfigWithEnableCoherenceRepositoriesAnnotation.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 19 with Session

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

the class CoherenceRepositoryFactory method ensureNamedMap.

/**
 * Ensures a {@link NamedMap} is available.
 * @return a {@link NamedMap} based on the {@link #mapName}
 */
@SuppressWarnings("rawtypes")
private NamedMap ensureNamedMap() {
    if (this.namedMap == null) {
        Session session = ensureSession();
        this.namedMap = session.getMap(this.mapName);
    }
    return this.namedMap;
}
Also used : Session(com.tangosol.net.Session)

Example 20 with Session

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

the class GrpcSessionBeanTests method testBasicGrpcClient.

@Test
@Order(1)
public void testBasicGrpcClient() throws Exception {
    final GrpcSessionConfiguration.Builder builder = GrpcSessionConfiguration.builder();
    final Session session = Session.create(builder.build()).get();
    final Map<String, String> fooMap = session.getMap("fooMap");
    fooMap.put("foo", "bar");
    final Map<String, String> mapFromCoherence = this.coherence.getSession().getMap("fooMap");
    assertEquals("bar", mapFromCoherence.get("foo"));
}
Also used : GrpcSessionConfiguration(com.oracle.coherence.client.GrpcSessionConfiguration) Session(com.tangosol.net.Session) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

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