无法启动嵌入式Google App Engine服务器进行集成测试

时间:2012-11-12 08:19:38

标签: java google-app-engine maven integration-testing

我正在尝试在由maven failsafe插件运行的测试套件的@BeforeClass中启动嵌入式Google App Engine开发服务器(sdk 1.7.3)。应该启动它的代码如下所示:

private static final String HOST = "0.0.0.0";
private static final int PORT = 8887;
private static DevAppServer devAppServer;


@BeforeClass
public static void setup() throws Exception {
    log.debug("Starting development server");
    File appRootDir = new File("target/visualize-1.0.war");
    DevAppServerFactory devAppServerFactory = new DevAppServerFactory();
    devAppServer = devAppServerFactory.createDevAppServer(appRootDir, HOST, PORT); 
    devAppServer.start();
}

但是在调用createDevAppServer期间,我收到了一个安全异常:

java.security.AccessControlException: access denied (java.lang.RuntimePermission setContextClassLoader)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.Thread.setContextClassLoader(Thread.java:1394)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:366)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)

使用-Djava.security.debug = access调试安全性异常,我看到失败:

  access: access allowed (java.io.FilePermission    /home/me/.m2/repository/com/google/appengine/appengine-tools-sdk/1.7.3/appengine-tools-sdk-1.7.3.jar read)
 access: access denied (java.security.SecurityPermission getPolicy)
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1249)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:364)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.security.Policy.getPolicy(Policy.java:133)
at com.google.apphosting.utils.security.SecurityManagerInstaller.install(SecurityManagerInstaller.java:81)
at com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:152)
at com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:69)
at com.google.appengine.tools.development.DevAppServerFactory.createDevAppServer(DevAppServerFactory.java:53)

我做错了什么?

1 个答案:

答案 0 :(得分:2)

实际上,你不应该按照你的方式打电话给GAE(提示:GAE有很多补丁来处理安全问题,这根本不值得)

然而,maven-gae-plugin确实有gae:start和gae:专门针对IT停止。

这就是我将它用于IT的方式:

<plugin>
    <groupId>net.kindleit</groupId>
    <artifactId>maven-gae-plugin</artifactId>
    <version>0.9.4</version>
    <dependencies>
        <dependency>
            <groupId>net.kindleit</groupId>
            <artifactId>gae-runtime</artifactId>
            <version>1.6.6</version>
            <type>pom</type>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>start-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-integration-test</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.12</version>
    <executions>
        <execution>
            <id>it</id>
            <phase>integration-test</phase>
            <goals>
                <goal>integration-test</goal>
            </goals>
        </execution>
    </executions>
</plugin>