Skip to content

Commit 510eb18

Browse files
Add E2E tests for JUL (#4598)
* Add E2E tests for JUL * Format code * codereview changes * add to CI matrix --------- Co-authored-by: Sentry Github Bot <[email protected]>
1 parent 96301df commit 510eb18

File tree

6 files changed

+152
-6
lines changed

6 files changed

+152
-6
lines changed

.github/workflows/system-tests-backend.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ jobs:
6060
- sample: "sentry-samples-log4j2"
6161
agent: "false"
6262
agent-auto-init: "true"
63+
- sample: "sentry-samples-jul"
64+
agent: "false"
65+
agent-auto-init: "true"
6366
steps:
6467
- uses: actions/checkout@v4
6568
with:
Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,80 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
13
plugins {
24
java
35
application
6+
kotlin("jvm")
47
alias(libs.plugins.gradle.versions)
8+
id("com.github.johnrengelman.shadow") version "8.1.1"
59
}
610

711
application { mainClass.set("io.sentry.samples.jul.Main") }
812

13+
java.sourceCompatibility = JavaVersion.VERSION_17
14+
15+
java.targetCompatibility = JavaVersion.VERSION_17
16+
17+
repositories { mavenCentral() }
18+
919
configure<JavaPluginExtension> {
10-
sourceCompatibility = JavaVersion.VERSION_1_8
11-
targetCompatibility = JavaVersion.VERSION_1_8
20+
sourceCompatibility = JavaVersion.VERSION_17
21+
targetCompatibility = JavaVersion.VERSION_17
22+
}
23+
24+
tasks.withType<KotlinCompile>().configureEach {
25+
kotlinOptions {
26+
freeCompilerArgs = listOf("-Xjsr305=strict")
27+
jvmTarget = JavaVersion.VERSION_17.toString()
28+
}
1229
}
1330

1431
dependencies {
1532
implementation(projects.sentryJul)
1633
implementation(libs.slf4j.jdk14)
34+
35+
testImplementation(kotlin(Config.kotlinStdLib))
36+
testImplementation(projects.sentry)
37+
testImplementation(projects.sentrySystemTestSupport)
38+
testImplementation(libs.kotlin.test.junit)
39+
testImplementation(libs.slf4j.api)
40+
testImplementation(libs.slf4j.jdk14)
41+
}
42+
43+
// Configure the Shadow JAR (executable JAR with all dependencies)
44+
tasks.shadowJar {
45+
manifest { attributes["Main-Class"] = "io.sentry.samples.jul.Main" }
46+
archiveClassifier.set("") // Remove the classifier so it replaces the regular JAR
47+
mergeServiceFiles()
48+
}
49+
50+
// Make the regular jar task depend on shadowJar
51+
tasks.jar {
52+
enabled = false
53+
dependsOn(tasks.shadowJar)
54+
}
55+
56+
// Fix the startScripts task dependency
57+
tasks.startScripts { dependsOn(tasks.shadowJar) }
58+
59+
configure<SourceSetContainer> { test { java.srcDir("src/test/java") } }
60+
61+
tasks.register<Test>("systemTest").configure {
62+
group = "verification"
63+
description = "Runs the System tests"
64+
65+
outputs.upToDateWhen { false }
66+
67+
maxParallelForks = 1
68+
69+
// Cap JVM args per test
70+
minHeapSize = "128m"
71+
maxHeapSize = "1g"
72+
73+
filter { includeTestsMatching("io.sentry.systemtest*") }
74+
}
75+
76+
tasks.named("test").configure {
77+
require(this is Test)
78+
79+
filter { excludeTestsMatching("io.sentry.systemtest.*") }
1780
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
io.sentry.jul.SentryHandler.minimumEventLevel=FINE
1+
io.sentry.jul.SentryHandler.minimumEventLevel=INFO
22
io.sentry.jul.SentryHandler.minimumBreadcrumbLevel=CONFIG
3-
io.sentry.jul.SentryHandler.minimumLevel=FINE
3+
io.sentry.jul.SentryHandler.minimumLevel=INFO
44
io.sentry.jul.SentryHandler.printfStyle=true
5-
io.sentry.jul.SentryHandler.level=CONFIG
5+
io.sentry.jul.SentryHandler.level=FINEST
6+
java.util.logging.ConsoleHandler.level = FINE
67
handlers=io.sentry.jul.SentryHandler
7-
level=CONFIG
8+
level=FINEST
9+
io.sentry.samples.jul.Main.level=FINEST
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.sentry
2+
3+
import kotlin.test.Test
4+
import kotlin.test.assertTrue
5+
6+
class DummyTest {
7+
@Test
8+
fun `the only test`() {
9+
// only needed to have more than 0 tests and not fail the build
10+
assertTrue(true)
11+
}
12+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package io.sentry.systemtest
2+
3+
import io.sentry.SentryLevel
4+
import io.sentry.systemtest.util.TestHelper
5+
import java.util.concurrent.TimeUnit
6+
import org.junit.Assert
7+
import org.junit.Before
8+
import org.junit.Test
9+
10+
class ConsoleApplicationSystemTest {
11+
lateinit var testHelper: TestHelper
12+
13+
@Before
14+
fun setup() {
15+
testHelper = TestHelper("http://localhost:8000")
16+
testHelper.reset()
17+
}
18+
19+
@Test
20+
fun `jul application sends expected events when run as JAR`() {
21+
val jarFile = testHelper.findJar("sentry-samples-jul")
22+
val process =
23+
testHelper.launch(
24+
jarFile,
25+
mapOf(
26+
"SENTRY_DSN" to testHelper.dsn,
27+
"SENTRY_TRACES_SAMPLE_RATE" to "1.0",
28+
"SENTRY_ENABLE_PRETTY_SERIALIZATION_OUTPUT" to "false",
29+
"SENTRY_DEBUG" to "true",
30+
),
31+
)
32+
33+
process.waitFor(30, TimeUnit.SECONDS)
34+
Assert.assertEquals(0, process.exitValue())
35+
36+
// Verify that we received the expected events
37+
verifyExpectedEvents()
38+
}
39+
40+
private fun verifyExpectedEvents() {
41+
// Verify we received the RuntimeException
42+
testHelper.ensureErrorReceived { event ->
43+
event.exceptions?.any { ex ->
44+
ex.type == "RuntimeException" && ex.value == "Invalid productId=445"
45+
} == true && event.message?.message == "Something went wrong" && event.level?.name == "ERROR"
46+
}
47+
48+
testHelper.ensureErrorReceived { event ->
49+
event.breadcrumbs?.firstOrNull {
50+
it.message == "Hello Sentry!" && it.level == SentryLevel.DEBUG
51+
} != null
52+
}
53+
54+
testHelper.ensureErrorReceived { event ->
55+
event.breadcrumbs?.firstOrNull {
56+
it.message == "User has made a purchase of product: 445" && it.level == SentryLevel.INFO
57+
} != null
58+
}
59+
60+
testHelper.ensureLogsReceived { logs, _ ->
61+
testHelper.doesContainLogWithBody(logs, "User has made a purchase of product: 445") &&
62+
testHelper.doesContainLogWithBody(logs, "Something went wrong")
63+
}
64+
}
65+
}

test/system-test-runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ def get_available_modules(self) -> List[ModuleConfig]:
616616
ModuleConfig("sentry-samples-console-opentelemetry-noagent", "false", "true", "false"),
617617
ModuleConfig("sentry-samples-logback", "false", "true", "false"),
618618
ModuleConfig("sentry-samples-log4j2", "false", "true", "false"),
619+
ModuleConfig("sentry-samples-jul", "false", "true", "false"),
619620
]
620621

621622
def _find_module_number(self, module_name: str, agent: str, auto_init: str) -> int:

0 commit comments

Comments
 (0)