【问题标题】:Why is SystemProperty.environment.value() returning null in Google App Engine?为什么 SystemProperty.environment.value() 在 Google App Engine 中返回 null?
【发布时间】:2013-10-26 15:42:56
【问题描述】:

我有一个从 SystemProperty.environment.value() 和 SystemProperty 的所有其他静态成员返回 null 的 Google App Engine Java 应用程序。我在通过 Maven 运行 JUnit 测试时看到了这一点。

import com.google.appengine.api.utils.SystemProperty;
...
void printProps() {
    log.info("props:" + System.getProperties());
    log.info("env=" + SystemProperty.environment.value());
    log.info("log=" + System.getProperty("java.util.logging.config.file"));
    log.info("id=" + SystemProperty.applicationId.get());
    log.info("ver=" + SystemProperty.applicationVersion.get());
}

上面唯一返回非 null 的项是 System.getProperties()。

以下是我设置的一些细节:

  • IntelliJ IDEA EAP 13
  • 马文
  • App Engine SDK 1.8.5
  • Java 7 (1.7.0_40)
  • JUnit 4

【问题讨论】:

  • 我可以根据需要提供有关我的设置和代码的更多详细信息,但我不确定此时还要发布什么。我想我正在寻找有关检查内容的建议。
  • 在开发服务器上部署它并投入生产后,我发现环境在那里并且很好。我想对于我的 JUnit 测试,我负责自己提供环境。我将重新阅读 JUnit with App Engine 的文档,以了解我需要做什么。

标签: java google-app-engine maven junit


【解决方案1】:

我遇到了同样的问题。我试图在 LocalServiceTestHelper 上调用这些方法,但这些方法没有填充 SystemProperty.applicationId 或 SystemProperty.version

setEnvAppId(java.lang.String envAppId) 
setEnvVersionId(java.lang.String envVersionId)

例如

public final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(), new LocalTaskQueueTestConfig() ).setEnvAppId("JUnitApplicationId").setEnvVersionId("JUnitVersion");

我的解决方案是自己在我的 JUnit setUp() 方法中填充这些属性:

@Before
public void setUp() throws Exception {
    SystemProperty.version.set("JUnitVersion");
    SystemProperty.applicationId.set("JUnitApplicationId");
    SystemProperty.applicationVersion.set("JUnitApplicationVersion");
    SystemProperty.environment.set( SystemProperty.Environment.Value.Development );
    helper.setUp();
    datastore = DatastoreServiceFactory.getDatastoreService();
    queue = QueueFactory.getDefaultQueue();
}

请注意,SystemProperty.Environment 的唯一有效值是静态最终值 Production 和 Development。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-28
    • 1970-01-01
    • 2010-12-28
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多