Search in sources :

Example 66 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class CommandResultTest method testNullErrorCode.

@Test
public void testNullErrorCode() throws UnknownHostException {
    try {
        new CommandResult(new BsonDocument("ok", new BsonInt32(0)), new ServerAddress()).throwOnError();
        fail("Should throw");
    } catch (MongoCommandException e) {
        assertEquals(-1, e.getCode());
    }
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) Test(org.junit.Test)

Example 67 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class CommandResultTest method shouldBeOkWhenOkFieldIsOne.

@Test
public void shouldBeOkWhenOkFieldIsOne() throws UnknownHostException {
    CommandResult commandResult = new CommandResult(new BsonDocument("ok", new BsonDouble(1.0)));
    assertTrue(commandResult.ok());
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDouble(org.bson.BsonDouble) Test(org.junit.Test)

Example 68 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class CommandResultTest method shouldNotBeOkWhenOkFieldTypeIsNotBooleanOrNumber.

@Test
public void shouldNotBeOkWhenOkFieldTypeIsNotBooleanOrNumber() throws UnknownHostException {
    CommandResult commandResult = new CommandResult(new BsonDocument("ok", new BsonString("1")));
    assertFalse(commandResult.ok());
}
Also used : BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) Test(org.junit.Test)

Example 69 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class CommandResultTest method shouldBeOkWhenOkFieldIsTrue.

@Test
public void shouldBeOkWhenOkFieldIsTrue() throws UnknownHostException {
    CommandResult commandResult = new CommandResult(new BsonDocument("ok", BsonBoolean.TRUE));
    assertTrue(commandResult.ok());
}
Also used : BsonDocument(org.bson.BsonDocument) Test(org.junit.Test)

Example 70 with BsonDocument

use of org.bson.BsonDocument in project drill by apache.

the class MongoRecordReader method next.

@Override
public int next() {
    if (cursor == null) {
        logger.info("Filters Applied : " + filters);
        logger.info("Fields Selected :" + fields);
        cursor = collection.find(filters).projection(fields).batchSize(100).iterator();
    }
    writer.allocate();
    writer.reset();
    int docCount = 0;
    Stopwatch watch = Stopwatch.createStarted();
    try {
        while (docCount < BaseValueVector.INITIAL_VALUE_ALLOCATION && cursor.hasNext()) {
            writer.setPosition(docCount);
            if (isBsonRecordReader) {
                BsonDocument bsonDocument = cursor.next();
                bsonReader.write(writer, new BsonDocumentReader(bsonDocument));
            } else {
                String doc = cursor.next().toJson();
                jsonReader.setSource(doc.getBytes(Charsets.UTF_8));
                jsonReader.write(writer);
            }
            docCount++;
        }
        if (isBsonRecordReader) {
            bsonReader.ensureAtLeastOneField(writer);
        } else {
            jsonReader.ensureAtLeastOneField(writer);
        }
        writer.setValueCount(docCount);
        logger.debug("Took {} ms to get {} records", watch.elapsed(TimeUnit.MILLISECONDS), docCount);
        return docCount;
    } catch (IOException e) {
        String msg = "Failure while reading document. - Parser was at record: " + (docCount + 1);
        logger.error(msg, e);
        throw new DrillRuntimeException(msg, e);
    }
}
Also used : BsonDocument(org.bson.BsonDocument) Stopwatch(com.google.common.base.Stopwatch) BsonDocumentReader(org.bson.BsonDocumentReader) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Aggregations

BsonDocument (org.bson.BsonDocument)169 BsonString (org.bson.BsonString)53 BsonValue (org.bson.BsonValue)37 Test (org.junit.Test)36 BsonArray (org.bson.BsonArray)29 BsonInt32 (org.bson.BsonInt32)28 ArrayList (java.util.ArrayList)24 BsonDocumentReader (org.bson.BsonDocumentReader)17 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)14 BsonDocumentWriter (org.bson.BsonDocumentWriter)14 BsonInt64 (org.bson.BsonInt64)14 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)10 BsonDouble (org.bson.BsonDouble)8 Document (org.bson.Document)7 MongoNamespace (com.mongodb.MongoNamespace)6 Before (org.junit.Before)6 MongoGridFSException (com.mongodb.MongoGridFSException)5 BsonObjectId (org.bson.BsonObjectId)5 BsonWriter (org.bson.BsonWriter)5 ObjectId (org.bson.types.ObjectId)5