|
| 1 | +/* |
| 2 | + * Source++, the continuous feedback platform for developers. |
| 3 | + * Copyright (C) 2022-2023 CodeBrig, Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package integration.breakpoint |
| 18 | + |
| 19 | +import integration.ProbeIntegrationTest |
| 20 | +import io.vertx.junit5.VertxTestContext |
| 21 | +import org.junit.jupiter.api.Test |
| 22 | +import spp.protocol.instrument.LiveBreakpoint |
| 23 | +import spp.protocol.instrument.event.LiveBreakpointHit |
| 24 | +import spp.protocol.instrument.event.LiveInstrumentEvent |
| 25 | +import spp.protocol.instrument.event.LiveInstrumentEventType |
| 26 | +import spp.protocol.instrument.location.LiveSourceLocation |
| 27 | +import spp.protocol.instrument.throttle.InstrumentThrottle |
| 28 | + |
| 29 | +import static org.junit.jupiter.api.Assertions.assertEquals |
| 30 | +import static org.junit.jupiter.api.Assertions.assertNotNull |
| 31 | + |
| 32 | +class GroovyBreakpointTest extends ProbeIntegrationTest { |
| 33 | + |
| 34 | + private void doTest() { |
| 35 | + def a = null |
| 36 | + def b = 1 |
| 37 | + def c = 'a' |
| 38 | + def d = "a" |
| 39 | + def e = true |
| 40 | + def f = 1.0 |
| 41 | + def g = 1.0f |
| 42 | + def h = 1L |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void testGroovy() { |
| 47 | + def breakpointId = "groovy-breakpoint-test" |
| 48 | + def testContext = new VertxTestContext() |
| 49 | + getLiveInstrumentSubscription(breakpointId).handler { |
| 50 | + def body = it.body() |
| 51 | + testContext.verify { |
| 52 | + def event = LiveInstrumentEvent.fromJson(body) |
| 53 | + if (event.eventType == LiveInstrumentEventType.BREAKPOINT_HIT) { |
| 54 | + def item = event as LiveBreakpointHit |
| 55 | + def vars = item.stackTrace.first().variables |
| 56 | + assertEquals(8, vars.size()) |
| 57 | + |
| 58 | + assertNotNull(vars.stream().find { it.name == "a" }) |
| 59 | + assertNotNull(vars.stream().find { it.name == "b" }) |
| 60 | + assertNotNull(vars.stream().find { it.name == "c" }) |
| 61 | + assertNotNull(vars.stream().find { it.name == "d" }) |
| 62 | + assertNotNull(vars.stream().find { it.name == "e" }) |
| 63 | + assertNotNull(vars.stream().find { it.name == "f" }) |
| 64 | + assertNotNull(vars.stream().find { it.name == "g" }) |
| 65 | + |
| 66 | + testContext.completeNow() |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + instrumentService.addLiveInstrument( |
| 72 | + new LiveBreakpoint( |
| 73 | + null, |
| 74 | + new LiveSourceLocation( |
| 75 | + GroovyBreakpointTest.class.name, |
| 76 | + 42, //todo: breaks if bp on return |
| 77 | + "spp-test-probe" |
| 78 | + ), |
| 79 | + null, |
| 80 | + null, |
| 81 | + 1, |
| 82 | + breakpointId, |
| 83 | + true, |
| 84 | + false, |
| 85 | + false, |
| 86 | + InstrumentThrottle.DEFAULT, |
| 87 | + new HashMap<String, Object>() |
| 88 | + ) |
| 89 | + ).onComplete { |
| 90 | + if (it.succeeded()) { |
| 91 | + log.info("Triggering breakpoint") |
| 92 | + doTest() |
| 93 | + } else { |
| 94 | + testContext.failNow(it.cause()) |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + errorOnTimeout(testContext, 2000) |
| 99 | + } |
| 100 | +} |
0 commit comments