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());
}
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations