Skip to content

Commit

Permalink
#76 Apply auto-formatting and import sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Aug 3, 2021
1 parent b2fcac0 commit 43595df
Show file tree
Hide file tree
Showing 18 changed files with 514 additions and 98 deletions.
366 changes: 366 additions & 0 deletions etc/eclipse-formatter-config.xml

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.15.0</version>
<configuration>
<configFile>etc/eclipse-formatter-config.xml</configFile>
</configuration>
</plugin>

<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<groups>java.,javax.,org.,com.</groups>
<removeUnused>true</removeUnused>
<staticAfter>true</staticAfter>
<!-- <staticGroups>java.,javax.,org.w3c.,org.xml.,junit.</staticGroups> -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
Expand Down Expand Up @@ -171,6 +195,32 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<executions>
<execution>
<id>format</id>
<goals>
<goal>format</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<executions>
<execution>
<id>sort-imports</id>
<goals>
<goal>sort</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/moditect/jfrunit/EnableEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
long threshold() default -1L;

enum StacktracePolicy {
DEFAULT, INCLUDED, EXCLUDED
DEFAULT,
INCLUDED,
EXCLUDED
}

long period() default -1L;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/moditect/jfrunit/ExpectedClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
package org.moditect.jfrunit;

import jdk.jfr.consumer.RecordedClassLoader;

import java.util.function.Predicate;

import jdk.jfr.consumer.RecordedClassLoader;

