|
6 | 6 | */
|
7 | 7 | package org.hibernate.test.hql;
|
8 | 8 |
|
| 9 | +import java.lang.reflect.Field; |
| 10 | +import java.util.Map; |
| 11 | +import java.util.stream.IntStream; |
9 | 12 | import javax.persistence.Entity;
|
10 | 13 | import javax.persistence.Id;
|
11 | 14 | import javax.persistence.Table;
|
12 | 15 |
|
13 | 16 | import org.hibernate.hql.internal.QuerySplitter;
|
| 17 | +import org.hibernate.metamodel.internal.MetamodelImpl; |
14 | 18 |
|
15 | 19 | import org.hibernate.testing.TestForIssue;
|
16 | 20 | import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
@@ -47,6 +51,29 @@ public void testQueryWithEntityNameAsStringLiteral2() {
|
47 | 51 | );
|
48 | 52 | }
|
49 | 53 |
|
| 54 | + @Test |
| 55 | + @TestForIssue(jiraKey = "HHH-14948") |
| 56 | + public void testMemoryConsumptionOfFailedImportsCache() throws NoSuchFieldException, IllegalAccessException { |
| 57 | + |
| 58 | + IntStream.range( 0, 1001 ) |
| 59 | + .forEach( i -> QuerySplitter.concreteQueries( |
| 60 | + "from Employee e join e.company" + i, |
| 61 | + sessionFactory() |
| 62 | + ) ); |
| 63 | + |
| 64 | + MetamodelImpl metamodel = (MetamodelImpl) sessionFactory().getMetamodel(); |
| 65 | + |
| 66 | + Field field = MetamodelImpl.class.getDeclaredField( "imports" ); |
| 67 | + field.setAccessible( true ); |
| 68 | + |
| 69 | + //noinspection unchecked |
| 70 | + Map<String, String> imports = (Map<String, String>) field.get( metamodel ); |
| 71 | + |
| 72 | + // VERY hard-coded, but considering the possibility of a regression of a memory-related issue, |
| 73 | + // it should be worth it |
| 74 | + assertEquals( 1000, imports.size() ); |
| 75 | + } |
| 76 | + |
50 | 77 | @Test
|
51 | 78 | @TestForIssue(jiraKey = "HHH-7973" )
|
52 | 79 | public void testQueryWithEntityNameAsStringLiteralAndEscapeQuoteChar() {
|
|
0 commit comments