Permalink
Browse files

Add Java mapscript to the test target; Fix a thread safety issue with…

… msWMSGetCapabilities by wrapping it with a lock
  • Loading branch information...
1 parent caafcaa commit 54ef04bbba208da2971e8b3c2c189cce105e0348 @unicolet unicolet committed Aug 13, 2013
View
@@ -1,13 +1,14 @@
AUTOTEST_OPTS=-strict -q
PHP_MAPSCRIPT=build/mapscript/php/php_mapscript.so
PYTHON_MAPSCRIPT_PATH=build/mapscript/python
+JAVA_MAPSCRIPT_PATH=build/mapscript/java
BUILDPATH=../../build
FLEX=flex
YACC=yacc
CMAKEFLAGS=-DCMAKE_C_FLAGS="--coverage" -DCMAKE_CXX_FLAGS="--coverage" \
-DCMAKE_SHARED_LINKER_FLAGS="-lgcov" -DWITH_GD=1 -DWITH_CLIENT_WMS=1 \
-DWITH_CLIENT_WFS=1 -DWITH_KML=1 -DWITH_SOS=1 -DWITH_PHP=1 \
- -DWITH_PYTHON=1 -DWITH_FRIBIDI=0 -DWITH_FCGI=0 -DWITH_EXEMPI=1 \
+ -DWITH_PYTHON=1 -DWITH_JAVA=1 -DWITH_THREADS=1 -DWITH_FRIBIDI=0 -DWITH_FCGI=0 -DWITH_EXEMPI=1 \
-DCMAKE_BUILD_TYPE=Release -DWITH_RSVG=1 -DWITH_CURL=1
all: cmakebuild
@@ -42,10 +43,14 @@ mspython-testcase:
php-testcase:
test -f "$(PHP_MAPSCRIPT)" && (export PHP_MAPSCRIPT_SO="../../$(PHP_MAPSCRIPT)" && cd msautotest/php && ./run_test.sh)
+java-testcase:
+ test -d "$(JAVA_MAPSCRIPT_PATH)" && (export JAVA_MAPSCRIPT_SO="../../$(JAVA_MAPSCRIPT_PATH)" && cd mapscript/java && ./run_test.sh)
+
test: autotest-install cmakebuild
@$(MAKE) $(MFLAGS) wxs-testcase renderers-testcase misc-testcase gdal-testcase query-testcase mspython-testcase
@./print-test-results.sh
@$(MAKE) $(MFLAGS) php-testcase
+ @$(MAKE) $(MFLAGS) java-testcase
lexer: maplexer.c
View
@@ -85,7 +85,6 @@ static char *ms_errorCodes[MS_NUMERRORCODES] = {"",
"OpenGL renderer error.",
"Renderer error."
};
-
#ifndef USE_THREAD
errorObj *msGetErrorObj()
@@ -1,6 +1,7 @@
import edu.umn.gis.mapscript.mapObj;
import edu.umn.gis.mapscript.OWSRequest;
import edu.umn.gis.mapscript.mapscript;
+import java.io.*;
class WxSTest_thread extends Thread {
@@ -29,6 +30,7 @@ public void run() {
// System.out.println( mapscript.msIO_getStdoutBufferString() );
resultBytes = mapscript.msIO_getStdoutBufferBytes();
+ mapscript.msIO_resetHandlers();
}
}
@@ -54,15 +56,20 @@ public static void main(String[] args) {
if( i == 0 )
{
expectedLength = tt[i].resultBytes.length;
- System.out.println( "Document Length: " + expectedLength + ", expecting somewhere around 10000 or more." );
+ System.out.println( "["+i+"] Document Length: " + expectedLength + ", expecting somewhere around 10000 or more." );
}
else if( expectedLength != tt[i].resultBytes.length )
{
- System.out.println( "Document Length:" + tt[i].resultBytes.length + " Expected:" + expectedLength );
+ System.out.println( "["+i+"] Document Length:" + tt[i].resultBytes.length + " Expected:" + expectedLength );
failure++;
}
else
success++;
+
+ // dump test results to fs for post-mortem inspection
+ FileOutputStream fos = new FileOutputStream("/tmp/wxs_test_"+i);
+ fos.write(tt[i].resultBytes);
+ fos.close();
}
System.out.println( "Successes: " + success );
@@ -0,0 +1,82 @@
+import edu.umn.gis.mapscript.mapObj;
+import edu.umn.gis.mapscript.OWSRequest;
+import edu.umn.gis.mapscript.mapscript;
+import java.io.*;
+
+class WxSTest_nothread {
+
+ public String mapName;
+ public byte[] resultBytes;
+
+ public void run() {
+ mapObj map = new mapObj(mapName);
+
+ map.setMetaData( "ows_onlineresource", "http://dummy.org/" );
+
+ OWSRequest req = new OWSRequest();
+
+ req.setParameter( "SERVICE", "WMS" );
+ req.setParameter( "VERSION", "1.1.0" );
+ req.setParameter( "REQUEST", "GetCapabilities" );
+
+ mapscript.msIO_installStdoutToBuffer();
+
+ int owsResult = map.OWSDispatch( req );
+
+ if( owsResult != 0 )
+ System.out.println( "OWSDispatch Result (expect 0): " + owsResult );
+
+// System.out.println( "Document:" );
+// System.out.println( mapscript.msIO_getStdoutBufferString() );
+
+ resultBytes = mapscript.msIO_getStdoutBufferBytes();
+ mapscript.msIO_resetHandlers();
+ }
+}
+
+public class WxSTestNoThread {
+ public static void main(String[] args) {
+ try {
+ WxSTest_nothread tt[] = new WxSTest_nothread[1];
+ int i;
+ int expectedLength=0, success = 0, failure=0;
+
+ for( i = 0; i < tt.length; i++ )
+ {
+ tt[i] = new WxSTest_nothread();
+ tt[i].mapName = args[0];
+ }
+
+ for( i = 0; i < tt.length; i++ )
+ tt[i].run();
+
+ for( i = 0; i < tt.length; i++ )
+ {
+ if( i == 0 )
+ {
+ expectedLength = tt[i].resultBytes.length;
+ System.out.println( "["+i+"] Document Length: " + expectedLength + ", expecting somewhere around 10000 or more." );
+ }
+ else if( expectedLength != tt[i].resultBytes.length )
+ {
+ System.out.println( "["+i+"] Document Length:" + tt[i].resultBytes.length + " Expected:" + expectedLength );
+ failure++;
+ }
+ else
+ success++;
+
+ // dump test results to fs for post-mortem inspection
+ FileOutputStream fos = new FileOutputStream("/tmp/wxs_test_"+i);
+ fos.write(tt[i].resultBytes);
+ fos.close();
+ }
+
+ System.out.println( "Successes: " + success );
+ System.out.println( "Failures: " + failure );
+
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+}
+
@@ -0,0 +1,23 @@
+#!/bin/sh -ex
+
+JAVA=${JAVA_HOME}/bin/java
+JAVAC=${JAVA_HOME}/bin/javac
+
+${JAVAC} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -d examples/ examples/RFC24.java examples/ConnPool.java examples/DrawMap.java examples/DumpShp.java examples/MakePoint.java examples/QueryByAttribute.java examples/ShapeInfo.java examples/WxSTest.java examples/Metadata.java examples/RunTimeBuiltWMSClient.java examples/WxSTestNoThread.java
+${JAVAC} -encoding utf8 -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -d examples/ examples/QueryByAttributeUnicode.java
+${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} DumpShp ../../tests/point.shp
+${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} ShapeInfo ../../tests/point.shp ../../tests/point.dbf
+${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} DrawMap ../../tests/test.map ./map.png
+${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} ConnPool
+${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} QueryByAttribute ../../tests/test.map
+${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} WxSTest ../../tests/test.map
+${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} WxSTestNoThread ../../tests/test.map
+${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} RFC24 ../../tests/test.map
+LC_ALL=en_US.UTF-8 ${JAVA} -classpath ./:examples/:${JAVA_MAPSCRIPT_SO}/mapscript.jar -Djava.library.path=${JAVA_MAPSCRIPT_SO} QueryByAttributeUnicode data/subset-umlauts.map
+
+${JAVAC} -cp ${JAVA_MAPSCRIPT_SO}/mapscript.jar -d tests/threadtest/ tests/threadtest/*.java
+#-------------------------------------------------------------------------
+# You can use your own map! Copy the following command in your shell
+# and change the file to the map file (the last argument)
+#-------------------------------------------------------------------------
+${JAVA} -Djava.library.path=${JAVA_MAPSCRIPT_SO} -classpath tests/threadtest/:${JAVA_MAPSCRIPT_SO}/mapscript.jar MapTest -t 50 -i 5 ../../tests/test.map
@@ -0,0 +1,31 @@
+import mapscript
+
+map = mapscript.mapObj('../../tests/test.map')
+map.setMetaData( "ows_onlineresource", "http://dummy.org/" )
+ows_req = mapscript.OWSRequest()
+
+ows_req.type = mapscript.MS_GET_REQUEST
+
+ows_req.setParameter( "SERVICE", "WMS" );
+ows_req.setParameter( "VERSION", "1.1.0" );
+ows_req.setParameter( "REQUEST", "GetCapabilities" );
+
+mapscript.msIO_installStdoutToBuffer()
+dispatch_status = map.OWSDispatch(ows_req)
+if dispatch_status:
+ status = '200 OK'
+else:
+ status = '500 Internal Server Error'
+content_type = mapscript.msIO_stripStdoutBufferContentType()
+mapscript.msIO_stripStdoutBufferContentHeaders()
+result = mapscript.msIO_getStdoutBufferBytes()
+
+try:
+ # MapServer 6.0:
+ mapscript.msCleanup()
+except:
+ # MapServer 6.1:
+ mapscript.msCleanup(1)
+
+response_headers = [('Content-Type', content_type),
+ ('Content-Length', str(len(result)))]
View
@@ -67,6 +67,7 @@ extern "C" {
#define TLOCK_OGR 14
#define TLOCK_TIME 15
#define TLOCK_FRIBIDI 16
+#define TLOCK_WxS 17
#define TLOCK_STATIC_MAX 20
#define TLOCK_MAX 100
View
@@ -31,6 +31,7 @@
#include "mapserver.h"
#include "maperror.h"
+#include "mapthread.h"
#include "mapgml.h"
#include <ctype.h>
#include "maptemplate.h"
@@ -4927,7 +4928,10 @@ int msWMSDispatch(mapObj *map, cgiRequestObj *req, owsRequestObj *ows_request, i
msSetError(MS_WMSERR, "WMS request not enabled. Check wms/ows_enable_request settings.", "msWMSGetCapabilities()");
return msWMSException(map, nVersion, NULL, wms_exception_format);
}
- return msWMSGetCapabilities(map, nVersion, req, ows_request, updatesequence, wms_exception_format, language);
+ msAcquireLock(TLOCK_WxS);
+ status=msWMSGetCapabilities(map, nVersion, req, ows_request, updatesequence, wms_exception_format, language);
+ msReleaseLock(TLOCK_WxS);
+ return status;
} else if (request && (strcasecmp(request, "context") == 0 ||
strcasecmp(request, "GetContext") == 0) ) {
/* Return a context document with all layers in this mapfile

0 comments on commit 54ef04b

Please sign in to comment.