Skip to content

Commit

Permalink
Refactoring a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
chiroito committed Apr 5, 2024
1 parent 4dc1836 commit f6fae83
Show file tree
Hide file tree
Showing 159 changed files with 1,736 additions and 2,029 deletions.
51 changes: 46 additions & 5 deletions artifact-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,58 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.install.skip>true</maven.install.skip>
<exec.mainClass>dev.jfr4jdbc.artifact.DemoApplication</exec.mainClass>
</properties>

<profiles>
<profile>
<id>test-java11</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test-java8</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<testExcludes>
<exclude>dev/jfr4jdbc/sample/ModuleTest.java</exclude>
<exclude>module-info.java</exclude>
</testExcludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.7.1</version>
<version>0.10.1</version>
<extensions>true</extensions>
<executions>
<execution>
Expand All @@ -42,7 +83,7 @@
</execution>
</executions>
<configuration>
<mainClass>dev.jfr4jdbc.artifact.NativeImageTest</mainClass>
<mainClass>dev.jfr4jdbc.artifact.DemoApplication</mainClass>
<buildArgs>
<buildArg>--no-fallback --enable-monitoring</buildArg>
</buildArgs>
Expand Down Expand Up @@ -79,19 +120,19 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.4</version>
<version>42.7.3</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package dev.jfr4jdbc.artifact;

import dev.jfr4jdbc.JfrDataSource;
import jdk.jfr.Recording;
import org.postgresql.ds.PGPoolingDataSource;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/*
java -XX:StartFlightRecording=disk=true,dumponexit=true,duration=60s,filename=DemoApp.jfr
*/
public class DemoApplication {

public class NativeImageTest {
public static void main(String[] args) throws Exception {

Recording r = new Recording();
r.start();

PGPoolingDataSource postgreDs = new PGPoolingDataSource();

String hostname = System.getenv("POSTGRES_HOST");
Expand All @@ -30,6 +41,11 @@ public static void main(String[] args) throws Exception {

rs.next();
System.out.println(rs.getString("datname"));
} catch (SQLException e) {
e.printStackTrace();
}

r.stop();
r.dump(Files.createFile(Paths.get("DemoApp.jfr")));
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion artifact-test/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module artifact.app {
requires dev.jfr4jdbc;
requires transitive dev.jfr4jdbc;
requires java.naming;
requires org.postgresql.jdbc;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.jfr4jdbc.sample;
package dev.jfr4jdbc.artifact;

import dev.jfr4jdbc.JfrDataSource;
import org.junit.jupiter.api.DisplayName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.jfr4jdbc.sample;
package dev.jfr4jdbc.artifact;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -10,9 +10,13 @@
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class MultiReleaseJarTest {
public class ReleaseJarTest {

private final int JAVA_8_VERSION = 52;
private final int JAVA_11_VERSION = 55;

private JarFile open() throws IOException {
File artifactDir = new File("../jfr4jdbc-driver/target");
Expand All @@ -21,13 +25,13 @@ private JarFile open() throws IOException {
return new JarFile(files[0]);
}

@DisplayName("Multi Release Jar")
@Test
void isMultiRelease() throws Exception {

JarFile jarFile = open();
assertTrue(jarFile.isMultiRelease());
}
// @DisplayName("Multi Release Jar")
// @Test
// void isMultiRelease() throws Exception {
//
// JarFile jarFile = open();
// assertTrue(!jarFile.isMultiRelease());
// }

@DisplayName("Service Loader File exists")
@Test
Expand All @@ -36,40 +40,26 @@ void hasServiceLoaderFile() throws IOException {
assertNotNull(jarFile.getEntry("META-INF/services/java.sql.Driver"));
}

@DisplayName("Java 11 Directory exists")
@Test
void hasJava11Directory() throws IOException {
JarFile jarFile = open();
assertNotNull(jarFile.getEntry("META-INF/versions/11"));
}
// @DisplayName("Java 11 Directory exists")
// @Test
// void hasJava11Directory() throws IOException {
// JarFile jarFile = open();
// assertNull(jarFile.getEntry("META-INF/versions/11"));
// }

@DisplayName("Modular for Java 11")
@Test
void hasModuleInfo() throws IOException {
JarFile jarFile = open();
// assertNotNull(jarFile.getEntry("META-INF/versions/11/module-info.class"));
assertNotNull(jarFile.getEntry("module-info.class"));
}

private final int JAVA_8_VERSION = 52;
private final int JAVA_11_VERSION = 55;

@DisplayName("Classes for JDBC 4.2 exists")
@DisplayName("Jar is compatible with Java 8")
@Test
void hasJdbc42() throws IOException {
void isCompatibleWithJava8() throws IOException {
JarFile jarFile = open();

assertEquals(JAVA_8_VERSION, readMajorVersion(jarFile, "dev/jfr4jdbc/JfrDataSource.class"));
assertEquals(JAVA_8_VERSION, readMajorVersion(jarFile, "dev/jfr4jdbc/JfrDataSource42.class"));
}

@DisplayName("Classes for JDBC 4.3 exists")
@Test
void hasJdbc43() throws IOException {
JarFile jarFile = open();

assertEquals(JAVA_11_VERSION, readMajorVersion(jarFile, "META-INF/versions/11/dev/jfr4jdbc/JfrDataSource.class"));
assertEquals(JAVA_11_VERSION, readMajorVersion(jarFile, "META-INF/versions/11/dev/jfr4jdbc/JfrDataSource43.class"));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.jfr4jdbc.sample;
package dev.jfr4jdbc.artifact;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -13,7 +13,12 @@ public class ServiceLoaderTest {
@Test
void loadedTest() throws Exception {
ServiceLoader<Driver> loader = ServiceLoader.load(Driver.class);
long jfrDriverCount = loader.stream().filter(d -> d.get().getClass().getCanonicalName().equals("dev.jfr4jdbc.JfrServiceLoadedDriver")).count();
int jfrDriverCount = 0;
for (Driver d : loader) {
if (d.getClass().getCanonicalName().equals("dev.jfr4jdbc.JfrServiceLoadedDriver")) {
jfrDriverCount++;
}
}

assertEquals(1, jfrDriverCount);
}
Expand Down
2 changes: 1 addition & 1 deletion artifact-test/src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open module artifact.test {
requires dev.jfr4jdbc;
requires transitive dev.jfr4jdbc;

requires transitive org.junit.jupiter.engine;
requires transitive org.junit.jupiter.api;
Expand Down
4 changes: 1 addition & 3 deletions bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ export WORK_DIR=$(cd ${SCRIPT_DIR}; cd ../ ; pwd)
cd ${WORK_DIR}

# Run unit test
mvn -B --no-transfer-progress clean test -f pom.xml

# install jfr4jdbc-driver for artifact test
mvn -B --no-transfer-progress -DskipTests -Dgpg.skip clean install -f jfr4jdbc-driver/pom.xml
mvn -B --no-transfer-progress -Dgpg.skip clean install -f jfr4jdbc-driver/pom.xml

# Run artifact test
mvn -B --no-transfer-progress clean test -f artifact-test/pom.xml
Loading

0 comments on commit f6fae83

Please sign in to comment.