• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MongoServiceInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.cloud.service.common.MongoServiceInfo的典型用法代码示例。如果您正苦于以下问题:Java MongoServiceInfo类的具体用法?Java MongoServiceInfo怎么用?Java MongoServiceInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MongoServiceInfo类属于org.springframework.cloud.service.common包,在下文中一共展示了MongoServiceInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: cloudMongoCreationNoConfig

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void cloudMongoCreationNoConfig() throws Exception {
	MongoServiceInfo serviceInfo = new MongoServiceInfo("id", TEST_HOST, TEST_PORT, TEST_USERNAME, TEST_PASSWORD, TEST_DB);

	MongoDbFactory mongoDbFactory = testCreator.create(serviceInfo, null);

	assertNotNull(mongoDbFactory);

	MongoClient mongo = (MongoClient) ReflectionTestUtils.getField(mongoDbFactory, "mongo");
	assertNotNull(mongo);

	MongoCredential credentials = mongo.getCredentialsList().get(0);

	List<ServerAddress> addresses = extractServerAddresses(mongo);
	assertEquals(1, addresses.size());

	ServerAddress address = addresses.get(0);

	assertEquals(serviceInfo.getHost(), address.getHost());
	assertEquals(serviceInfo.getPort(), address.getPort());
	assertEquals(serviceInfo.getUserName(), credentials.getUserName());
	assertNotNull(credentials.getPassword());

	// Don't do connector.getDatabase().getName() as that will try to initiate the connection
	assertEquals(serviceInfo.getDatabase(), ReflectionTestUtils.getField(mongoDbFactory, "databaseName"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:27,代码来源:MongoServiceConnectorCreatorTest.java


示例2: cloudMongoCreationWithMultipleHostsByUri

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void cloudMongoCreationWithMultipleHostsByUri() throws Exception {
	String uri = String.format("%s://%s:%[email protected]%s:%s/%s", MONGODB_SCHEME, TEST_USERNAME, TEST_PASSWORD,
			StringUtils.arrayToDelimitedString(TEST_HOSTS, ","), TEST_PORT, TEST_DB);

	MongoServiceInfo serviceInfo = new MongoServiceInfo("id", uri);

	MongoDbFactory mongoDbFactory = testCreator.create(serviceInfo, null);

	assertNotNull(mongoDbFactory);

	MongoClient mongo = (MongoClient) ReflectionTestUtils.getField(mongoDbFactory, "mongo");
	assertNotNull(mongo);

	List<ServerAddress> addresses = extractServerAddresses(mongo);
	assertEquals(3, addresses.size());

	MongoCredential credentials = mongo.getCredentialsList().get(0);
	assertEquals(TEST_USERNAME, credentials.getUserName());
	assertNotNull(credentials.getPassword());

	// Don't do connector.getDatabase().getName() as that will try to initiate the connection
	assertEquals(TEST_DB, ReflectionTestUtils.getField(mongoDbFactory, "databaseName"));

	ServerAddress address1 = addresses.get(0);
	assertEquals(TEST_HOST, address1.getHost());
	assertEquals(TEST_PORT_DEFAULT, address1.getPort());

	ServerAddress address2 = addresses.get(1);
	assertEquals(TEST_HOST_1, address2.getHost());
	assertEquals(TEST_PORT_DEFAULT, address2.getPort());

	ServerAddress address3 = addresses.get(2);
	assertEquals(TEST_HOST_2, address3.getHost());
	assertEquals(TEST_PORT, address3.getPort());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:37,代码来源:MongoServiceConnectorCreatorTest.java


示例3: getCollection

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
private static DBCollection getCollection(MongoServiceInfo info) throws ToDoStoreException {
  MongoClient client;
  try {
    client = new MongoClient(info.getHost(), info.getPort());
    DB db = client.getDB(info.getDatabase());
    boolean auth = db.authenticate(info.getUserName(), info.getPassword().toCharArray());
    if(!auth) {
      throw new ToDoStoreException("Could not authenticate to Mongo DB.");
    }
    return db.getCollection("todos");
  } catch (Exception e) {
    throw new ToDoStoreException("Error creating Mongo DB client.", e);
  }
}
 
开发者ID:IBM-Cloud,项目名称:todo-apps,代码行数:15,代码来源:ToDoStoreFactory.java


示例4: servicePropsOneServiceOfTheSameLabel

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void servicePropsOneServiceOfTheSameLabel() {
	MysqlServiceInfo mysqlServiceInfo = createMysqlService("my-mysql");
	MongoServiceInfo mongoServiceInfo = createMongoService("my-mongo");
	CloudConnector stubCloudConnector = getTestCloudConnector(mysqlServiceInfo, mongoServiceInfo);
	Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators);
	
	Properties cloudProperties = testCloud.getCloudProperties();
	assertRelationalProps("cloud.services.my-mysql", mysqlServiceInfo, cloudProperties);
	assertMongoProps("cloud.services.my-mongo", mongoServiceInfo, cloudProperties);
	assertRelationalProps("cloud.services.mysql", mysqlServiceInfo, cloudProperties);
	assertMongoProps("cloud.services.mongo", mongoServiceInfo, cloudProperties);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:14,代码来源:CloudTest.java


示例5: servicePropsMongoMultipleHostsUriString

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void servicePropsMongoMultipleHostsUriString() {
	String serviceId = "my-mongo-multiple-hosts-uri";
	MongoServiceInfo mongoServiceInfo = createMongoServiceWithMultipleHostsByUri(serviceId);
	CloudConnector stubCloudConnector = getTestCloudConnector(mongoServiceInfo);
	Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators);

	Properties cloudProperties = testCloud.getCloudProperties();
	assertMongoPropsWithMultipleHostsByUri("cloud.services.my-mongo-multiple-hosts-uri", mongoServiceInfo, cloudProperties);
	assertMongoPropsWithMultipleHostsByUri("cloud.services.mongo", mongoServiceInfo, cloudProperties);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:12,代码来源:CloudTest.java


示例6: assertMongoPropsWithMultipleHostsByUri

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
private void assertMongoPropsWithMultipleHostsByUri(String leadKey, MongoServiceInfo serviceInfo, Properties cloudProperties) {
	assertEquals(serviceInfo.getId(), cloudProperties.get(leadKey + ".id"));
	assertEquals(serviceInfo.getUri(), cloudProperties.get(leadKey + ".connection.uri"));
	assertEquals(-1, cloudProperties.get(leadKey + ".connection.port"));

	assertNull(cloudProperties.get(leadKey + ".connection.host"));
	assertNull(cloudProperties.get(leadKey + ".connection.username"));
	assertNull(cloudProperties.get(leadKey + ".connection.password"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:10,代码来源:CloudTest.java


示例7: mongoServiceCreation

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void mongoServiceCreation() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMongoServicePayload("mongo-1", hostname, port, username, password, "inventory-1", "db"),
					getMongoServicePayload("mongo-2", hostname, port, username, password, "inventory-2", "db")));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertServiceFoundOfType(serviceInfos, "mongo-1", MongoServiceInfo.class);
	assertServiceFoundOfType(serviceInfos, "mongo-2", MongoServiceInfo.class);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:12,代码来源:CloudFoundryConnectorMongodbServiceTest.java


示例8: mongoServiceCreationNoLabelNoTags

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void mongoServiceCreationNoLabelNoTags() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMongoServicePayloadNoLabelNoTags("mongo-1", hostname, port, username, password, "inventory-1", "db"),
					getMongoServicePayloadNoLabelNoTags("mongo-2", hostname, port, username, password, "inventory-2", "db")));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertServiceFoundOfType(serviceInfos, "mongo-1", MongoServiceInfo.class);
	assertServiceFoundOfType(serviceInfos, "mongo-2", MongoServiceInfo.class);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:12,代码来源:CloudFoundryConnectorMongodbServiceTest.java


示例9: serviceOverride

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void serviceOverride() {
	env.setSystemProperty("spring.cloud.candygram", "mongodb://youruser:[email protected]:4321/dbname");

	List<ServiceInfo> services = connector.getServiceInfos();
	ServiceInfo service = getServiceInfo(services, "candygram");
	assertNotNull(service);
	assertTrue(service instanceof MongoServiceInfo);
	MongoServiceInfo mongo = (MongoServiceInfo) service;
	assertEquals("youruser", mongo.getUserName());
	assertEquals(4321, mongo.getPort());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:13,代码来源:LocalConfigServiceOverrideTest.java


示例10: serviceCreation

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void serviceCreation() {
	List<ServiceInfo> services = connector.getServiceInfos();
	ServiceInfo service = getServiceInfo(services, "candygram");
	assertNotNull(service);
	assertTrue(service instanceof MongoServiceInfo);
	assertUriParameters((MongoServiceInfo) service);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:9,代码来源:LocalConfigConnectorMongoServiceTest.java


示例11: mongoServiceCreation

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void mongoServiceCreation() {
	for (String mongoEnv : new String[]{"MONGOLAB_URI", "MONGOHQ_URL", "MONGOSOUP_URL"}) {
		Map<String, String> env = new HashMap<String, String>();
		String mongoUrl = getMongoServiceUrl("db");
		env.put(mongoEnv, mongoUrl);
		when(mockEnvironment.getEnv()).thenReturn(env);

		List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
		ServiceInfo serviceInfo = getServiceInfo(serviceInfos, mongoEnv.substring(0, mongoEnv.length() - 4));
		assertNotNull(serviceInfo);
		assertTrue(serviceInfo instanceof MongoServiceInfo);
		assertMongoServiceInfo((MongoServiceInfo) serviceInfo, "db");
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:16,代码来源:HerokuConnectorMongoServiceTest.java


示例12: assertMongoServiceInfo

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
protected void assertMongoServiceInfo(MongoServiceInfo serviceInfo, String databaseName) {
	assertEquals(hostname, serviceInfo.getHost());
	assertEquals(port, serviceInfo.getPort());
	assertEquals(username, serviceInfo.getUserName());
	assertEquals(password, serviceInfo.getPassword());
	assertEquals(databaseName, serviceInfo.getPath());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:8,代码来源:HerokuConnectorMongoServiceTest.java


示例13: createMongoDbFactory

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
private SimpleMongoDbFactory createMongoDbFactory(MongoServiceInfo serviceInfo, MongoClientOptions.Builder mongoOptionsToUse) throws UnknownHostException {
	MongoClientURI mongoClientURI = new MongoClientURI(serviceInfo.getUri(), mongoOptionsToUse);
	MongoClient mongo = new MongoClient(mongoClientURI);
	return new SimpleMongoDbFactory(mongo, mongoClientURI.getDatabase());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:6,代码来源:MongoDbFactoryCreator.java


示例14: createMongoService

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
protected MongoServiceInfo createMongoService(String id) {
	return new MongoServiceInfo(id, "10.20.30.40", 1234, "username", "password", "db");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:4,代码来源:StubCloudConnectorTest.java


示例15: createMongoServiceWithMultipleHostsByUri

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
protected MongoServiceInfo createMongoServiceWithMultipleHostsByUri(String id) {
	return new MongoServiceInfo(id, "mongo://username:[email protected],10.20.30.41,10.20.30.42:1234/db");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:4,代码来源:StubCloudConnectorTest.java


示例16: assertMongoProps

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
private void assertMongoProps(String leadKey, MongoServiceInfo serviceInfo, Properties cloudProperties) {
	assertBasicProps(leadKey, serviceInfo, cloudProperties);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:4,代码来源:CloudTest.java


示例17: getTestServiceInfo

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
public MongoServiceInfo getTestServiceInfo(String id) {
	return new MongoServiceInfo(id, new UriInfo("mongodb", "host", 0, "username", "password", "db").getUriString());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:4,代码来源:MongoDbFactoryFactoryTest.java


示例18: MongoServiceInfoCreator

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
public MongoServiceInfoCreator() {
	// the literal in the tag is CloudFoundry-specific
	super(new Tags("mongodb"), MongoServiceInfo.MONGODB_SCHEME);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:5,代码来源:MongoServiceInfoCreator.java


示例19: MongoServiceInfoCreator

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
public MongoServiceInfoCreator() {
	super(MongoServiceInfo.MONGODB_SCHEME);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:4,代码来源:MongoServiceInfoCreator.java


示例20: createServiceInfo

import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Override
public MongoServiceInfo createServiceInfo(String id, String uri) {
	return new MongoServiceInfo(id, uri);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:5,代码来源:MongoServiceInfoCreator.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DiagnosticGroups类代码示例发布时间:2022-05-22
下一篇:
Java CodecJOrbis类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap