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) 方法,该方法应该因未知主机异常而失败。它在我的机器上没有失败(无论我输入什么字符串而不是失败),但它在我的同事机器上失败了。所以测试在我的机器上失败并通过了他的(即他得到了异常)。任何想法都会让我难过!

谢谢

保罗

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

 */
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)。

4

1 回答 1

1

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.

于 2011-12-07T09:46:55.210 回答