La dernière version du DataGrid Java d’Oracle vient de sortir, Coherence 12.2.1. Voici comment démarrer un projet de zéro.

Télécharger le produit

Depuis le site d’Oracle sur http://www.oracle.com/technetwork/middleware/coherence/downloads/index.html

Télécharger les 2 binaires:

  • Coherence Quick install
  • Coherence Quick install Supplemental

Download coherence 12.2

 Installer Coherence

  • Décompresser les 2 archives dans un répertoire commun
  • Installer le package de base dans OracleHome
set COHERENCE_HOME=c:\Oracle\Coherence12.2
java -jar fmw_12.2.1.1.0_coherence_quick.jar ORACLE_HOME=%ORACLE_HOME%
  • Installer les extensions
java -jar fmw_12.2.1.1.0_coherence_quick_supplemental.jar ORACLE_HOME=%COHERENCE_HOME%

Installer les paquets Maven

Cette étape installe les librairies et plugins nécessaires dans votre repository Maven local.

La documentation Oracle est ici: https://docs.oracle.com/middleware/1221/core/MAVEN/config_maven.htm#MAVEN311

cd %COHERENCE_HOME%\oracle_common\plugins\maven\com\oracle\maven\oracle-maven-sync\12.2.1
mvn install:install-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar
mvn com.oracle.maven:oracle-maven-sync:push -Doracle-maven-sync.oracleHome=%COHERENCE_HOME% -DoverwriteParent=true -DtestingOnly=false

Initialiser le projet Maven

Dans le répertoire racine de votre projet, exécuter la création via l’archetype Maven:

mvn archetype:generate -DarchetypeGroupId=com.oracle.coherence.archetype -DarchetypeArtifactId=gar-maven-archetype -DarchetypeVersion=12.2.1-1-0 -DgroupId=fr.middlewareSolutions.coherence -DartifactId=demoA -Dversion=1.0-SNAPSHOT

Le fichier POM de base est alors celui-ci:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

 <groupId>fr.middlewareSolutions.coherence</groupId>
 <artifactId>demoA</artifactId>
 <version>1.0-SNAPSHOT</version>

 <packaging>gar</packaging>

 <dependencies>
 <dependency>
 <groupId>com.oracle.coherence</groupId>
 <artifactId>coherence</artifactId>
 <version>[12.2.1,12.2.2)</version>
 <scope>provided</scope>
 </dependency>

 </dependencies>

 <build>
 <plugins>
 <plugin>
 <groupId>com.oracle.coherence</groupId>
 <artifactId>gar-maven-plugin</artifactId>
 <version>12.2.1-1-0</version>
 <extensions>true</extensions>
 </plugin>

 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-jar-plugin</artifactId>
 <version>2.6</version>
 <configuration>
 <forceCreation>true</forceCreation>
 </configuration>
 </plugin>

 </plugins>
 </build>

</project>

Ajouter un test

Pour dérouler un test JUnit, il est nécessaire de compléter le pom avec

1_ une dépendance JUnit

<dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>4.12</version>
 </dependency>

2_ un contexte Coherence indépendant: src/test/resources/tangosol-coherence-override.xml

<?xml version='1.0'?>

<coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config"
 xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-operational-config coherence-operational-config.xsd">
 <cluster-config>
 <member-identity>
 <cluster-name>TestCluster</cluster-name>
 </member-identity>
 <multicast-listener>
 <address>127.0.0.1</address>
 <port>12120</port>
 </multicast-listener>
 </cluster-config>
 <logging-config>
 <severity-level>5</severity-level>
 </logging-config>
 <configurable-cache-factory-config>
 <init-params>
 <init-param>
 <param-type>java.lang.String</param-type>
 <param-value system-property="coherence.cacheconfig">META-INF/cache-config.xml
 </param-value>
 </init-param>
 <init-param id="1">
 <param-type>boolean</param-type>
 <param-value system-property="distributed.localstorage">true</param-value>
 </init-param>
 </init-params>
 </configurable-cache-factory-config>
 
