Out of memory: Java heap space and very slow test execution

Description

We have a project with 300 test methods and on weaker machines, our build fails because of "Out of memory: Java heap space"

What we have noticed that each test method is creating a new context object.
Besides out of memory exception test execution is very slow (For each test class we are registering a minimum of necessary services and appropriate resource resolver type).

Example:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 @ExtendWith(AemContextExtension.class) class SomeServletTest { private AemContext context = new AppAemContextBuilder(ResourceResolverType.RESOURCERESOLVER_MOCK).build(); private SomeServlet servlet = context.registerService(new SomeServlet()); @Test void test1() { servlet.doGet(context.request(), context.response()); assertAll( () -> assertEquals(HttpServletResponse.SC_OK, context.response().getStatus()), () -> assertEquals(PreCheckServlet.STATUS_FAILED, context.response().getOutputAsString()) ); } @Test void test2() { context.create().resource(JCR_INSTALLER_PAUSED_INSTALLATIONS_PARENT_NODE_PATH); servlet.doGet(context.request(), context.response()); assertAll( () -> assertEquals(HttpServletResponse.SC_OK, context.response().getStatus()), () -> assertEquals(PreCheckServlet.STATUS_SUCCEEDED, context.response().getOutputAsString()) ); } @Test void test3() { context.create().resource(SAMPLE_NODE_PATH); servlet.doGet(context.request(), context.response()); assertAll( () -> assertEquals(HttpServletResponse.SC_OK, context.response().getStatus()), () -> assertNull(context.resourceResolver().getResource(SAMPLE_NODE_PATH)), () -> assertEquals(PreCheckServlet.STATUS_SUCCEEDED, context.response().getOutputAsString()) ); } }

Environment

None

Status

Assignee

Unassigned

Reporter

Matija Kovacek

Labels

None

Components

Affects versions

AEM Mocks 2.4.8

Priority

Critical
Configure