diff --git a/Makefile b/Makefile index 3f78b8dca..922699f9b 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ tests: build-builder mapfish_print_builder \ gradle --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/main/java/org/mapfish/print/servlet/job/PrintJob.java b/core/src/main/java/org/mapfish/print/servlet/job/PrintJob.java index 33c1f6f42..7d2564736 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/ClusteredMapPrinterServletTest.java b/core/src/test/java/org/mapfish/print/servlet/ClusteredMapPrinterServletTest.java index 639dfd4fb..9bf40a4e2 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 = 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 cdfdae2ea..0300254bb 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,28 +3,29 @@ 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.Constants; 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; 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; 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 { + private static final Logger LOGGER = LoggerFactory.getLogger(ClusteringTaskTest.class); + TestJobManager jobMan1; TestJobManager jobMan2; @Autowired private ApplicationContext context; @@ -38,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())); @@ -70,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()); @@ -79,8 +99,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) { @@ -91,21 +110,20 @@ public TestJobManager(String name) { } protected PrintJob createJob(final PrintJobEntry entry) { + LOGGER.error("createJob on " + name); 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 { + LOGGER.error(getEntry().getReferenceId() + " is being run by jobman " + name); + jobsRun++; + return super.call(); } }; job.initForTesting(ClusteringTaskTest.this.context); 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 33f5d724a..a949c2adf 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();