@@ -1522,6 +1522,120 @@ public void mergedProbesDifferentSignature() throws IOException, URISyntaxExcept
15221522 assertNull (listener .snapshots .get (2 ).getEvaluationErrors ());
15231523 }
15241524
1525+ @ Test
1526+ public void mergedProbesWithCaptureExpressionsMixed () throws IOException , URISyntaxException {
1527+ final String CLASS_NAME = "CapturedSnapshot08" ;
1528+ LogProbe probe1 =
1529+ createProbeBuilder (PROBE_ID1 , CLASS_NAME , "doit" , null )
1530+ .evaluateAt (MethodLocation .EXIT )
1531+ .captureSnapshot (false )
1532+ .captureExpressions (
1533+ Arrays .asList (
1534+ new LogProbe .CaptureExpression (
1535+ "typed_fld_fld_msg" ,
1536+ new ValueScript (
1537+ DSL .getMember (
1538+ DSL .getMember (DSL .getMember (DSL .ref ("typed" ), "fld" ), "fld" ),
1539+ "msg" ),
1540+ "typed.fld.fld.msg" ),
1541+ null ),
1542+ new LogProbe .CaptureExpression (
1543+ "nullTyped_fld" ,
1544+ new ValueScript (
1545+ DSL .getMember (DSL .ref ("nullTyped" ), "fld" ), "nullTyped.fld" ),
1546+ null )))
1547+ .build ();
1548+ LogProbe probe2 = createMethodProbeAtExit (PROBE_ID2 , CLASS_NAME , "doit" , null );
1549+ TestSnapshotListener listener = installProbes (probe1 , probe2 );
1550+ Class <?> testClass = compileAndLoadClass (CLASS_NAME );
1551+ int result = Reflect .onClass (testClass ).call ("main" , "1" ).get ();
1552+ assertEquals (3 , result );
1553+ List <Snapshot > snapshots = assertSnapshots (listener , 2 , PROBE_ID1 , PROBE_ID2 );
1554+ // snapshot with Capture Expressions
1555+ Snapshot snapshot0 = snapshots .get (0 );
1556+ assertEquals (2 , snapshot0 .getCaptures ().getReturn ().getCaptureExpressions ().size ());
1557+ assertCaptureExpressions (
1558+ snapshot0 .getCaptures ().getReturn (),
1559+ "typed_fld_fld_msg" ,
1560+ String .class .getTypeName (),
1561+ "hello" );
1562+ assertCaptureExpressions (
1563+ snapshot0 .getCaptures ().getReturn (), "nullTyped_fld" , Object .class .getTypeName (), null );
1564+ assertNull (snapshot0 .getCaptures ().getReturn ().getArguments ());
1565+ assertNull (snapshot0 .getCaptures ().getReturn ().getLocals ());
1566+ // Snapshot without Capture Expressions
1567+ Snapshot snapshot1 = snapshots .get (1 );
1568+ assertNull (snapshot1 .getCaptures ().getReturn ().getCaptureExpressions ());
1569+ assertCaptureArgs (snapshot1 .getCaptures ().getReturn (), "arg" , String .class .getTypeName (), "1" );
1570+ assertCaptureLocals (
1571+ snapshot1 .getCaptures ().getReturn (), "var1" , Integer .TYPE .getTypeName (), "3" );
1572+ assertCaptureLocals (
1573+ snapshot1 .getCaptures ().getReturn (), "@return" , Integer .TYPE .getTypeName (), "3" );
1574+ }
1575+
1576+ @ Test
1577+ public void mergedProbesWithDifferentCaptureExpressions () throws IOException , URISyntaxException {
1578+ final String CLASS_NAME = "CapturedSnapshot08" ;
1579+ LogProbe probe1 =
1580+ createProbeBuilder (PROBE_ID1 , CLASS_NAME , "doit" , null )
1581+ .evaluateAt (MethodLocation .EXIT )
1582+ .captureSnapshot (false )
1583+ .captureExpressions (
1584+ Arrays .asList (
1585+ new LogProbe .CaptureExpression (
1586+ "typed_fld_fld_msg" ,
1587+ new ValueScript (
1588+ DSL .getMember (
1589+ DSL .getMember (DSL .getMember (DSL .ref ("typed" ), "fld" ), "fld" ),
1590+ "msg" ),
1591+ "typed.fld.fld.msg" ),
1592+ null ),
1593+ new LogProbe .CaptureExpression (
1594+ "nullTyped_fld" ,
1595+ new ValueScript (
1596+ DSL .getMember (DSL .ref ("nullTyped" ), "fld" ), "nullTyped.fld" ),
1597+ null )))
1598+ .build ();
1599+ LogProbe probe2 =
1600+ createProbeBuilder (PROBE_ID2 , CLASS_NAME , "doit" , null )
1601+ .evaluateAt (MethodLocation .EXIT )
1602+ .captureSnapshot (false )
1603+ .captureExpressions (
1604+ Arrays .asList (
1605+ new LogProbe .CaptureExpression (
1606+ "var1" , new ValueScript (DSL .ref ("var1" ), "var1" ), null ),
1607+ new LogProbe .CaptureExpression (
1608+ "this_fld" ,
1609+ new ValueScript (DSL .getMember (DSL .ref ("this" ), "fld" ), "this.fld" ),
1610+ null )))
1611+ .build ();
1612+ TestSnapshotListener listener = installProbes (probe1 , probe2 );
1613+ Class <?> testClass = compileAndLoadClass (CLASS_NAME );
1614+ int result = Reflect .onClass (testClass ).call ("main" , "1" ).get ();
1615+ assertEquals (3 , result );
1616+ List <Snapshot > snapshots = assertSnapshots (listener , 2 , PROBE_ID1 , PROBE_ID2 );
1617+ // Snapshot 0
1618+ Snapshot snapshot0 = snapshots .get (0 );
1619+ assertEquals (2 , snapshot0 .getCaptures ().getReturn ().getCaptureExpressions ().size ());
1620+ assertCaptureExpressions (
1621+ snapshot0 .getCaptures ().getReturn (),
1622+ "typed_fld_fld_msg" ,
1623+ String .class .getTypeName (),
1624+ "hello" );
1625+ assertCaptureExpressions (
1626+ snapshot0 .getCaptures ().getReturn (), "nullTyped_fld" , Object .class .getTypeName (), null );
1627+ assertNull (snapshot0 .getCaptures ().getReturn ().getArguments ());
1628+ assertNull (snapshot0 .getCaptures ().getReturn ().getLocals ());
1629+ // Snapshot 1
1630+ Snapshot snapshot1 = snapshots .get (1 );
1631+ assertCaptureExpressions (
1632+ snapshot1 .getCaptures ().getReturn (), "var1" , Integer .class .getTypeName (), "3" );
1633+ assertCaptureExpressions (
1634+ snapshot1 .getCaptures ().getReturn (), "this_fld" , Integer .class .getTypeName (), "11" );
1635+ assertNull (snapshot1 .getCaptures ().getReturn ().getArguments ());
1636+ assertNull (snapshot1 .getCaptures ().getReturn ().getLocals ());
1637+ }
1638+
15251639 @ Test
15261640 public void fields () throws IOException , URISyntaxException {
15271641 final String CLASS_NAME = "CapturedSnapshot06" ;
0 commit comments