Question

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).

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top