Skip to content

Commit

Permalink
Merge 3033728 into 86952e7
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Dec 28, 2018
2 parents 86952e7 + 3033728 commit f6d14f1
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 68 deletions.
73 changes: 73 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2

references:
build: &build
working_directory: ~/repo

environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx2048m
JACOCO: false

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v2-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v2-dependencies-

- run:
name: Go Offline with Maven
command: mvn verify -DskipTests

- save_cache:
paths:
- ~/.m2
key: v2-dependencies-{{ checksum "pom.xml" }}

# run tests!
- run:
name: Run integration tests
command: mvn verify

workflows:
version: 2
integration-tests:
jobs:
- zulu-6
- zulu-7
- zulu-8
- zulu-9
- zulu-11

jobs:
zulu-6:
docker:
- image: wavesoftware/circleci-zulujdk:6
<<: *build
zulu-7:
docker:
- image: wavesoftware/circleci-zulujdk:7
<<: *build
zulu-8:
docker:
- image: wavesoftware/circleci-zulujdk:8
<<: *build
zulu-9:
docker:
- image: wavesoftware/circleci-zulujdk:9
<<: *build
zulu-11:
docker:
- image: wavesoftware/circleci-zulujdk:11
<<: *build



5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 4

[*.yml]
indent_size = 2
34 changes: 18 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
language: java
dist: trusty
before_script: mvn dependency:go-offline
script: mvn clean verify --fail-at-end
notifications:
email:
on_failure: true
on_failure: change
matrix:
include:
# Performance testing
- jdk: openjdk7
env: JACOCO=false
- jdk: openjdk8
env: JACOCO=false
# Quality testing
- jdk: openjdk7
env: JACOCO=true
- jdk: openjdk8
env: JACOCO=true COVERALLS=true
- jdk: oraclejdk8
env: JACOCO=true
- jdk: openjdk8
env: JACOCO=true SONAR=publish
script: mvn clean verify sonar:sonar --fail-at-end
# Quality testing
- jdk: oraclejdk8
env: JACOCO=true COVERALLS=true
- jdk: oraclejdk8
env: JACOCO=true SONAR=publish
script: mvn clean verify sonar:sonar --fail-at-end
# Performance testing
- jdk: openjdk7
env: JACOCO=false
- jdk: openjdk8
env: JACOCO=false
- jdk: oraclejdk9
env: JACOCO=false
- jdk: oraclejdk11
env: JACOCO=false
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.11.3</version>
<version>1.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.11.3</version>
<version>1.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.20</version>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -207,7 +207,7 @@
<configuration>
<compilerArgs>
<arg>-Werror</arg>
<arg>-Xlint:all</arg>
<arg>-Xlint:all,-options,-processing</arg>
</compilerArgs>
</configuration>
</plugin>
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/pl/wavesoftware/eid/DisableValidatorState.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.wavesoftware.eid.api.ConfigurationBuilder;
import pl.wavesoftware.eid.api.Configurator;

Expand All @@ -29,6 +31,8 @@
*/
@State(Scope.Benchmark)
public class DisableValidatorState {
private static final Logger LOGGER =
LoggerFactory.getLogger(DisableValidatorState.class);
private ConfigurationContext context;

@Setup
Expand All @@ -38,12 +42,14 @@ public void setup() {
@Override
public void configure(ConfigurationBuilder configuration) {
configuration.validator(null);
LOGGER.debug("Disable validation of Eid numbers");
}
});
}

@TearDown
public void tearDown() {
context.close();
LOGGER.debug("Restoring configuration context");
}
}
17 changes: 9 additions & 8 deletions src/test/java/pl/wavesoftware/eid/EidIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import org.slf4j.LoggerFactory;
import pl.wavesoftware.eid.exceptions.EidRuntimeException;
import pl.wavesoftware.testing.JavaAgentSkip;
import pl.wavesoftware.testing.JavaVersion;
import pl.wavesoftware.testing.JmhCleaner;
import pl.wavesoftware.testing.JvmArgs;

