#chiroito ’s blog

Java を中心とした趣味の技術について

Infinispan をテストしてみる

ここでは Infinispan を開発するにあたって必要となるテストの実行の仕方を紹介します。

環境構築についてはこちら(Windows 上に Infinispan 11 のビルド環境を構築してみた - #chiroito ’s blog)をご覧ください。

全体のテスト

Infinispan のテストを全部実行するには以下の様にします。

mvn test -s maven-settings.xml

特定のモジュールだけのテスト

特定のモジュールにパッチを書いた時などにはそのモジュールのテストがきちんと通るか確認しないといけません。特定のモジュールだけのテストを実行するには、-pl <モジュール>を指定してテストを実行します。以下の例ではcoreモジュールをテストする例です。

mvn test -s maven-settings.xml -pl core

特定のモジュールの中で特定のテスト

Infinispan の開発中などに特定のテストだけを実行したいこともあると思います。特定のテストだけを実行する場合は、さらに-Dtest=<テストクラス名>を追加します。次の例はorg.infinispan.configuration.ConfigurationUnitTestをテストします。

mvn test -s maven-settings.xml -pl core -Dtest=org.infinispan.configuration.ConfigurationUnitTest

テストをデバッグ

テストに失敗した時には失敗した原因を調べたいこともあると思います。そんな時はテストをデバッグしましょう。Maven で実行しているテストをデバッグするには、そのテストへリモートから接続できるように-Dmaven.surefire.debugを付けてテストを実行します。テストの実行が止まったらIDEなどを使ってリモートからデバッガで接続しましょう。

mvn test -s maven-settings.xml -pl core -Dmaven.surefire.debug -Dtest=org.infinispan.configuration.ConfigurationUnitTest

Windows 上に Infinispan 11 のビルド環境を構築してみた

ここでは Windows 上でInfinispan を開発するためビルドできるように環境を構築していきます。Windows固有の理由でテストが通らなかったりするので、テストはスキップします。

環境変数

Java 11 と Maven が必要になりますので適宜インストールしてください。 それらのインストールディレクトリをJAVA_HOMEおよびM2_HOMEとして、JavaはPATHにも通しておきましょう。

また、ビルド時にログが化けたりするので英語にします。これは_JAVA_OPTIONSで指定します。

$ set JAVA_HOME=C:\opt\jdk-11.0.2
$ set M2_HOME=C:\opt\apache-maven-3.6.2
$ set PATH=%JAVA_HOME%\bin;%PATH%
$ set _JAVA_OPTIONS=-Dfile.encoding=UTF-8 -Duser.language=en -Duser.country=US

ソースコードのダウンロード

ソースコードはGithubにあります。ソースコードをダウンロードするにはgit cloneを使います。

$ git clone https://github.com/infinispan/infinispan.git

ビルド

bin\build.batと言うものもありますがこれは失敗します。このファイルは内部でclean installしているだけです。 なぜか、一発でmvn installすると失敗します。mvn packageを挟むと大丈夫なようです。今回はテストを省略しながらビルドします。maven-settings.xmlを必ず指定しましょう。

$ cd infinispan
$ mvn -s maven-settings.xml package -DskipTests=true
$ mvn -s maven-settings.xml install -DskipTests=true

これだけで完了です。

macOS に OpenJDK のビルド環境を構築

環境

以下の環境で試しました。

  • macOS Mojave バージョン 10.14.6
  • Xcode Version 11.3.1 (11C504)

環境の準備

環境を準備するには以下の3つが必要です。

  • Xcode
  • autoconf
  • Boot用JDK

Xcode は App Store からインストールしました。 デフォルトの設定ではbash configure時に以下のエラーが出るので開発者ディレクトリを変更します。

$ bash configure
Runnable configure script is not present
Generating runnable configure script at /Users/cito/develop/jdk/build/.configure-support/generated-configure.sh
Using autoconf at /usr/local/bin/autoconf [autoconf (GNU Autoconf) 2.69]
configure: Configuration created at Wed Mar 11 13:35:20 JST 2020.
checking for basename... /usr/bin/basename
(略)
checking which variants of the JVM to build... server
checking for sdk name... 
configure: error: No xcodebuild tool and no system framework headers found, use --with-sysroot or --with-sdk-name to provide a path to a valid SDK
/Users/cito/develop/jdk/build/.configure-support/generated-configure.sh: line 82: 5: Bad file descriptor
configure exiting with result code 1

開発者ディレクトリはxcode-selectコマンドに-sオプションを付けて変更します。-pオプションを付けることで今設定されているパスを確認できます。

$ xcode-select -p
/Library/Developer/CommandLineTools

$  sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

次に、Autoconf をインストールします。これはbrewコマンドでインストールします。

$ brew install autoconf
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
(略)
==> Caveats
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/autoconf
==> Summary
🍺  /usr/local/Cellar/autoconf/2.69: 71 files, 3.0MB

最後に Boot 用JDKをインストールします。これはリリースされている最新メジャーバージョンのJDKが必要です。

$ brew install java
==> Downloading https://homebrew.bintray.com/bottles/openjdk-13.0.2+8_2.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/60/6034ec5a0927803eae37a5e85b6c6efadb930527827b45ecc593e25a9750061c?__gda__=exp=1583902642
######################################################################## 100.0%
==> Pouring openjdk-13.0.2+8_2.mojave.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /usr/local,
because it shadows the macOS `java` wrapper.

If you need to have openjdk first in your PATH run:
  echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.bash_profile

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk/include"

==> Summary
🍺  /usr/local/Cellar/openjdk/13.0.2+8_2: 631 files, 314.6MB

インストールできたことを確認しましょう

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    13, x86_64: "OpenJDK 13"    /Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home
    1.8.0_221, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home

ビルド

ビルドはbash configureしてからmakeします。

$ bash configure
configure: Configuration created at Wed Mar 11 14:12:40 JST 2020.
checking for basename... /usr/bin/basename
(略)
====================================================
The existing configuration has been successfully updated in
/Users/cito/develop/jdk/build/macosx-x86_64-server-release
using default settings.

Configuration summary:
* Debug level:    release
* HS debug level: product
* JVM variants:   server
* JVM features:   server: 'aot cds compiler1 compiler2 dtrace epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc' 
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 15-internal+0-adhoc.cito.jdk (15-internal)

Tools summary:
* Boot JDK:       openjdk version "13" 2019-09-17 OpenJDK Runtime Environment (build 13+33) OpenJDK 64-Bit Server VM (build 13+33, mixed mode, sharing)  (at /Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home)
* Toolchain:      clang (clang/LLVM from Xcode 11.3.1)
* C Compiler:     Version 11.0.0 (at /usr/bin/clang)
* C++ Compiler:   Version 11.0.0 (at /usr/bin/clang++)

Build performance summary:
* Cores to use:   8
* Memory limit:   16384 MB

WARNING: The result of this configuration has overridden an older
configuration. You *should* run 'make clean' to make sure you get a
proper build. Failure to do so might result in strange build problems.

makeしてみましょう。

make images
Building target 'images' in configuration 'macosx-x86_64-server-release'
Compiling 8 files for BUILD_TOOLS_LANGTOOLS
Parsing 2 properties into enum-like class for jdk.compiler
Compiling 10 properties into resource bundles for jdk.javadoc
Compiling 19 properties into resource bundles for jdk.compiler
Compiling 12 properties into resource bundles for jdk.jdeps
(略)
Creating jdk image
WARNING: Using incubator modules: jdk.incubator.foreign, jdk.incubator.jpackage
Creating CDS archive for jdk image
Finished building target 'images' in configuration 'macosx-x86_64-server-release'

確認

ビルドしたものを確認してみます。

build/macosx-x86_64-server-release/jdk/bin/java -version
openjdk version "15-internal" 2020-09-15
OpenJDK Runtime Environment (build 15-internal+0-adhoc.cito.jdk)
OpenJDK 64-Bit Server VM (build 15-internal+0-adhoc.cito.jdk, mixed mode)