Browse Source

Disable tests on Java 16 that require class-based proxies.

Original pull request: #3687.
Resolves #3656
pull/3701/head
Christoph Strobl 5 years ago committed by Mark Paluch
parent
commit
81bc3c599b
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 4
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java
  2. 6
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/DbRefMappingMongoConverterUnitTests.java
  3. 20
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepositoryLazyLoadingIntegrationTests.java
  4. 6
      src/main/asciidoc/reference/document-references.adoc

4
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java

@ -71,7 +71,7 @@ public class MongoMappingContext extends AbstractMappingContext<MongoPersistentE @@ -71,7 +71,7 @@ public class MongoMappingContext extends AbstractMappingContext<MongoPersistentE
@Override
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
if(NullableWrapperConverters.supports(type.getType())) {
if (NullableWrapperConverters.supports(type.getType())) {
return false;
}
@ -139,7 +139,7 @@ public class MongoMappingContext extends AbstractMappingContext<MongoPersistentE @@ -139,7 +139,7 @@ public class MongoMappingContext extends AbstractMappingContext<MongoPersistentE
MongoPersistentEntity<?> entity = super.getPersistentEntity(persistentProperty);
if(entity == null || !persistentProperty.isUnwrapped()) {
if (entity == null || !persistentProperty.isUnwrapped()) {
return entity;
}

6
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/DbRefMappingMongoConverterUnitTests.java

@ -36,6 +36,8 @@ import org.bson.conversions.Bson; @@ -36,6 +36,8 @@ import org.bson.conversions.Bson;
import org.bson.types.ObjectId;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
@ -181,6 +183,7 @@ class DbRefMappingMongoConverterUnitTests { @@ -181,6 +183,7 @@ class DbRefMappingMongoConverterUnitTests {
}
@Test // DATAMONGO-348
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
void lazyLoadingProxyForLazyDbRefOnConcreteCollection() {
String id = "42";
@ -508,6 +511,7 @@ class DbRefMappingMongoConverterUnitTests { @@ -508,6 +511,7 @@ class DbRefMappingMongoConverterUnitTests {
}
@Test // DATAMONGO-1076
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
void shouldNotTriggerResolvingOfLazyLoadedProxyWhenFinalizeMethodIsInvoked() throws Exception {
MongoPersistentEntity<?> entity = mappingContext
@ -526,6 +530,7 @@ class DbRefMappingMongoConverterUnitTests { @@ -526,6 +530,7 @@ class DbRefMappingMongoConverterUnitTests {
}
@Test // DATAMONGO-1194
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
void shouldBulkFetchListOfReferences() {
String id1 = "1";
@ -576,6 +581,7 @@ class DbRefMappingMongoConverterUnitTests { @@ -576,6 +581,7 @@ class DbRefMappingMongoConverterUnitTests {
}
@Test // DATAMONGO-1194
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
void shouldFallbackToOneByOneFetchingWhenElementsInListOfReferencesPointToDifferentCollections() {
String id1 = "1";

20
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepositoryLazyLoadingIntegrationTests.java

@ -22,14 +22,15 @@ import java.util.ArrayList; @@ -22,14 +22,15 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration test for {@link PersonRepository} for lazy loading support.
@ -38,13 +39,13 @@ import org.springframework.test.context.junit4.SpringRunner; @@ -38,13 +39,13 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Oliver Gierke
*/
@ContextConfiguration(locations = "PersonRepositoryIntegrationTests-context.xml")
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
public class PersonRepositoryLazyLoadingIntegrationTests {
@Autowired PersonRepository repository;
@Autowired MongoOperations operations;
@Before
@BeforeEach
public void setUp() throws InterruptedException {
repository.deleteAll();
@ -61,7 +62,6 @@ public class PersonRepositoryLazyLoadingIntegrationTests { @@ -61,7 +62,6 @@ public class PersonRepositoryLazyLoadingIntegrationTests {
Person person = new Person();
person.setFirstname("Oliver");
person.setFans(Arrays.asList(thomas));
person.setRealFans(new ArrayList<User>(Arrays.asList(thomas)));
repository.save(person);
Person oliver = repository.findById(person.id).get();
@ -75,7 +75,8 @@ public class PersonRepositoryLazyLoadingIntegrationTests { @@ -75,7 +75,8 @@ public class PersonRepositoryLazyLoadingIntegrationTests {
}
@Test // DATAMONGO-348
public void shouldLoadAssociationWithDbRefOnConcreteCollectionAndLazyLoadingEnabled() throws Exception {
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
public void shouldLoadAssociationWithDbRefOnConcreteCollectionAndLazyLoadingEnabled() {
User thomas = new User();
thomas.username = "Thomas";
@ -83,7 +84,6 @@ public class PersonRepositoryLazyLoadingIntegrationTests { @@ -83,7 +84,6 @@ public class PersonRepositoryLazyLoadingIntegrationTests {
Person person = new Person();
person.setFirstname("Oliver");
person.setFans(Arrays.asList(thomas));
person.setRealFans(new ArrayList<User>(Arrays.asList(thomas)));
repository.save(person);

6
src/main/asciidoc/reference/document-references.adoc

@ -49,6 +49,9 @@ TIP: Lazily loaded ``DBRef``s can be hard to debug. @@ -49,6 +49,9 @@ TIP: Lazily loaded ``DBRef``s can be hard to debug.
Make sure tooling does not accidentally trigger proxy resolution by e.g. calling `toString()` or some inline debug rendering invoking property getters.
Please consider to enable _trace_ logging for `org.springframework.data.mongodb.core.convert.DefaultDbRefResolver` to gain insight on `DBRef` resolution.
CAUTION: Lazy loading may require class proxies, that in turn, might need access to jdk internals, that are not open, starting with Java 16+, due to https://openjdk.java.net/jeps/396[JEP 396: Strongly Encapsulate JDK Internals by Default].
For those cases please consider falling back to an interface type (eg. switch from `ArrayList` to `List`) or provide the required `--add-opens` argument.
[[mapping-usage.document-references]]
=== Using Document References
@ -136,6 +139,9 @@ Result order of `Collection` like properties is restored based on the used looku @@ -136,6 +139,9 @@ Result order of `Collection` like properties is restored based on the used looku
| Resolves properties eagerly by default.
|===
CAUTION: Lazy loading may require class proxies, that in turn, might need access to jdk internals, that are not open, starting with Java 16+, due to https://openjdk.java.net/jeps/396[JEP 396: Strongly Encapsulate JDK Internals by Default].
For those cases please consider falling back to an interface type (eg. switch from `ArrayList` to `List`) or provide the required `--add-opens` argument.
`@DocumentReference(lookup)` allows defining filter queries that can be different from the `_id` field and therefore offer a flexible way of defining references between entities as demonstrated in the sample below, where the `Publisher` of a book is referenced by its acronym instead of the internal `id`.
====

Loading…
Cancel
Save