Search in sources :

Example 1 with BsonInt32

use of com.eightkdata.mongowp.bson.BsonInt32 in project torodb by torodb.

the class OplogTestParser method getOps.

private static List<OplogOperation> getOps(BsonDocument doc) {
    BsonValue<?> oplogValue = doc.get("oplog");
    if (oplogValue == null) {
        throw new AssertionError("Does not contain oplog");
    }
    AtomicInteger tsFactory = new AtomicInteger();
    AtomicInteger tFactory = new AtomicInteger();
    BsonInt32 twoInt32 = DefaultBsonValues.newInt(2);
    return oplogValue.asArray().asList().stream().map(BsonValue::asDocument).map(child -> {
        BsonDocumentBuilder builder = new BsonDocumentBuilder(child);
        if (child.get("ts") == null) {
            builder.appendUnsafe("ts", DefaultBsonValues.newTimestamp(tsFactory.incrementAndGet(), tFactory.incrementAndGet()));
        }
        if (child.get("h") == null) {
            builder.appendUnsafe("h", DefaultBsonValues.INT32_ONE);
        }
        if (child.get("v") == null) {
            builder.appendUnsafe("v", twoInt32);
        }
        return builder.build();
    }).map(child -> {
        try {
            return OplogOperationParser.fromBson(child);
        } catch (MongoException ex) {
            throw new AssertionError("Invalid oplog operation", ex);
        }
    }).collect(Collectors.toList());
}
Also used : java.util(java.util) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) Truth(com.google.common.truth.Truth) KvValue(com.torodb.kvdocument.values.KvValue) BsonValue(com.eightkdata.mongowp.bson.BsonValue) OplogOperation(com.eightkdata.mongowp.server.api.oplog.OplogOperation) MongoWpConverter(com.torodb.kvdocument.conversion.mongowp.MongoWpConverter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TorodTransaction(com.torodb.torod.TorodTransaction) BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder) MongoException(com.eightkdata.mongowp.exceptions.MongoException) DefaultBsonValues(com.eightkdata.mongowp.bson.utils.DefaultBsonValues) MongoBsonTranslator(com.eightkdata.mongowp.bson.org.bson.utils.MongoBsonTranslator) OplogOperationParser(com.torodb.mongodb.commands.pojos.OplogOperationParser) Charsets(com.google.common.base.Charsets) Files(java.nio.file.Files) BsonInt32(com.eightkdata.mongowp.bson.BsonInt32) KvDocument(com.torodb.kvdocument.values.KvDocument) Collectors(java.util.stream.Collectors) WriteMongodTransaction(com.torodb.mongodb.core.WriteMongodTransaction) Stream(java.util.stream.Stream) java.io(java.io) Paths(java.nio.file.Paths) ReadOnlyMongodTransaction(com.torodb.mongodb.core.ReadOnlyMongodTransaction) Assert(org.junit.Assert) BsonInt32(com.eightkdata.mongowp.bson.BsonInt32) MongoException(com.eightkdata.mongowp.exceptions.MongoException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder)

Aggregations

BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)1 BsonInt32 (com.eightkdata.mongowp.bson.BsonInt32)1 BsonValue (com.eightkdata.mongowp.bson.BsonValue)1 MongoBsonTranslator (com.eightkdata.mongowp.bson.org.bson.utils.MongoBsonTranslator)1 DefaultBsonValues (com.eightkdata.mongowp.bson.utils.DefaultBsonValues)1 MongoException (com.eightkdata.mongowp.exceptions.MongoException)1 OplogOperation (com.eightkdata.mongowp.server.api.oplog.OplogOperation)1 BsonDocumentBuilder (com.eightkdata.mongowp.utils.BsonDocumentBuilder)1 Charsets (com.google.common.base.Charsets)1 Truth (com.google.common.truth.Truth)1 MongoWpConverter (com.torodb.kvdocument.conversion.mongowp.MongoWpConverter)1 KvDocument (com.torodb.kvdocument.values.KvDocument)1 KvValue (com.torodb.kvdocument.values.KvValue)1 OplogOperationParser (com.torodb.mongodb.commands.pojos.OplogOperationParser)1 ReadOnlyMongodTransaction (com.torodb.mongodb.core.ReadOnlyMongodTransaction)1 WriteMongodTransaction (com.torodb.mongodb.core.WriteMongodTransaction)1 TorodTransaction (com.torodb.torod.TorodTransaction)1 java.io (java.io)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1