Skip to content

Commit

Permalink
Merge pull request #3494 from mapfish/enable_cluster_test
Browse files Browse the repository at this point in the history
Enabled cluster test
  • Loading branch information
sebr72 authored Nov 6, 2024
2 parents 630d0f6 + bee202d commit 790d3df
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
Expand Down Expand Up @@ -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());

Expand All @@ -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) {
Expand All @@ -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<String, String>()));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 790d3df

Please sign in to comment.