From 99044c32a6d8cad425f04adb9b5903a5f4f50836 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Wed, 30 Oct 2024 19:33:13 +0100 Subject: [PATCH 1/3] Enabled cluster test --- .../mapfish/print/servlet/job/PrintJob.java | 2 +- .../print/servlet/job/ClusteringTaskTest.java | 23 +++++++------------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java b/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java index 33c1f6f42c..7d2564736d 100644 --- a/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java +++ b/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java @@ -126,7 +126,7 @@ protected abstract PrintJobResult createResult( throws URISyntaxException, IOException; @Override - public final PrintJobResult call() throws Exception { + public PrintJobResult call() throws Exception { SecurityContextHolder.setContext(this.securityContext); final Timer.Context timer = this.metricRegistry diff --git a/core/src/test/java/org/mapfish/print/servlet/job/ClusteringTaskTest.java b/core/src/test/java/org/mapfish/print/servlet/job/ClusteringTaskTest.java index cdfdae2eac..6ba014c182 100644 --- a/core/src/test/java/org/mapfish/print/servlet/job/ClusteringTaskTest.java +++ b/core/src/test/java/org/mapfish/print/servlet/job/ClusteringTaskTest.java @@ -3,14 +3,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.util.HashMap; import org.json.JSONObject; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mapfish.print.AbstractMapfishSpringTest; import org.mapfish.print.config.access.AlwaysAllowAssertion; -import org.mapfish.print.processor.AbstractProcessor; import org.mapfish.print.servlet.ClusteredMapPrinterServletTest; import org.mapfish.print.servlet.MapPrinterServlet; import org.mapfish.print.servlet.job.impl.PrintJobEntryImpl; @@ -22,7 +19,6 @@ import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(locations = {ClusteredMapPrinterServletTest.CLUSTERED_CONTEXT}) -@Ignore // db must be set up to run this test public class ClusteringTaskTest extends AbstractMapfishSpringTest { TestJobManager jobMan1; @@ -79,8 +75,7 @@ public void testRun() throws Exception { } private class TestJobManager extends ThreadPoolJobManager { - private String name; - + private final String name; private int jobsRun; public TestJobManager(String name) { @@ -94,18 +89,16 @@ protected PrintJob createJob(final PrintJobEntry entry) { PrintJob job = new PrintJob() { @Override - protected PrintResult withOpenOutputStream(PrintAction function) throws Exception { - System.out.println(getEntry().getReferenceId() + " is being run by jobman " + name); - TestJobManager.this.jobsRun++; - Thread.sleep(1000); - return new PrintResult( - 42, new AbstractProcessor.Context(new HashMap())); + protected PrintJobResult createResult( + String fileName, String fileExtension, String mimeType) { + return null; } @Override - protected PrintJobResult createResult( - final String fileName, final String fileExtension, final String mimeType) { - return null; + public PrintJobResult call() throws Exception { + System.out.println(getEntry().getReferenceId() + " is being run by jobman " + name); + jobsRun++; + return super.call(); } }; job.initForTesting(ClusteringTaskTest.this.context); From c104d8ffa5333dd26fce4c10e3fd4f845f5a3a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Thu, 31 Oct 2024 14:02:23 +0100 Subject: [PATCH 2/3] Add log, cleanup logs --- Makefile | 4 +-- .../print/servlet/job/ClusteringTaskTest.java | 29 +++++++++++++++++-- .../job/PostResultToRegistryTaskTest.java | 18 +++++++++++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 3f78b8dca3..ab7104c32d 100644 --- a/Makefile +++ b/Makefile @@ -42,9 +42,9 @@ tests: build-builder --volume=$(PWD)/core/build/scripts/:/src/core/build/scripts/ \ --volume=$(PWD)/core/src/test/:/src/core/src/test/ \ mapfish_print_builder \ - gradle --parallel --exclude-task=:core:spotbugsMain --exclude-task=:core:checkstyleMain \ + gradle --no-parallel --exclude-task=:core:spotbugsMain --exclude-task=:core:checkstyleMain \ --exclude-task=:core:spotbugsTest --exclude-task=:core:checkstyleTest \ - :core:test :core:testCli + --info :core:test :core:testCli .PHONY: acceptance-tests-up acceptance-tests-up: build .env diff --git a/core/src/test/java/org/mapfish/print/servlet/job/ClusteringTaskTest.java b/core/src/test/java/org/mapfish/print/servlet/job/ClusteringTaskTest.java index 6ba014c182..0300254bb0 100644 --- a/core/src/test/java/org/mapfish/print/servlet/job/ClusteringTaskTest.java +++ b/core/src/test/java/org/mapfish/print/servlet/job/ClusteringTaskTest.java @@ -7,12 +7,15 @@ import org.junit.Before; import org.junit.Test; import org.mapfish.print.AbstractMapfishSpringTest; +import org.mapfish.print.Constants; import org.mapfish.print.config.access.AlwaysAllowAssertion; import org.mapfish.print.servlet.ClusteredMapPrinterServletTest; import org.mapfish.print.servlet.MapPrinterServlet; import org.mapfish.print.servlet.job.impl.PrintJobEntryImpl; import org.mapfish.print.servlet.job.impl.ThreadPoolJobManager; import org.mapfish.print.wrapper.json.PJsonObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.security.core.context.SecurityContextHolder; @@ -21,6 +24,8 @@ @ContextConfiguration(locations = {ClusteredMapPrinterServletTest.CLUSTERED_CONTEXT}) public class ClusteringTaskTest extends AbstractMapfishSpringTest { + private static final Logger LOGGER = LoggerFactory.getLogger(ClusteringTaskTest.class); + TestJobManager jobMan1; TestJobManager jobMan2; @Autowired private ApplicationContext context; @@ -34,9 +39,26 @@ public void setup() { @Test(timeout = 60000) public void testRun() throws Exception { + LOGGER.error("Starting jobs"); + PJsonObject requestData = new PJsonObject( - new JSONObject("{\"" + MapPrinterServlet.JSON_APP + "\":\"default\"}"), "job"); + new JSONObject( + "{" + // App + + "\"" + + MapPrinterServlet.JSON_APP + + "\": \"default\", " + // Output format + + "\"" + + MapPrinterServlet.JSON_OUTPUT_FORMAT + + "\": \"pdf\", " + // Layout + + "\"" + + Constants.JSON_LAYOUT_KEY + + "\": \"A4 Landscape\"" + + "}"), + "job"); jobMan1.submit( new PrintJobEntryImpl( "first job", requestData, System.currentTimeMillis(), new AlwaysAllowAssertion())); @@ -66,6 +88,8 @@ public void testRun() throws Exception { } } + LOGGER.error("All jobs are done"); + // verify each job was run only once assertEquals(4, jobMan1.getJobsRun() + jobMan2.getJobsRun()); @@ -86,6 +110,7 @@ public TestJobManager(String name) { } protected PrintJob createJob(final PrintJobEntry entry) { + LOGGER.error("createJob on " + name); PrintJob job = new PrintJob() { @Override @@ -96,7 +121,7 @@ protected PrintJobResult createResult( @Override public PrintJobResult call() throws Exception { - System.out.println(getEntry().getReferenceId() + " is being run by jobman " + name); + LOGGER.error(getEntry().getReferenceId() + " is being run by jobman " + name); jobsRun++; return super.call(); } diff --git a/core/src/test/java/org/mapfish/print/servlet/job/PostResultToRegistryTaskTest.java b/core/src/test/java/org/mapfish/print/servlet/job/PostResultToRegistryTaskTest.java index 33f5d724ae..a949c2adf4 100644 --- a/core/src/test/java/org/mapfish/print/servlet/job/PostResultToRegistryTaskTest.java +++ b/core/src/test/java/org/mapfish/print/servlet/job/PostResultToRegistryTaskTest.java @@ -9,6 +9,7 @@ import org.json.JSONObject; import org.junit.Test; import org.mapfish.print.AbstractMapfishSpringTest; +import org.mapfish.print.Constants; import org.mapfish.print.config.Configuration; import org.mapfish.print.config.Template; import org.mapfish.print.processor.AbstractProcessor; @@ -101,7 +102,22 @@ private class TestPrintJob extends PrintJob { PrintJobEntryImpl entry = (PrintJobEntryImpl) getEntry(); entry.setRequestData( new PJsonObject( - new JSONObject("{\"" + MapPrinterServlet.JSON_APP + "\":\"default\"}"), "job")); + new JSONObject( + "{" + // App + + "\"" + + MapPrinterServlet.JSON_APP + + "\": \"default\", " + // Output format + + "\"" + + MapPrinterServlet.JSON_OUTPUT_FORMAT + + "\": \"pdf\", " + // Layout + + "\"" + + Constants.JSON_LAYOUT_KEY + + "\": \"A4 Landscape\"" + + "}"), + "job")); entry.setReferenceId("abc"); Template template = new Template(); Configuration configuration = new Configuration(); From 07daedce25206d0657780b759f26cbf5634a59fe Mon Sep 17 00:00:00 2001 From: sebr72 Date: Fri, 1 Nov 2024 14:13:56 +0100 Subject: [PATCH 3/3] Fix broken test --- Makefile | 2 +- .../mapfish/print/servlet/ClusteredMapPrinterServletTest.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ab7104c32d..922699f9bc 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ tests: build-builder --volume=$(PWD)/core/build/scripts/:/src/core/build/scripts/ \ --volume=$(PWD)/core/src/test/:/src/core/src/test/ \ mapfish_print_builder \ - gradle --no-parallel --exclude-task=:core:spotbugsMain --exclude-task=:core:checkstyleMain \ + gradle --parallel --exclude-task=:core:spotbugsMain --exclude-task=:core:checkstyleMain \ --exclude-task=:core:spotbugsTest --exclude-task=:core:checkstyleTest \ --info :core:test :core:testCli diff --git a/core/src/test/java/org/mapfish/print/servlet/ClusteredMapPrinterServletTest.java b/core/src/test/java/org/mapfish/print/servlet/ClusteredMapPrinterServletTest.java index 639dfd4fb0..9bf40a4e24 100644 --- a/core/src/test/java/org/mapfish/print/servlet/ClusteredMapPrinterServletTest.java +++ b/core/src/test/java/org/mapfish/print/servlet/ClusteredMapPrinterServletTest.java @@ -1,8 +1,10 @@ package org.mapfish.print.servlet; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(locations = {ClusteredMapPrinterServletTest.CLUSTERED_CONTEXT}) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class ClusteredMapPrinterServletTest extends MapPrinterServletTest { public static final String CLUSTERED_CONTEXT =