Skip to content

Commit

Permalink
Disable ObjectToMapTransformerTests.cycle test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
artembilan committed Sep 7, 2022
1 parent 0e6b70c commit fa85d99
Showing 1 changed file with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -28,7 +29,8 @@
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;
Expand All @@ -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());
Expand All @@ -68,9 +70,9 @@ public void testObjectToSpelMapTransformer() throws IOException {
Map<String, Object> transformedMap = (Map<String, Object>) 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]");
Expand Down Expand Up @@ -149,7 +151,8 @@ public void testObjectToSpelMapTransformer() throws IOException {
assertThat(valueFromExpression).isEqualTo(valueFromTheMap);
}

@Test(expected = MessageTransformationException.class)
@Disabled("StackOverflowError")
@Test
public void testObjectToSpelMapTransformerWithCycle() {
Employee employee = this.buildEmployee();
Child child = new Child();
Expand All @@ -158,11 +161,13 @@ public void testObjectToSpelMapTransformerWithCycle() {
child.setParent(parent);
ObjectToMapTransformer transformer = new ObjectToMapTransformer();
Message<Employee> 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();

Expand All @@ -172,12 +177,12 @@ public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntry
Map<String, Object> 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();
Expand All @@ -203,20 +208,20 @@ public Employee buildEmployee() {
companyAddress.setStreet("1123 Main");
companyAddress.setZip("12345");

Map<String, Long[]> coordinates = new HashMap<String, Long[]>();
coordinates.put("latitude", new Long[] { (long) 1, (long) 5, (long) 13 });
coordinates.put("longitude", new Long[] { (long) 156 });
Map<String, Long[]> 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<Date> datesA = new ArrayList<Date>();
List<Date> datesA = new ArrayList<>();
datesA.add(new Date(System.currentTimeMillis() + 10000));
datesA.add(new Date(System.currentTimeMillis() + 20000));

List<Date> datesB = new ArrayList<Date>();
List<Date> datesB = new ArrayList<>();
datesB.add(new Date(System.currentTimeMillis() + 30000));
datesB.add(new Date(System.currentTimeMillis() + 40000));

List<List<Date>> listOfDates = new ArrayList<List<Date>>();
List<List<Date>> listOfDates = new ArrayList<>();
listOfDates.add(datesA);
listOfDates.add(datesB);

Expand All @@ -238,31 +243,31 @@ public Employee buildEmployee() {
Address personAddress = new Address();
personAddress.setCity("Philly");
personAddress.setStreet("123 Main");
List<String> listTestData = new ArrayList<String>();
List<String> listTestData = new ArrayList<>();
listTestData.add("hello");
listTestData.add("blah");
Map<String, List<String>> mapWithListTestData = new HashMap<String, List<String>>();
Map<String, List<String>> mapWithListTestData = new HashMap<>();
mapWithListTestData.put("mapWithListTestData", listTestData);
personAddress.setMapWithListData(mapWithListTestData);
person.setAddress(personAddress);

Map<String, Object> remarksA = new HashMap<String, Object>();
Map<String, Object> remarksB = new HashMap<String, Object>();
Map<String, Object> remarksA = new HashMap<>();
Map<String, Object> remarksB = new HashMap<>();
remarksA.put("foo", "foo");
remarksA.put("bar", "bar");
remarksB.put("baz", "baz");
List<Map<String, Object>> remarks = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> remarks = new ArrayList<>();
remarks.add(remarksA);
remarks.add(remarksB);
person.setRemarks(remarks);
employee.setPerson(person);

Map<String, Map<String, Object>> testMapData = new HashMap<String, Map<String, Object>>();
Map<String, Map<String, Object>> testMapData = new HashMap<>();

Map<String, Object> internalMapA = new HashMap<String, Object>();
Map<String, Object> internalMapA = new HashMap<>();
internalMapA.put("foo", "foo");
internalMapA.put("bar", "bar");
Map<String, Object> internalMapB = new HashMap<String, Object>();
Map<String, Object> internalMapB = new HashMap<>();
internalMapB.put("baz", "baz");

testMapData.put("internalMapA", internalMapA);
Expand Down

0 comments on commit fa85d99

Please sign in to comment.