From fa85d99214445563e55378ffa2ddf9876c156769 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 7 Sep 2022 11:26:14 -0400 Subject: [PATCH] Disable ObjectToMapTransformerTests.cycle test The `ObjectToMapTransformerTests.testObjectToSpelMapTransformerWithCycle()` causes a `StackOverflowError` according to the parent-child-parent cycle in the model under test. This ends up with an error in the Gradle logs: ``` *** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at s\src\java.instrument\share\native\libinstrument\JPLISAgent.c line: 873 ``` * Disable this test to avoid memory overhead and CPU time to let Java determine stack overflow and avoid a build error --- .../ObjectToMapTransformerTests.java | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/ObjectToMapTransformerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/ObjectToMapTransformerTests.java index fe4f346b48..6619a4dcfd 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/transformer/ObjectToMapTransformerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/ObjectToMapTransformerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.integration.transformer; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.io.IOException; import java.math.BigDecimal; @@ -28,7 +29,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.context.expression.MapAccessor; import org.springframework.expression.Expression; @@ -55,7 +57,7 @@ public class ObjectToMapTransformerTests { @SuppressWarnings("unchecked") @Test - public void testObjectToSpelMapTransformer() throws IOException { + public void testObjectToSpelMapTransformer() { Employee employee = this.buildEmployee(); StandardEvaluationContext context = new StandardEvaluationContext(); context.addPropertyAccessor(new MapAccessor()); @@ -68,9 +70,9 @@ public class ObjectToMapTransformerTests { Map transformedMap = (Map) transformedMessage.getPayload(); assertThat(transformedMap).isNotNull(); - Object valueFromTheMap = null; - Object valueFromExpression = null; - Expression expression = null; + Object valueFromTheMap; + Object valueFromExpression; + Expression expression; expression = parser.parseExpression("departments[0]"); valueFromTheMap = transformedMap.get("departments[0]"); @@ -149,7 +151,8 @@ public class ObjectToMapTransformerTests { assertThat(valueFromExpression).isEqualTo(valueFromTheMap); } - @Test(expected = MessageTransformationException.class) + @Disabled("StackOverflowError") + @Test public void testObjectToSpelMapTransformerWithCycle() { Employee employee = this.buildEmployee(); Child child = new Child(); @@ -158,11 +161,13 @@ public class ObjectToMapTransformerTests { child.setParent(parent); ObjectToMapTransformer transformer = new ObjectToMapTransformer(); Message message = MessageBuilder.withPayload(employee).build(); - transformer.transform(message); + assertThatExceptionOfType(MessageTransformationException.class) + .isThrownBy(() -> transformer.transform(message)) + .withRootCauseInstanceOf(StackOverflowError.class); } @Test - public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntryForInstantField() throws Exception { + public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntryForInstantField() { Person person = new Person(); person.deathDate = Instant.now(); @@ -172,12 +177,12 @@ public class ObjectToMapTransformerTests { Map transformedMap = new ObjectToMapTransformer().transformPayload(employee); // If JSR310 support is enabled by calling findAndRegisterModules() on the Jackson mapper, - // Instant field should not be broken. Thus the count should exactly be 1 here. + // Instant field should not be broken. Therefore, the count should exactly be 1 here. assertThat(transformedMap.values().stream().filter(Objects::nonNull).count()).isEqualTo(1L); } @Test - public void testCustomMapperSupport_DisableTimestampFlag_SerializesDateAsString() throws Exception { + public void testCustomMapperSupport_DisableTimestampFlag_SerializesDateAsString() { Employee employee = buildEmployee(); ObjectMapper customMapper = new ObjectMapper(); @@ -203,20 +208,20 @@ public class ObjectToMapTransformerTests { companyAddress.setStreet("1123 Main"); companyAddress.setZip("12345"); - Map coordinates = new HashMap(); - coordinates.put("latitude", new Long[] { (long) 1, (long) 5, (long) 13 }); - coordinates.put("longitude", new Long[] { (long) 156 }); + Map coordinates = new HashMap<>(); + coordinates.put("latitude", new Long[]{ (long) 1, (long) 5, (long) 13 }); + coordinates.put("longitude", new Long[]{ (long) 156 }); companyAddress.setCoordinates(coordinates); - List datesA = new ArrayList(); + List datesA = new ArrayList<>(); datesA.add(new Date(System.currentTimeMillis() + 10000)); datesA.add(new Date(System.currentTimeMillis() + 20000)); - List datesB = new ArrayList(); + List datesB = new ArrayList<>(); datesB.add(new Date(System.currentTimeMillis() + 30000)); datesB.add(new Date(System.currentTimeMillis() + 40000)); - List> listOfDates = new ArrayList>(); + List> listOfDates = new ArrayList<>(); listOfDates.add(datesA); listOfDates.add(datesB); @@ -238,31 +243,31 @@ public class ObjectToMapTransformerTests { Address personAddress = new Address(); personAddress.setCity("Philly"); personAddress.setStreet("123 Main"); - List listTestData = new ArrayList(); + List listTestData = new ArrayList<>(); listTestData.add("hello"); listTestData.add("blah"); - Map> mapWithListTestData = new HashMap>(); + Map> mapWithListTestData = new HashMap<>(); mapWithListTestData.put("mapWithListTestData", listTestData); personAddress.setMapWithListData(mapWithListTestData); person.setAddress(personAddress); - Map remarksA = new HashMap(); - Map remarksB = new HashMap(); + Map remarksA = new HashMap<>(); + Map remarksB = new HashMap<>(); remarksA.put("foo", "foo"); remarksA.put("bar", "bar"); remarksB.put("baz", "baz"); - List> remarks = new ArrayList>(); + List> remarks = new ArrayList<>(); remarks.add(remarksA); remarks.add(remarksB); person.setRemarks(remarks); employee.setPerson(person); - Map> testMapData = new HashMap>(); + Map> testMapData = new HashMap<>(); - Map internalMapA = new HashMap(); + Map internalMapA = new HashMap<>(); internalMapA.put("foo", "foo"); internalMapA.put("bar", "bar"); - Map internalMapB = new HashMap(); + Map internalMapB = new HashMap<>(); internalMapB.put("baz", "baz"); testMapData.put("internalMapA", internalMapA);