public class ExpectedClassLoader implements Predicate<RecordedClassLoader> {
private Long id;
private String name;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/moditect/jfrunit/ExpectedEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ public static ExpectedEvent event(String name) {
return false;
}

if(!expectedEvent.getHasProps().isEmpty()) {
for(String name: expectedEvent.getHasProps()) {
if(!hasPropertyMatching(recordedEvent, name))
if (!expectedEvent.getHasProps().isEmpty()) {
for (String name : expectedEvent.getHasProps()) {
if (!hasPropertyMatching(recordedEvent, name))
return false;
}
}

if(!expectedEvent.getHasNotProps().isEmpty()) {
for(String name: expectedEvent.getHasNotProps()) {
if(hasPropertyMatching(recordedEvent, name)) {
if (!expectedEvent.getHasNotProps().isEmpty()) {
for (String name : expectedEvent.getHasNotProps()) {
if (hasPropertyMatching(recordedEvent, name)) {
return false;
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ private static boolean hasPropertyMatching(RecordedEvent recordedEvent, String n
}

Object value = recordedEvent.getValue(name);
return value!=null;
return value != null;
}

private static boolean withPropertyMatching(RecordedEvent recordedEvent, String name, Object value) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/moditect/jfrunit/ExpectedMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
package org.moditect.jfrunit;

import jdk.jfr.consumer.RecordedMethod;

import java.lang.reflect.Method;
import java.util.function.Predicate;

import jdk.jfr.consumer.RecordedMethod;

public class ExpectedMethod implements Predicate<RecordedMethod> {
private ExpectedClass type;
private String name;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/moditect/jfrunit/ExpectedStackFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
package org.moditect.jfrunit;

import jdk.jfr.consumer.RecordedFrame;

import java.util.Objects;
import java.util.function.Predicate;

import jdk.jfr.consumer.RecordedFrame;

public class ExpectedStackFrame implements Predicate<RecordedFrame> {
private Boolean isJavaFrame;
private Integer bytecodeIndex;
Expand All @@ -38,7 +38,6 @@ public ExpectedStackFrame(StackWalker.StackFrame stackFrame) {
this.method.setName(stackFrame.getMethodName());
}


public ExpectedStackFrame(StackTraceElement stackTraceElement) {
this.isJavaFrame = !stackTraceElement.isNativeMethod();
this.method = new ExpectedMethod();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/moditect/jfrunit/ExpectedThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
package org.moditect.jfrunit;

import jdk.jfr.consumer.RecordedThread;

import java.util.function.Predicate;

import jdk.jfr.consumer.RecordedThread;

public class ExpectedThread implements Predicate<RecordedThread> {
private Long id;
private Long javaThreadId;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/moditect/jfrunit/ExpectedThreadGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
package org.moditect.jfrunit;

import jdk.jfr.consumer.RecordedThreadGroup;

import java.util.function.Predicate;

import jdk.jfr.consumer.RecordedThreadGroup;

public class ExpectedThreadGroup implements Predicate<RecordedThreadGroup> {
private String name;
private ExpectedThreadGroup parent;
Expand Down
31 changes: 15 additions & 16 deletions src/main/java/org/moditect/jfrunit/JfrEventTestExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ public class JfrEventTestExtension implements Extension, BeforeEachCallback, Aft
@Override
public void beforeEach(ExtensionContext context) throws Exception {
String enabledConfiguration = AnnotationSupport.findAnnotation(context.getRequiredTestMethod(), EnableConfiguration.class)
.map(EnableConfiguration::value)
.map(String::trim)
.orElse(null);
.map(EnableConfiguration::value)
.map(String::trim)
.orElse(null);

List<EventConfiguration> enabledEvents = AnnotationSupport.findRepeatableAnnotations(context.getRequiredTestMethod(), EnableEvent.class)
.stream()
.map(e -> new EventConfiguration(e.value(), e.stackTrace(), e.threshold(), e.period()))
.collect(Collectors.toList());


Object instance = context.getRequiredTestInstance();
List<JfrEvents> allJfrEvents = getJfrEvents(instance);
for (JfrEvents jfrEvents : allJfrEvents) {
Expand All @@ -63,16 +62,16 @@ public void afterEach(ExtensionContext context) throws Exception {

private List<JfrEvents> getJfrEvents(Object instance) {
return getAllFields(instance.getClass())
.filter(f -> f.getType() == JfrEvents.class)
.map(f -> {
try {
return (JfrEvents) f.get(instance);
}
catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());
.filter(f -> f.getType() == JfrEvents.class)
.map(f -> {
try {
return (JfrEvents) f.get(instance);
}
catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());
}

/**
Expand All @@ -84,7 +83,7 @@ private List<JfrEvents> getJfrEvents(Object instance) {
private static Stream<Field> getAllFields(Class<?> c) {
Class<?> superclass = c.getSuperclass();
return Stream.concat(
Arrays.stream(c.getDeclaredFields()),
superclass == null ? Stream.empty() : getAllFields(superclass));
Arrays.stream(c.getDeclaredFields()),
superclass == null ? Stream.empty() : getAllFields(superclass));
}
}
27 changes: 15 additions & 12 deletions src/main/java/org/moditect/jfrunit/JfrEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
*/
package org.moditect.jfrunit;

import jdk.jfr.Configuration;
import jdk.jfr.EventSettings;
import jdk.jfr.EventType;
import jdk.jfr.FlightRecorder;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordingStream;

import java.io.IOException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
Expand All @@ -48,6 +40,14 @@
import org.moditect.jfrunit.EnableEvent.StacktracePolicy;
import org.moditect.jfrunit.internal.SyncEvent;

import jdk.jfr.Configuration;
import jdk.jfr.EventSettings;
import jdk.jfr.EventType;
import jdk.jfr.FlightRecorder;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordingStream;

public class JfrEvents {

private static final Logger LOGGER = System.getLogger(JfrEvents.class.getName());
Expand Down Expand Up @@ -96,7 +96,8 @@ void stopRecordingEvents() {
Path dumpDir;
try {
dumpDir = Files.createDirectories(Path.of(testSourceUri).getParent().resolve("jfrunit"));
} catch (FileSystemNotFoundException e) {
}
catch (FileSystemNotFoundException e) {
dumpDir = Files.createTempDirectory(null);
LOGGER.log(Level.WARNING, "'" + testSourceUri.getScheme() + "' is not a valid file system, dumping recording to a temporary location.");
}
Expand Down Expand Up @@ -130,7 +131,8 @@ public void awaitEvents() {
while (watermark.get() < seq) {
try {
Thread.sleep(INTERNAL_WAIT_TIME);
} catch (InterruptedException e) {
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -158,7 +160,7 @@ private Stream<RecordedEvent> stream() {
}

private void awaitStreamStart(CountDownLatch streamStarted) throws InterruptedException {
while(streamStarted.getCount() != 0) {
while (streamStarted.getCount() != 0) {
SyncEvent event = new SyncEvent();
event.sequence = sequence.incrementAndGet();
event.cause = "awaiting stream start";
Expand Down Expand Up @@ -233,7 +235,8 @@ else if (enabledEvent.stackTrace == StacktracePolicy.EXCLUDED) {
if (isSyncEvent(re)) {
watermark.set(re.getLong("sequence"));
streamStarted.countDown();
} else if (!isInternalSleepEvent(re)) {
}
else if (!isInternalSleepEvent(re)) {
events.add(re);
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/moditect/jfrunit/JfrEventsAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public JfrEventsAssert contains(ExpectedEvent expectedEvent) {
isNotNull();

boolean found = actual.events()
.anyMatch(re -> ExpectedEvent.matches(expectedEvent, re));
.anyMatch(re -> ExpectedEvent.matches(expectedEvent, re));

if (!found) {
if (expectedEvent.getWithProps().isEmpty() && expectedEvent.getHasProps().isEmpty() && expectedEvent.getHasNotProps().isEmpty()) {
failWithMessage("No JFR event of type <%s>", expectedEvent.getName());
}
else if(!expectedEvent.getHasProps().isEmpty()) {
else if (!expectedEvent.getHasProps().isEmpty()) {
failWithMessage("No JFR event of type <%s> with attributes <%s>", expectedEvent.getName(), expectedEvent.getHasProps());
}
else if(!expectedEvent.getHasNotProps().isEmpty()) {
else if (!expectedEvent.getHasNotProps().isEmpty()) {
failWithMessage("No JFR event of type <%s> without attributes <%s>", expectedEvent.getName(), expectedEvent.getHasNotProps());
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.quarkus.test.junit.callback.QuarkusTestAfterEachCallback;
import io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback;
import io.quarkus.test.junit.callback.QuarkusTestMethodContext;
import java.util.stream.Stream;

public class JfrUnitQuarkusLifecycleCallback implements QuarkusTestBeforeEachCallback, QuarkusTestAfterEachCallback {

Expand Down Expand Up @@ -62,22 +62,22 @@ private String getEnabledConfiguration(Method testMethod) {

private List<EventConfiguration> getEnabledEvents(Method testMethod) {
return Arrays.stream(testMethod.getAnnotationsByType(EnableEvent.class))
.map(e -> new EventConfiguration(e.value(), e.stackTrace(), e.threshold(), e.period()))
.collect(Collectors.toList());
.map(e -> new EventConfiguration(e.value(), e.stackTrace(), e.threshold(), e.period()))
.collect(Collectors.toList());
}

private List<JfrEvents> getJfrEvents(Object instance) {
return getAllFields(instance.getClass())
.filter(f -> f.getType() == JfrEvents.class)
.map(f -> {
try {
return (JfrEvents) f.get(instance);
}
catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());
.filter(f -> f.getType() == JfrEvents.class)
.map(f -> {
try {
return (JfrEvents) f.get(instance);
}
catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());
}

/**
Expand All @@ -88,7 +88,7 @@ private List<JfrEvents> getJfrEvents(Object instance) {
private static Stream<Field> getAllFields(Class<?> c) {
Class<?> superclass = c.getSuperclass();
return Stream.concat(
Arrays.stream(c.getDeclaredFields()),
superclass == null ? Stream.empty() : getAllFields(superclass));
Arrays.stream(c.getDeclaredFields()),
superclass == null ? Stream.empty() : getAllFields(superclass));
}
}
Loading

0 comments on commit 43595df

Please sign in to comment.