Skip to content

Commit 53ca0ce

Browse files
update java and JuniTest + JMemoryBuddy
1 parent 6e5f34b commit 53ca0ce

4 files changed

Lines changed: 78 additions & 8 deletions

File tree

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
os: [ubuntu-latest, macOS-latest, windows-latest]
21-
java: [ '16' ]
21+
java: [ '17-ea' ] // 16
2222
fail-fast: false
2323
name: ${{ matrix.os }}
2424
steps:

build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ dependencies {
3131
implementation 'org.xmlunit:xmlunit-core:2.8.1'
3232
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
3333
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
34+
implementation 'org.junit.jupiter:junit-jupiter:5.7.0'
3435

3536
// test dependencies
36-
testImplementation group: 'junit', name: 'junit', version: '4.13'
37+
testImplementation("org.junit.jupiter:junit-jupiter:5.7.2")
38+
testImplementation 'de.sandec:JMemoryBuddy:0.5.1'
3739
}
3840

3941
repositories {
4042
mavenCentral()
4143
}
4244

4345
javafx {
44-
version = '16' // '14.0.2.1'
46+
version = '17-ea+16' // '16' // '14.0.2.1'
4547
modules = ['javafx.controls']
4648
}
4749

@@ -78,15 +80,15 @@ runtime {
7880
installerName = applicationName
7981
// Set the environment property BADASS_JLINK_JPACKAGE_HOME or explicitly configure the below property
8082
def os = org.gradle.internal.os.OperatingSystem.current()
81-
if(os.macOsX) {
83+
/* if(os.macOsX) {
8284
// jpackageHome = '/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home'
8385
jpackageHome = '/Library/Java/JavaVirtualMachines/jdk-17-b-32.jdk/Contents/Home'
8486
} else if(os.windows) {
8587
jpackageHome = 'C:/Program Files/Java/jdk-16+36'
8688
} else {
8789
// Linux
8890
jpackageHome = '/usr/lib/jvm/jdk-16'
89-
}
91+
} */
9092
jvmArgs = []
9193
installerOptions = [
9294
// '--file-associations', 'src/main/resources/associations.properties',
@@ -97,7 +99,7 @@ runtime {
9799
if(os.macOsX) {
98100
imageOptions = ['--icon', 'src/main/deploy/package/macosx/hello.icns']
99101
installerOptions += [
100-
'--mac-sign',
102+
// '--mac-sign',
101103
// '--mac-signing-key-user-name', System.getenv('SIGNING_KEY_USER_NAME'),
102104
// '--mac-signing-keychain', System.getenv('SIGNING_KEYCHAIN_PATH')
103105
]

src/test/java/com/example/hellofx/HelloFXTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.example.hellofx;
22

3-
import static org.junit.Assert.*;
3+
import org.junit.jupiter.api.Test;
44

5-
import org.junit.Test;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
66

77
public class HelloFXTest {
88

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.example.hellofx;
2+
3+
import de.sandec.jmemorybuddy.JMemoryBuddy;
4+
import javafx.application.Platform;
5+
import javafx.scene.Scene;
6+
import javafx.scene.control.Button;
7+
import javafx.scene.control.MenuButton;
8+
import javafx.scene.control.ToolBar;
9+
import javafx.scene.layout.BorderPane;
10+
import javafx.stage.Stage;
11+
import org.junit.jupiter.api.Test;
12+
13+
import java.util.concurrent.CountDownLatch;
14+
import java.util.concurrent.TimeUnit;
15+
import java.util.concurrent.atomic.AtomicReference;
16+
17+
public class LeakTest {
18+
19+
@Test
20+
public void stageLeakWithMenuButton() throws Exception {
21+
JMemoryBuddy.memoryTest((checker) -> {
22+
CountDownLatch startupLatch = new CountDownLatch(1);
23+
CountDownLatch showingLatch = new CountDownLatch(1);
24+
AtomicReference<Stage> stage = new AtomicReference<>();
25+
26+
Platform.startup(() -> {
27+
startupLatch.countDown();
28+
});
29+
try {
30+
startupLatch.await(15, TimeUnit.SECONDS);
31+
} catch (InterruptedException e) {
32+
throw new RuntimeException(e);
33+
}
34+
35+
Platform.runLater(() -> {
36+
stage.set(new Stage());
37+
BorderPane root = new BorderPane();
38+
39+
ToolBar tb = new ToolBar();
40+
root.setTop(tb);
41+
tb.getItems().add(new Button("A"));
42+
tb.getItems().add(new Button("B"));
43+
tb.getItems().add(new Button("C"));
44+
// causes memory leak !!!
45+
tb.getItems().add(new MenuButton("MB"));
46+
47+
stage.get().setScene(new Scene(root));
48+
stage.get().setOnShown(l -> {
49+
Platform.runLater(() -> showingLatch.countDown());
50+
});
51+
stage.get().show();
52+
});
53+
54+
try {
55+
showingLatch.await(15, TimeUnit.SECONDS);
56+
} catch (InterruptedException e) {
57+
throw new RuntimeException(e);
58+
}
59+
60+
Platform.runLater(() -> {
61+
stage.get().close();
62+
});
63+
64+
checker.assertCollectable(stage.get());
65+
});
66+
}
67+
68+
}

0 commit comments

Comments
 (0)