当前位置: 首页>>代码示例>>Java>>正文


Java Fongo类代码示例

本文整理汇总了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);
}
  }
 
开发者ID:cloudronin,项目名称:cyberattack-event-collector,代码行数:24,代码来源:EventCollectorTest.java

示例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());
}
 
开发者ID:Talend,项目名称:daikon,代码行数:24,代码来源:MultiTenantMongoDbFactoryTest.java

示例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();
        }
    };
}
 
开发者ID:Talend,项目名称:daikon,代码行数:21,代码来源:TestMultiTenantConfiguration.java

示例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());
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:19,代码来源:MongobeeTest.java

示例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);

}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:17,代码来源:LockDaoTest.java

示例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);

}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:18,代码来源:LockDaoTest.java

示例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));
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:24,代码来源:ChangeEntryDaoTest.java

示例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());
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:23,代码来源:ChangeEntryDaoTest.java

示例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));
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:23,代码来源:ChangeEntryDaoTest.java

示例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);

}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:23,代码来源:ChangeEntryDaoTest.java

示例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);
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:23,代码来源:ChangeEntryDaoTest.java

示例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));
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:22,代码来源:ChangeEntryDaoTest.java

示例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);
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:24,代码来源:ChangeEntryDaoTest.java

示例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));
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:26,代码来源:ChangeEntryIndexDaoTest.java

示例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);
}
 
开发者ID:mongobee,项目名称:mongobee,代码行数:20,代码来源:MongobeeProfileTest.java


注:本文中的com.github.fakemongo.Fongo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。