Package com.mongodb

Examples of com.mongodb.CommandResult


        assertThat(startupWarnings.get("log")).isEqualTo(Collections.emptyList());
    }

    @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


        assertThat(currentOperations.get("inprog")).isInstanceOf(List.class);
    }

    @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);

        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

    }

    @Test
    public void testFindAndModifyCommandEmpty() throws Exception {
        DBObject cmd = new BasicDBObject("findandmodify", collection.getName());
        CommandResult result = db.command(cmd);
        assertThat(result.getErrorMessage()).isEqualTo("need remove or update");
        assertThat(result.ok()).isFalse();
    }
View Full Code Here

        cmd.put("query", json("_id: 1"));
        cmd.put("update", new BasicDBObject("$inc", json("_id: 1")));

        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

        DBObject cmd = new BasicDBObject("findAndModify", collection.getName());
        cmd.put("query", json("_id: 1"));
        cmd.put("update", json("$inc: {a: 1}"));

        CommandResult result = db.command(cmd);
        assertThat(result.get("lastErrorObject")).isEqualTo(json("updatedExisting: true, n: 1"));

        assertThat(collection.findOne()).isEqualTo(json("_id: 1, a: 1"));
        assertThat(result.ok()).isTrue();
    }
View Full Code Here

    }

    @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();
        assertThat(before.after(serverTime)).isFalse();

        BSONObject connections = (BSONObject) serverStatus.get("connections");
        assertThat(connections.get("current")).isNotNull();
    }
View Full Code Here

        assertThat(connections.get("current")).isNotNull();
    }

    @Test
    public void testReplSetGetStatus() throws Exception {
        CommandResult result = command("replSetGetStatus");
        assertThat(result.ok()).isFalse();
        assertThat(result.getErrorMessage()).isEqualTo("not running with --replSet");
    }
View Full Code Here

    }

    @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

        assertThat(actual).isEqualTo(expected);
    }

    @Test
    public void testIsMaster() throws Exception {
        CommandResult isMaster = db.command("isMaster");
        assertThat(isMaster.ok()).isTrue();
        assertThat(isMaster.getBoolean("ismaster")).isTrue();
        assertThat(isMaster.getDate("localTime")).isInstanceOf(Date.class);
        assertThat(isMaster.getInt("maxBsonObjectSize")).isGreaterThan(1000);
        assertThat(isMaster.getInt("maxMessageSizeBytes")).isGreaterThan(isMaster.getInt("maxBsonObjectSize"));
    }
View Full Code Here

                    must(QueryBuilders.rangeQuery("_uid").lte("document_index#" + lessThanId.toString()));
       
      }//TESTED
      indexManager.doDeleteByQuery(soloOrCombinedQuery);           
     
      CommandResult result = DbManager.getDocument().getLastError("metadata");
      return result.getLong("n", 0);
     
    } catch (Exception e) {
      // If an exception occurs log the error
      logger.error("Exception Message: " + e.getMessage(), e);     
    }
View Full Code Here

TOP

Related Classes of com.mongodb.CommandResult

Copyright © 2018 www.massapicom. 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.