本文整理汇总了Java中com.github.fakemongo.Fongo类的典型用法代码示例。如果您正苦于以下问题:Java Fongo类的具体用法?Java Fongo怎么用?Java Fongo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Fongo类属于com.github.fakemongo包,在下文中一共展示了Fongo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.github.fakemongo.Fongo; //导入依赖的package包/类
public static void main(String[] args) {
try {
PersistenceUnit.setInstance(new FakePersister(new Fongo("mongo server test")));
final EventPersister persister = PersistenceUnit.getInstance();
MessageHandler defaultHandler = new MessageHandler() {
public void handleMessage(String message) {
logger.log(Level.INFO, "Received:" + message);
persister.persist(message, Constants.DB_NAME, Constants.NORSE_DB_COLLECTION_NAME);
}
};
SocketClientEndpoint endpoint = new WebsocketClientEndpoint(
new URI(Constants.NORSE_WEBSOCKET_URL));
endpoint.addMessageHandler(defaultHandler);
EventCollectorThread norseCollector = new EventCollectorThread(endpoint);
norseCollector.run();
} catch (UnknownHostException ex) {
logger.log(Level.SEVERE, "EventCollector failed with UnknownHostException: ", ex);
} catch (URISyntaxException e) {
logger.log(Level.SEVERE, "EventCollector failed with URISyntaxException: ", e);
}
}
示例2: shouldUseDifferentHosts
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldUseDifferentHosts() throws Exception {
// Given
final TestData tenant1 = new TestData();
tenant1.setId("1");
tenant1.setValue("tenant1");
final TestData tenant2 = new TestData();
tenant2.setId("1");
tenant2.setValue("tenant2");
// When
changeTenant("tenant1");
changeHost("tenant1Host");
testRepository.insert(tenant1);
changeTenant("tenant2");
changeHost("tenant2Host");
testRepository.insert(tenant2);
// Then
final Map<String, Fongo> instances = TestMultiTenantConfiguration.getFongoInstances();
assertEquals(2, instances.size());
}
示例3: mongoClientProvider
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Bean
public MongoClientProvider mongoClientProvider() {
return new MongoClientProvider() {
@Override
public MongoClient get(TenantInformationProvider provider) {
final String name = provider.getDatabaseURI().getURI();
fongoInstances.computeIfAbsent(name, Fongo::new);
return fongoInstances.get(name).getMongo();
}
@Override
public void close() throws IOException {
for (Map.Entry<String, Fongo> entry : fongoInstances.entrySet()) {
entry.getValue().getMongo().close();
}
fongoInstances.clear();
}
};
}
示例4: init
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Before
public void init() throws MongobeeException, UnknownHostException {
fakeDb = new Fongo("testServer").getDB("mongobeetest");
fakeMongoDatabase = new Fongo("testServer").getDatabase("mongobeetest");
when(dao.connectMongoDb(any(MongoClientURI.class), anyString()))
.thenReturn(fakeMongoDatabase);
when(dao.getDb()).thenReturn(fakeDb);
when(dao.getMongoDatabase()).thenReturn(fakeMongoDatabase);
doCallRealMethod().when(dao).save(any(ChangeEntry.class));
doCallRealMethod().when(dao).setChangelogCollectionName(anyString());
doCallRealMethod().when(dao).setIndexDao(any(ChangeEntryIndexDao.class));
dao.setIndexDao(indexDao);
dao.setChangelogCollectionName(CHANGELOG_COLLECTION_NAME);
runner.setDbName("mongobeetest");
runner.setEnabled(true);
runner.setChangeLogsScanPackage(MongobeeTestResource.class.getPackage().getName());
}
示例5: shouldGetLockWhenPreviouslyHeldAndReleased
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldGetLockWhenPreviouslyHeldAndReleased() throws Exception {
// given
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
LockDao dao = new LockDao(LOCK_COLLECTION_NAME);
dao.intitializeLock(db);
// when
dao.acquireLock(db);
dao.releaseLock(db);
boolean hasLock = dao.acquireLock(db);
// then
assertTrue(hasLock);
}
示例6: releaseLockShouldBeIdempotent
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void releaseLockShouldBeIdempotent() {
// given
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
LockDao dao = new LockDao(LOCK_COLLECTION_NAME);
dao.intitializeLock(db);
// when
dao.releaseLock(db);
dao.releaseLock(db);
boolean hasLock = dao.acquireLock(db);
// then
assertTrue(hasLock);
}
示例7: shouldCreateChangeIdAuthorIndexIfNotFound
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldCreateChangeIdAuthorIndexIfNotFound() throws MongobeeConfigurationException {
// given
ChangeEntryDao dao = new ChangeEntryDao(CHANGELOG_COLLECTION_NAME, LOCK_COLLECTION_NAME);
MongoClient mongoClient = mock(MongoClient.class);
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
when(mongoClient.getDatabase(anyString())).thenReturn(db);
ChangeEntryIndexDao indexDaoMock = mock(ChangeEntryIndexDao.class);
when(indexDaoMock.findRequiredChangeAndAuthorIndex(db)).thenReturn(null);
dao.setIndexDao(indexDaoMock);
// when
dao.connectMongoDb(mongoClient, DB_NAME);
//then
verify(indexDaoMock, times(1)).createRequiredUniqueIndex(any(FongoMongoCollection.class));
// and not
verify(indexDaoMock, times(0)).dropIndex(any(FongoMongoCollection.class), any(Document.class));
}
示例8: shouldNotCreateChangeIdAuthorIndexIfFound
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldNotCreateChangeIdAuthorIndexIfFound() throws MongobeeConfigurationException {
// given
MongoClient mongoClient = mock(MongoClient.class);
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
when(mongoClient.getDatabase(anyString())).thenReturn(db);
ChangeEntryDao dao = new ChangeEntryDao(CHANGELOG_COLLECTION_NAME, LOCK_COLLECTION_NAME);
ChangeEntryIndexDao indexDaoMock = mock(ChangeEntryIndexDao.class);
when(indexDaoMock.findRequiredChangeAndAuthorIndex(db)).thenReturn(new Document());
when(indexDaoMock.isUnique(any(Document.class))).thenReturn(true);
dao.setIndexDao(indexDaoMock);
// when
dao.connectMongoDb(mongoClient, DB_NAME);
//then
verify(indexDaoMock, times(0)).createRequiredUniqueIndex(db.getCollection(CHANGELOG_COLLECTION_NAME));
// and not
verify(indexDaoMock, times(0)).dropIndex(db.getCollection(CHANGELOG_COLLECTION_NAME), new Document());
}
示例9: shouldRecreateChangeIdAuthorIndexIfFoundNotUnique
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldRecreateChangeIdAuthorIndexIfFoundNotUnique() throws MongobeeConfigurationException {
// given
MongoClient mongoClient = mock(MongoClient.class);
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
when(mongoClient.getDatabase(anyString())).thenReturn(db);
ChangeEntryDao dao = new ChangeEntryDao(CHANGELOG_COLLECTION_NAME, LOCK_COLLECTION_NAME);
ChangeEntryIndexDao indexDaoMock = mock(ChangeEntryIndexDao.class);
when(indexDaoMock.findRequiredChangeAndAuthorIndex(db)).thenReturn(new Document());
when(indexDaoMock.isUnique(any(Document.class))).thenReturn(false);
dao.setIndexDao(indexDaoMock);
// when
dao.connectMongoDb(mongoClient, DB_NAME);
//then
verify(indexDaoMock, times(1)).dropIndex(any(FongoMongoCollection.class), any(Document.class));
// and
verify(indexDaoMock, times(1)).createRequiredUniqueIndex(any(FongoMongoCollection.class));
}
示例10: shouldInitiateLock
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldInitiateLock() throws MongobeeConfigurationException {
// given
MongoClient mongoClient = mock(MongoClient.class);
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
when(mongoClient.getDatabase(anyString())).thenReturn(db);
ChangeEntryDao dao = new ChangeEntryDao(CHANGELOG_COLLECTION_NAME, LOCK_COLLECTION_NAME);
ChangeEntryIndexDao indexDaoMock = mock(ChangeEntryIndexDao.class);
dao.setIndexDao(indexDaoMock);
LockDao lockDao = mock(LockDao.class);
dao.setLockDao(lockDao);
// when
dao.connectMongoDb(mongoClient, DB_NAME);
// then
verify(lockDao).intitializeLock(db);
}
示例11: shouldGetLockWhenLockDaoGetsLock
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldGetLockWhenLockDaoGetsLock() throws Exception {
// given
MongoClient mongoClient = mock(MongoClient.class);
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
when(mongoClient.getDatabase(anyString())).thenReturn(db);
ChangeEntryDao dao = new ChangeEntryDao(CHANGELOG_COLLECTION_NAME, LOCK_COLLECTION_NAME);
LockDao lockDao = mock(LockDao.class);
when(lockDao.acquireLock(any(MongoDatabase.class))).thenReturn(true);
dao.setLockDao(lockDao);
dao.connectMongoDb(mongoClient, DB_NAME);
// when
boolean hasLock = dao.acquireProcessLock();
// then
assertTrue(hasLock);
}
示例12: shouldReleaseLockFromLockDao
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldReleaseLockFromLockDao() throws Exception {
// given
MongoClient mongoClient = mock(MongoClient.class);
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
when(mongoClient.getDatabase(anyString())).thenReturn(db);
ChangeEntryDao dao = new ChangeEntryDao(CHANGELOG_COLLECTION_NAME, LOCK_COLLECTION_NAME);
LockDao lockDao = mock(LockDao.class);
dao.setLockDao(lockDao);
dao.connectMongoDb(mongoClient, DB_NAME);
// when
dao.releaseProcessLock();
// then
verify(lockDao).releaseLock(any(MongoDatabase.class));
}
示例13: shouldCheckLockHeldFromFromLockDao
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
public void shouldCheckLockHeldFromFromLockDao() throws Exception {
// given
MongoClient mongoClient = mock(MongoClient.class);
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
when(mongoClient.getDatabase(anyString())).thenReturn(db);
ChangeEntryDao dao = new ChangeEntryDao(CHANGELOG_COLLECTION_NAME, LOCK_COLLECTION_NAME);
LockDao lockDao = mock(LockDao.class);
dao.setLockDao(lockDao);
dao.connectMongoDb(mongoClient, DB_NAME);
// when
when(lockDao.isLockHeld(db)).thenReturn(true);
boolean lockHeld = dao.isProccessLockHeld();
// then
assertTrue(lockHeld);
}
示例14: object
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Test
@Ignore("Fongo has not implemented dropIndex for MongoCollection object (issue with mongo driver 3.x)")
public void shouldDropWrongIndex() {
// init
MongoClient mongo = mock(MongoClient.class);
MongoDatabase db = new Fongo(TEST_SERVER).getDatabase(DB_NAME);
when(mongo.getDatabase(Mockito.anyString())).thenReturn(db);
MongoCollection<Document> collection = db.getCollection(CHANGELOG_COLLECTION_NAME);
collection.createIndex(new Document()
.append(ChangeEntry.KEY_CHANGEID, 1)
.append(ChangeEntry.KEY_AUTHOR, 1));
Document index = new Document("name", CHANGEID_AUTHOR_INDEX_NAME);
// given
Document createdIndex = findIndex(db, CHANGEID_AUTHOR_INDEX_NAME);
assertNotNull(createdIndex);
assertFalse(dao.isUnique(createdIndex));
// when
dao.dropIndex(db.getCollection(CHANGELOG_COLLECTION_NAME), index);
// then
assertNull(findIndex(db, CHANGEID_AUTHOR_INDEX_NAME));
}
示例15: init
import com.github.fakemongo.Fongo; //导入依赖的package包/类
@Before
public void init() throws Exception {
fakeDb = new Fongo("testServer").getDB("mongobeetest");
fakeMongoDatabase = new Fongo("testServer").getDatabase("mongobeetest");
when(dao.connectMongoDb(any(MongoClientURI.class), anyString()))
.thenReturn(fakeMongoDatabase);
when(dao.getDb()).thenReturn(fakeDb);
when(dao.getMongoDatabase()).thenReturn(fakeMongoDatabase);
when(dao.acquireProcessLock()).thenReturn(true);
doCallRealMethod().when(dao).save(any(ChangeEntry.class));
doCallRealMethod().when(dao).setChangelogCollectionName(anyString());
doCallRealMethod().when(dao).setIndexDao(any(ChangeEntryIndexDao.class));
dao.setIndexDao(indexDao);
dao.setChangelogCollectionName(CHANGELOG_COLLECTION_NAME);
runner.setDbName("mongobeetest");
runner.setEnabled(true);
}