</coherence>

3_ une configuration Coherence simple (Local): src/test/resources/META-INF/cache-config.xml

<?xml version="1.0"?>
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
 xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
 <caching-scheme-mapping>
 <cache-mapping>
 <cache-name>test-*</cache-name>
 <scheme-name>local</scheme-name>
 </cache-mapping>
 </caching-scheme-mapping>

 <caching-schemes>
 <local-scheme>
 <scheme-name>local</scheme-name>
 </local-scheme>

 </caching-schemes>
</cache-config>

4_ Une classe de test SimpleTest dans src/test/java

package fr.middlewareSolutions.coherence.demoA;

import static org.junit.Assert.*;

import org.junit.Test;

import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;

public class SimpleTest {

 @org.junit.AfterClass
 public void stopCache() {
 CacheFactory.shutdown();
 }
 
 @Test
 public void putASimpleValue() {
 String key = "k1";
 String value = "Hello World!";

 NamedCache&lt;Object, Object&gt; cache = CacheFactory.getCache("test-1");

 cache.put(key, value);
 assertEquals(value, (String) cache.get(key));

 
 }

}

Il ne reste plus qu’a lancer le build:


mvn test

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for fr.middlewareSolutions.coherence:demoA:gar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 45, column 12
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building demoA 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- gar-maven-plugin:12.2.1-1-0:generate-descriptor (default-generate-descriptor) @ demoA ---
[INFO] Generate the GridARchive descriptor
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ demoA ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ demoA ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ demoA ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ demoA ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ demoA ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running fr.middlewareSolutions.coherence.demoA.SimpleTest
2016-08-03 18:12:22.236/0.605 Oracle Coherence 12.2.1.1.0 <Info> (thread=main, member=n/a): Loaded operational configuration from "jar:file:/D:/apache/maven-repository/com/oracle/coherence/coherence/12.2.1-1-0/coherence-12.2.1-1-0.jar!/tangosol-coherence.xml"
2016-08-03 18:12:22.290/0.659 Oracle Coherence 12.2.1.1.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "jar:file:/D:/apache/maven-repository/com/oracle/coherence/coherence/12.2.1-1-0/coherence-12.2.1-1-0.jar!/tangosol-coherence-override-dev.xml"
2016-08-03 18:12:22.329/0.699 Oracle Coherence 12.2.1.1.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "file:/D:/Users/Emmanuel/workspaces/coherence/demoA/target/test-classes/tangosol-coherence-override.xml"
2016-08-03 18:12:22.333/0.702 Oracle Coherence 12.2.1.1.0 <D5> (thread=main, member=n/a): Optional configuration override "cache-factory-config.xml" is not specified
2016-08-03 18:12:22.334/0.703 Oracle Coherence 12.2.1.1.0 <D5> (thread=main, member=n/a): Optional configuration override "cache-factory-builder-config.xml" is not specified
2016-08-03 18:12:22.334/0.703 Oracle Coherence 12.2.1.1.0 <D5> (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml" is not specified

Oracle Coherence Version 12.2.1.1.0 Build 63073
 Grid Edition: Development mode
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

2016-08-03 18:12:22.520/0.889 Oracle Coherence GE 12.2.1.1.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "file:/D:/Users/Emmanuel/workspaces/coherence/demoA/target/test-classes/META-INF/cache-config.xml"
2016-08-03 18:12:28.060/6.429 Oracle Coherence GE 12.2.1.1.0 <Info> (thread=main, member=n/a): Created cache factory com.tangosol.net.ExtensibleConfigurableCacheFactory
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.345 sec - in fr.middlewareSolutions.coherence.demoA.SimpleTest

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.598 s
[INFO] Finished at: 2016-08-03T18:12:28+02:00
[INFO] Final Memory: 11M/309M
[INFO] ------------------------------------------------------------------------

Et voilà, un build complet Maven avec Coherence 12.2.1 !!

Victory 😉
Prise en main de Coherence 12.2.1