use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class CrudTest method setUp.
@Before
@Override
public void setUp() {
super.setUp();
collection = Fixture.initializeCollection(new MongoNamespace(getDefaultDatabaseName(), getClass().getName())).withDocumentClass(BsonDocument.class);
new MongoOperation<Void>() {
@Override
public void execute() {
List<BsonDocument> documents = new ArrayList<BsonDocument>();
for (BsonValue document : data) {
documents.add(document.asDocument());
}
collection.insertMany(documents, getCallback());
}
}.get();
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class CollectionAcceptanceTest method shouldBeAbleToRenameCollectionToAnExistingCollectionNameAndReplaceItWhenDropIsTrue.
@Test
public void shouldBeAbleToRenameCollectionToAnExistingCollectionNameAndReplaceItWhenDropIsTrue() {
//given
String existingCollectionName = "anExistingCollection";
String keyInOriginalCollection = "someKey";
String valueInOriginalCollection = "someValue";
collection.insertOne(new Document(keyInOriginalCollection, valueInOriginalCollection));
MongoCollection<Document> existingCollection = database.getCollection(existingCollectionName);
String keyInExistingCollection = "aDifferentDocument";
String valueInExistingCollection = "withADifferentValue";
existingCollection.insertOne(new Document(keyInExistingCollection, valueInExistingCollection));
assertThat(database.listCollectionNames().into(new ArrayList<String>()).contains(getCollectionName()), is(true));
assertThat(database.listCollectionNames().into(new ArrayList<String>()).contains(existingCollectionName), is(true));
//when
collection.renameCollection(new MongoNamespace(getDatabaseName(), existingCollectionName), new RenameCollectionOptions().dropTarget(true));
//then
assertThat(database.listCollectionNames().into(new ArrayList<String>()).contains(getCollectionName()), is(false));
assertThat(database.listCollectionNames().into(new ArrayList<String>()).contains(existingCollectionName), is(true));
MongoCollection<Document> replacedCollection = database.getCollection(existingCollectionName);
assertThat(replacedCollection.find().first().get(keyInExistingCollection), is(nullValue()));
assertThat(replacedCollection.find().first().get(keyInOriginalCollection).toString(), is(valueInOriginalCollection));
}
use of com.mongodb.MongoNamespace in project incubator-skywalking by apache.
the class MongoDBMethodInterceptorTest method setUp.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setUp() throws Exception {
interceptor = new MongoDBMethodInterceptor();
Config.Plugin.MongoDB.TRACE_PARAM = true;
when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017");
BsonDocument document = new BsonDocument();
document.append("name", new BsonString("by"));
MongoNamespace mongoNamespace = new MongoNamespace("test.user");
Decoder decoder = PowerMockito.mock(Decoder.class);
FindOperation findOperation = new FindOperation(mongoNamespace, decoder);
findOperation.filter(document);
arguments = new Object[] { findOperation };
argumentTypes = new Class[] { findOperation.getClass() };
}
use of com.mongodb.MongoNamespace in project engine by Lumeer.
the class MongoDbStorage method renameCollection.
@Override
public void renameCollection(final String oldCollectionName, final String newCollectionName) {
if (getCollectionCache() != null) {
collectionCacheRef.get().lock(COLLECTION_CACHE);
try {
final List<String> collections = getCollectionCache();
if (collections != null) {
collections.remove(oldCollectionName);
collections.add(newCollectionName);
}
if (hasCollection(oldCollectionName)) {
database.getCollection(oldCollectionName).renameCollection(new MongoNamespace(database.getName(), newCollectionName));
}
} finally {
collectionCacheRef.get().unlock(COLLECTION_CACHE);
}
} else {
if (hasCollection(oldCollectionName)) {
database.getCollection(oldCollectionName).renameCollection(new MongoNamespace(database.getName(), newCollectionName));
}
}
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class CommandMonitoringTest method setUp.
@Before
public void setUp() {
assumeFalse(skipTest);
List<BsonDocument> documents = new ArrayList<BsonDocument>();
for (BsonValue document : data) {
documents.add(document.asDocument());
}
CollectionHelper<Document> collectionHelper = new CollectionHelper<Document>(new DocumentCodec(), new MongoNamespace(databaseName, collectionName));
collectionHelper.drop();
if (!documents.isEmpty()) {
collectionHelper.insertDocuments(documents);
}
commandListener.reset();
MongoDatabase database = mongoClient.getDatabase(databaseName);
collection = database.getCollection(collectionName, BsonDocument.class);
if (definition.getDocument("operation").containsKey("read_preference")) {
collection = collection.withReadPreference(ReadPreference.valueOf(definition.getDocument("operation").getDocument("read_preference").getString("mode").getValue()));
}
helper = new JsonPoweredCrudTestHelper(description, database, collection);
}
Aggregations