import java.util.Collection;
import java.util.Date;
Expand All @@ -48,15 +50,18 @@ public class EidIT {
private static final int PERCENT = 100;
private static final int OPERATIONS = 1000;
private static final Logger LOG = LoggerFactory.getLogger(EidIT.class);
private static final double SPEED_THRESHOLD = 0.9d;
private static final double SPEED_THRESHOLD =
JavaVersion.get().greaterOrEqual(JavaVersion.of(8))
? 0.9d
: 0.6d;

@ClassRule
public static RuleChain chain = RuleChain
.outerRule(new JmhCleaner(EidIT.class))
.around(JavaAgentSkip.ifActive());

@Test
public void doBenckmarking() throws Exception {
public void benchmark() throws Exception {
Options opt = new OptionsBuilder()
.include(this.getClass().getName() + ".*")
.mode(Mode.Throughput)
Expand All @@ -70,11 +75,7 @@ public void doBenckmarking() throws Exception {
.forks(1)
.shouldFailOnError(true)
.shouldDoGC(true)
.jvmArgs(
"-server", "-Xms256m", "-Xmx256m",
"-XX:PermSize=128m", "-XX:MaxPermSize=128m",
"-XX:+UseParallelGC"
)
.jvmArgs(JvmArgs.get())
.build();

Runner runner = new Runner(opt);
Expand Down Expand Up @@ -105,7 +106,7 @@ public void doBenckmarking() throws Exception {
}

@Benchmark
public void control(Blackhole bh, DisableValidatorState state) {
public void control(Blackhole bh) {
for (int i = 0; i < OPERATIONS; i++) {
bh.consume(new Date());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

import javax.xml.bind.JAXBException;
import javax.naming.NamingException;
import java.util.UnknownFormatConversionException;

import static org.hamcrest.CoreMatchers.containsString;
Expand All @@ -32,7 +32,6 @@
* @author Krzysztof Suszyński <krzysztof.suszynski@wavesoftware.pl>
* @since 2015-10-07
*/
@SuppressWarnings("ConstantConditions")
public class EidRuntimeExceptionTest {

@Rule
Expand All @@ -42,19 +41,19 @@ public class EidRuntimeExceptionTest {
public void testGetMessage() {
// then
thrown.expect(EidRuntimeException.class);
thrown.expectCause(CoreMatchers.<Throwable>instanceOf(JAXBException.class));
thrown.expectCause(CoreMatchers.<Throwable>instanceOf(NamingException.class));
thrown.expectCause(hasMessage(is((String) null)));
thrown.expectMessage(containsString("20151007:212217"));
thrown.expectMessage(containsString("javax.xml.bind.JAXBException\n - " +
"with linked exception:\n" +
"[java.util.UnknownFormatConversionException: " +
"Conversion = Invalid for unit test]"));
thrown.expectMessage(containsString(
"javax.naming.NamingException [Root exception is java.util" +
".UnknownFormatConversionException: Conversion = Invalid for" +
" unit test]"
));

// given
String message = null;
Throwable original = new UnknownFormatConversionException("Invalid for unit test");
JAXBException cause = new JAXBException(message);
cause.setLinkedException(original);
NamingException cause = new NamingException(null);
cause.setRootCause(original);
throw new EidRuntimeException("20151007:212217", cause);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import pl.wavesoftware.eid.exceptions.EidRuntimeException;
import pl.wavesoftware.testing.JavaAgentSkip;
import pl.wavesoftware.testing.JmhCleaner;
import pl.wavesoftware.testing.JvmArgs;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -79,11 +80,7 @@ public void doBenchmarking() throws RunnerException {
.forks(1)
.shouldFailOnError(true)
.shouldDoGC(true)
.jvmArgs(
"-server", "-Xms256m", "-Xmx256m",
"-XX:PermSize=128m", "-XX:MaxPermSize=128m",
"-XX:+UseParallelGC"
)
.jvmArgs(JvmArgs.get())
.build();

Runner runner = new Runner(opt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import javax.annotation.Nonnull;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Locale;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -471,7 +472,7 @@ public void testCreate() throws NoSuchMethodException {
// given
Class<EidPreconditions> cls = EidPreconditions.class;
Constructor<?> constructor = cls.getDeclaredConstructor();
boolean access = constructor.isAccessible();
boolean access = Modifier.isPublic(constructor.getModifiers());

// then
assertThat(access).isFalse();
Expand Down
67 changes: 67 additions & 0 deletions src/test/java/pl/wavesoftware/testing/JavaVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2018 Wave Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.wavesoftware.testing;

/**
* @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a>
* @since 2018-12-29
*/
public final class JavaVersion implements Comparable<JavaVersion> {
private final int major;

private JavaVersion(int major) {
this.major = major;
}

public static JavaVersion get() {
return new JavaVersion(getMajor());
}

public static JavaVersion of(int major) {
return new JavaVersion(major);
}

private static int getMajor() {
String version = System.getProperty("java.version");
if (version.startsWith("1.")) {
version = version.substring(2);
}
// Allow these formats:
// 1.8.0_72-ea
// 9-ea
// 9
// 9.0.1
int dotPos = version.indexOf('.');
int dashPos = version.indexOf('-');
return Integer.parseInt(version.substring(
0,
dotPos > -1
? dotPos
: dashPos > -1
? dashPos : 1
));
}

public boolean greaterOrEqual(JavaVersion other) {
return compareTo(other) >= 0;
}

@Override
public int compareTo(JavaVersion other) {
return this.major - other.major;
}
}
Loading

0 comments on commit f6d14f1

Please sign in to comment.