Examples of throwOnError()


Examples of com.mongodb.CommandResult.throwOnError()

    }

    @Test
    public void testServerStatus() throws Exception {
        CommandResult serverStatus = readOnlyClient.getDB("admin").command("serverStatus");
        serverStatus.throwOnError();
    }

    @Test
    public void testCurrentOperations() throws Exception {
        DBObject currentOperations = readOnlyClient.getDB("admin").getCollection("$cmd.sys.inprog").findOne();
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

    }

    @Test
    public void testStats() throws Exception {
        CommandResult stats = readOnlyClient.getDB("testdb").getStats();
        stats.throwOnError();
        assertThat(((Number) stats.get("objects")).longValue()).isEqualTo(1);
    }

    @Test
    public void testListDatabaseNames() throws Exception {
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

        assertThat(stats.getErrorMessage()).isEqualTo("ns not found");

        collection.insert(json("{}"));
        collection.insert(json("abc: 'foo'"));
        stats = collection.getStats();
        stats.throwOnError();
        assertThat(((Number) stats.get("count")).longValue()).isEqualTo(2);
        assertThat(((Number) stats.get("size")).longValue()).isEqualTo(57);
        assertThat(((Number) stats.get("avgObjSize")).doubleValue()).isEqualTo(28.5);
    }
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

    }

    @Test
    public void testGetLogStartupWarnings() throws Exception {
        CommandResult startupWarnings = client.getDB("admin").command(json("getLog: 'startupWarnings'"));
        startupWarnings.throwOnError();
        assertThat(startupWarnings.get("totalLinesWritten")).isEqualTo(0);
        assertThat(startupWarnings.get("log")).isEqualTo(Collections.emptyList());
    }

    @Test
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

    @Test
    public void testGetLogWhichDoesNotExist() throws Exception {
        CommandResult startupWarnings = client.getDB("admin").command(json("getLog: 'illegal'"));
        try {
            startupWarnings.throwOnError();
            fail("CommandFailureException expected");
        } catch (CommandFailureException e) {
            assertThat(e.getMessage()).contains("no RamLog");
        }
    }
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

    }

    @Test
    public void testDatabaseStats() throws Exception {
        CommandResult stats = db.getStats();
        stats.throwOnError();
        assertThat(((Number) stats.get("objects")).longValue()).isEqualTo(1);
        assertThat(((Number) stats.get("collections")).longValue()).isEqualTo(1);
        assertThat(((Number) stats.get("indexes")).longValue()).isEqualTo(0);
        assertThat(((Number) stats.get("dataSize")).longValue()).isEqualTo(37);
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

        db.getCollection("foo").insert(json("{}"));
        db.getCollection("foo").insert(json("{}"));
        db.getCollection("bar").insert(json("{}"));

        stats = db.getStats();
        stats.throwOnError();

        assertThat(((Number) stats.get("objects")).longValue()).isEqualTo(8);
        assertThat(((Number) stats.get("collections")).longValue()).isEqualTo(3);
        assertThat(((Number) stats.get("indexes")).longValue()).isEqualTo(2);
        assertThat(((Number) stats.get("dataSize")).longValue()).isEqualTo(271);
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

        assertThat(collection.findOne()).isEqualTo(json("_id: 1"));

        CommandResult result = db.command(cmd);
        try {
            result.throwOnError();
            fail("MongoException expected");
        } catch (MongoException e) {
            assertThat(e.getCode()).isEqualTo(10148);
            assertThat(e.getMessage()).contains("Mod on _id not allowed");
        }
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

    @Test
    public void testServerStatus() throws Exception {
        Date before = new Date();
        CommandResult serverStatus = command("serverStatus");
        serverStatus.throwOnError();
        assertThat(serverStatus.get("uptime")).isInstanceOf(Number.class);
        assertThat(serverStatus.get("uptimeMillis")).isInstanceOf(Long.class);
        Date serverTime = (Date) serverStatus.get("localTime");
        assertThat(serverTime).isNotNull();
        assertThat(serverTime.after(new Date())).isFalse();
View Full Code Here

Examples of com.mongodb.CommandResult.throwOnError()

    @Test
    public void testWhatsMyUri() throws Exception {
        for (String dbname : new String[] { "admin", "local", "test" }) {
            CommandResult result = client.getDB(dbname).command("whatsmyuri");
            result.throwOnError();
            assertThat(result.ok()).isTrue();
            assertThat(result.get("you")).isNotNull();
            assertThat(result.get("you").toString()).startsWith("127.0.0.1:");
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.