MongoDB 和 Play!框架行为不一致

发布于 2024-12-19 22:27:05 字数 1348 浏览 0 评论 0原文

我在测试中有一些代码如下:

    @Test
public void testRetrieveMongoDBFailUnkownHost()
{   
    //Set up test port and host on DSMongo
    MyMongo mongoTest = new MyMongo();
    mongoTest.setHost("failure");
    mongoTest.setPort("0");

    //attempt to make the connection
    try
    {
        mongoTest.attemptMongoConnection();
        assertTrue(false);
    }
    catch (Exception e) 
    {
        assertEquals("Incorrect error message received: " + e.getMessage(),"Error (3013) : Unknown database host.", e.getMessage());
    }

}

尝试 MongoConnection() 方法运行新的 Mongo(host, port) 方法,该方法应该因未知主机异常而失败。它在我的机器上没有失败(无论我输入什么字符串而不是失败),但它在我同事的机器上失败了。因此,测试在我的机器上失败并通过了他的机器(即他得到了异常)。任何想法都会让我难住!

谢谢

Paul

编辑:尝试连接方法中的代码是

 */
public static void attemptMongoConnection() throws MYException 
{
    try {           
        singleMongo = new Mongo(getHost(), getPort());
        Logger.debug("Retrieved Mongo database from " + host);
    } catch (UnknownHostException e) {
        Logger.error("Unknown Host Exception", e);
        throw new MYException(MYMessage.MY_UNKNOWN_HOST);
    } catch (MongoException e) {
        Logger.error("Mongo error", e);
        throw new MYException(MYMessage.DS_MONGO_ERROR);
    }
}

singleMOngo 是 Mongo 变量, getHost 和 getPort 是我们设置的(即失败和 0)。

I have some code in a test as follows:

    @Test
public void testRetrieveMongoDBFailUnkownHost()
{   
    //Set up test port and host on DSMongo
    MyMongo mongoTest = new MyMongo();
    mongoTest.setHost("failure");
    mongoTest.setPort("0");

    //attempt to make the connection
    try
    {
        mongoTest.attemptMongoConnection();
        assertTrue(false);
    }
    catch (Exception e) 
    {
        assertEquals("Incorrect error message received: " + e.getMessage(),"Error (3013) : Unknown database host.", e.getMessage());
    }

}

And the attempt MongoConnection() method runs the new Mongo(host, port) method which should fail with an unknown host exception. It isn't failing on my machine (no matter what string I put in instead of failure) but it is failing on my colleagues machine. So the test fails on my machine and passes on his (i.e. he gets the exception). Any ideas cause I am stumped!

Thanks

Paul

EDIT: The code in the attempt Connection Method is

 */
public static void attemptMongoConnection() throws MYException 
{
    try {           
        singleMongo = new Mongo(getHost(), getPort());
        Logger.debug("Retrieved Mongo database from " + host);
    } catch (UnknownHostException e) {
        Logger.error("Unknown Host Exception", e);
        throw new MYException(MYMessage.MY_UNKNOWN_HOST);
    } catch (MongoException e) {
        Logger.error("Mongo error", e);
        throw new MYException(MYMessage.DS_MONGO_ERROR);
    }
}

where singleMOngo is a Mongo variable and the getHost and getPort are the ones we have set (.e. failure and 0).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晒暮凉 2024-12-26 22:27:05

我发现这是 DNS 某处的问题。当我在家里运行它时(从我最初发布帖子的地方)它失败了,并且似乎已经解决了“失败”的名称,因此当我输入“localhost_123”之类的内容时,它工作得很好。

今天早上我走进办公室,它再次出现“故障”。因此,做一些进一步的挖掘,似乎我的路由器或家里的某个东西正在将“故障”解决到它知道的地址,而该地址不存在于办公室的网络上。

感谢所有看过这篇文章的人。很奇怪。

I have found this was a problem with the DNS somewhere. When I ran it at home (from where I originally made the post) it failed and seems to hav been resolving the name of "failure" so when I instead entered something like "localhost_123" it works perfectly.

I have come into the office this morning and it works with "failure" again. Doing some further digging it seems therefore that my router or something at home is resolving "failure" to an address it is aware of which is not present on the network here in the office.

Thanks for all those who looked at this. Very bizarre.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文