Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(java-11): Tests run individually against JDK 11 #4

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: java
jdk:
- oraclejdk8
- oraclejdk9
- oraclejdk11
- openjdk8
- openjdk9
- openjdk11
after_script:
- mvn clean test jacoco:report coveralls:report -Dcoveralls.token=$coveralls_repo_token
- mvn test jacoco:report coveralls:report -Dcoveralls.token=$coveralls_repo_token

matrix:
allow_failures:
- jdk: oraclejdk9
- jdk: oraclejdk11
- jdk: openjdk8
- jdk: openjdk9
35 changes: 27 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
<version>1.0.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<coveralls.token>NOT-A-TOKEN</coveralls.token>
<spotless.version>1.23.0</spotless.version>
</properties>

<build>
Expand All @@ -27,6 +28,7 @@
<index>true</index>
<manifestEntries>
<Premain-Class>uk.co.probablyfine.bytemonkey.ByteMonkeyAgent</Premain-Class>
<Agent-Class>uk.co.probablyfine.bytemonkey.ByteMonkeyAgent</Agent-Class>
</manifestEntries>
</archive>
</configuration>
Expand All @@ -46,11 +48,23 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<version>3.8.0</version>
<configuration>
<compilerArgument>-XDignore.symbol.file</compilerArgument>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<java>
<googleJavaFormat>
<version>1.5</version>
<style>GOOGLE</style>
</googleJavaFormat>
<removeUnusedImports/>
</java>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -78,16 +92,21 @@
</build>

<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>7.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ea.agentloader</groupId>
<artifactId>ea-agent-loader</artifactId>
<version>1.0.0</version>
<groupId>org.avaje</groupId>
<artifactId>avaje-agentloader</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module uk.co.probablyfine.bytemonkey {
requires java.base;
requires java.instrument;
requires org.objectweb.asm.tree;
}
54 changes: 26 additions & 28 deletions src/main/java/uk/co/probablyfine/bytemonkey/AddChanceOfFailure.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
package uk.co.probablyfine.bytemonkey;

import java.util.Random;

import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.tree.FrameNode;
import jdk.internal.org.objectweb.asm.tree.InsnList;
import jdk.internal.org.objectweb.asm.tree.JumpInsnNode;
import jdk.internal.org.objectweb.asm.tree.LabelNode;
import jdk.internal.org.objectweb.asm.tree.LdcInsnNode;
import jdk.internal.org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

public class AddChanceOfFailure {

private static final Random random = new Random();
private static final Random random = new Random();

public InsnList apply(InsnList newInstructions, double chanceOfFailure) {
final InsnList list = new InsnList();
public InsnList apply(InsnList newInstructions, double chanceOfFailure) {
final InsnList list = new InsnList();

final LabelNode originalCodeLabel = new LabelNode();
final LabelNode originalCodeLabel = new LabelNode();

list.add(new LdcInsnNode(chanceOfFailure));
list.add(new MethodInsnNode(
list.add(new LdcInsnNode(chanceOfFailure));
list.add(
new MethodInsnNode(
Opcodes.INVOKESTATIC,
"uk/co/probablyfine/bytemonkey/AddChanceOfFailure",
"shouldActivate",
"(D)Z",
false // this is not a method on an interface
));
));

list.add(new JumpInsnNode(Opcodes.IFEQ, originalCodeLabel));
list.add(new JumpInsnNode(Opcodes.IFEQ, originalCodeLabel));

list.add(newInstructions);
list.add(newInstructions);

list.add(new FrameNode(
Opcodes.F_APPEND, // append to the last stack frame
0, new Object[] {}, // no local variables here
0, new Object[] {} // no stack either!
));
list.add(
new FrameNode(
Opcodes.F_APPEND, // append to the last stack frame
0,
new Object[] {}, // no local variables here
0,
new Object[] {} // no stack either!
));

list.add(originalCodeLabel);
list.add(originalCodeLabel);

return list;
}
return list;
}

public static boolean shouldActivate(double chanceOfFailure) {
return random.nextDouble() < chanceOfFailure;
}
public static boolean shouldActivate(double chanceOfFailure) {
return random.nextDouble() < chanceOfFailure;
}
}
32 changes: 17 additions & 15 deletions src/main/java/uk/co/probablyfine/bytemonkey/AgentArguments.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package uk.co.probablyfine.bytemonkey;

public class AgentArguments {
private final long latency;
private final double chanceOfFailure;
private final int tcIndex;
private final long latency;
private final double chanceOfFailure;
private final int tcIndex;

public AgentArguments(long latency, double activationRatio, int tcIndex) {
this.latency = latency;
this.chanceOfFailure = activationRatio;
this.tcIndex = tcIndex;
}
public AgentArguments(long latency, double activationRatio, int tcIndex) {
this.latency = latency;
this.chanceOfFailure = activationRatio;
this.tcIndex = tcIndex;
}

public long latency() {
return latency;
}
public long latency() {
return latency;
}

public double chanceOfFailure() {
return chanceOfFailure;
}
public double chanceOfFailure() {
return chanceOfFailure;
}

public int tcIndex() { return tcIndex; }
public int tcIndex() {
return tcIndex;
}
}
18 changes: 10 additions & 8 deletions src/main/java/uk/co/probablyfine/bytemonkey/ByteMonkeyAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

public class ByteMonkeyAgent {

public static void premain(String agentArguments, Instrumentation instrumentation) throws UnmodifiableClassException {
ByteMonkeyClassTransformer transformer = new ByteMonkeyClassTransformer(agentArguments);
instrumentation.addTransformer(transformer);
}
public static void premain(String agentArguments, Instrumentation instrumentation)
throws UnmodifiableClassException {
ByteMonkeyClassTransformer transformer = new ByteMonkeyClassTransformer(agentArguments);
instrumentation.addTransformer(transformer);
}

/* Duplicate of premain(), needed for ea-agent-loader in tests */
public static void agentmain(String agentArguments, Instrumentation instrumentation) throws UnmodifiableClassException {
premain(agentArguments, instrumentation);
}
/* Duplicate of premain(), needed for ea-agent-loader in tests */
public static void agentmain(String agentArguments, Instrumentation instrumentation)
throws UnmodifiableClassException {
premain(agentArguments, instrumentation);
}
}
Loading