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


Java Network.getFreeServerPort方法代码示例

本文整理汇总了Java中de.flapdoodle.embed.process.runtime.Network.getFreeServerPort方法的典型用法代码示例。如果您正苦于以下问题:Java Network.getFreeServerPort方法的具体用法?Java Network.getFreeServerPort怎么用?Java Network.getFreeServerPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在de.flapdoodle.embed.process.runtime.Network的用法示例。


在下文中一共展示了Network.getFreeServerPort方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
@BeforeAll
public static void start() throws Exception {
  StopWatch stopWatch = StopWatch.startForSplits();
  port = Network.getFreeServerPort();
  mongodExe =
      starter.prepare(
          new MongodConfigBuilder()
              .version(Version.Main.DEVELOPMENT)
              .net(new Net("localhost", port, Network.localhostIsIPv6()))
              .build());
  long prepareElapsedTime = stopWatch.split();
  mongod = mongodExe.start();
  long startElapsedTime = stopWatch.split();
  logger.info(
      "Started embedded Mongo in {}ms (prepareElapsedTime={}ms, startElapsedTime={}ms)",
      stopWatch.stop(),
      prepareElapsedTime,
      startElapsedTime);
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:20,代码来源:AbstractMongoDBTest.java

示例2: start

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
public synchronized void start() throws IOException {
	if (process != null) {
		throw new IllegalStateException();
	}

	Command command = Command.Postgres;

	IDownloadConfig downloadConfig = new PostgresDownloadConfigBuilder()
			.defaultsForCommand(command)
			.artifactStorePath(new FixedPath(artifactStorePath))
			.build();

	ArtifactStoreBuilder artifactStoreBuilder = new PostgresArtifactStoreBuilder()
			.defaults(command)
			.download(downloadConfig);

	LogWatchStreamProcessor logWatch = new LogWatchStreamProcessor("started",
			new HashSet<>(singletonList("failed")),
			new Slf4jStreamProcessor(getLogger("postgres"), Slf4jLevel.TRACE));

	IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
			.defaults(command)
			.processOutput(new ProcessOutput(logWatch, logWatch, logWatch))
			.artifactStore(artifactStoreBuilder)
			.build();

	PostgresStarter<PostgresExecutable, PostgresProcess> starter = new PostgresStarter<>(PostgresExecutable.class, runtimeConfig);

	PostgresConfig config = new PostgresConfig(version,
			new AbstractPostgresConfig.Net(host, port == 0 ? Network.getFreeServerPort() : port),
			new AbstractPostgresConfig.Storage(dbName),
			new AbstractPostgresConfig.Timeout(),
			new AbstractPostgresConfig.Credentials(username, password));
	process = starter.prepare(config).start();
	jdbcUrl = "jdbc:postgresql://" + config.net().host() + ":" + config.net().port() + "/" + config.storage().dbName();
}
 
开发者ID:honourednihilist,项目名称:gradle-postgresql-embedded,代码行数:37,代码来源:EmbeddedPostgres.java

示例3: setup

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
@Before
public void setup() throws Exception {
    int port = Network.getFreeServerPort();
    _mongodExe = starter.prepare(new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION)
            .net(new Net("localhost", port, false))
            .build());
    _mongod = _mongodExe.start();
    mongo = new MongoClient("localhost", port);
    service = new SimpleService(new MongoDatabaseProvider(mongo, dbName, collName), null);
}
 
开发者ID:Exorath,项目名称:ConnectorService,代码行数:12,代码来源:MongoDatabaseTest.java

示例4: setUpClass

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
/**
 * Initiate the MongoDB server on the default port
 */
@Override
public void setUpClass() throws Exception {
  super.setUpClass();
  MongodStarter runtime = MongodStarter.getDefaultInstance();

  int port = Network.getFreeServerPort();
  IMongodConfig mongodConfig = new MongodConfigBuilder()
          .version(version)
          .net(new Net(port, Network.localhostIsIPv6())).build();

  // Store Mongo server "host:port" in Hadoop configuration
  // so that MongoStore will be able to get it latter
  conf.set(MongoStoreParameters.PROP_MONGO_SERVERS, "127.0.0.1:" + port);

  log.info("Starting embedded Mongodb server on {} port.", port);
  try {

    _mongodExe = runtime.prepare(mongodConfig);
    _mongod = _mongodExe.start();

    _mongo = new MongoClient("localhost", port);
  } catch (Exception e) {
    log.error("Error starting embedded Mongodb server... tearing down test driver.");
    tearDownClass();
  }
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:30,代码来源:GoraMongodbTestDriver.java

示例5: configureMongo

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
@BeforeClass
public static void configureMongo() throws Exception {
    port = Network.getFreeServerPort();

    IMongodConfig config = new MongodConfigBuilder()
            .version(Version.Main.V3_2)
            .net(new Net(port, Network.localhostIsIPv6()))
            .build();

    MongodExecutable executable = STARTER.prepare(config);
    process = executable.start();
}
 
开发者ID:serhuz,项目名称:dropwizard-morphia,代码行数:13,代码来源:BaseMongoTest.java

示例6: before

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
@Override
public void before() throws Throwable {

    int port = Network.getFreeServerPort();
    String portProp = System.getProperty(MONGO_PORT_PROP);
    if (portProp != null && !portProp.isEmpty()) {
        port = Integer.valueOf(portProp);
    }

    IMongodConfig conf =
            new MongodConfigBuilder().version(Version.Main.PRODUCTION)
                .net(new Net(port, Network.localhostIsIPv6())).build();

    Command command = Command.MongoD;
    IRuntimeConfig runtimeConfig =
            new RuntimeConfigBuilder()
                .defaultsWithLogger(command, LOGGER)
                .artifactStore(
                        new ArtifactStoreBuilder().defaults(command).download(
                                new DownloadConfigBuilder().defaultsForCommand(command).proxyFactory(new SystemProxy())))
                .build();

    MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
    mongoExec = runtime.prepare(conf);

    mongoProc = mongoExec.start();

    client = new MongoClient(new ServerAddress(conf.net().getServerAddress(), conf.net().getPort()));

    // set the property for our config...
    System.setProperty("dbhost", conf.net().getServerAddress().getHostAddress());
    System.setProperty("dbport", Integer.toString(conf.net().getPort()));
}
 
开发者ID:jimzucker,项目名称:hygieia-temp,代码行数:34,代码来源:EmbeddedMongoDBRule.java

示例7: setUpClass

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    Integer port = Network.getFreeServerPort();
    MongodStarter starter = MongodStarter.getDefaultInstance();
    mongodExe = starter.prepare(
            new MongodConfigBuilder()
            .version(Version.Main.PRODUCTION)
            .net(new Net(port, Network.localhostIsIPv6()))
            .build());
    mongod = mongodExe.start();
    mongoClient = new MongoClient(HOST, port);
}
 
开发者ID:decebals,项目名称:pippo,代码行数:13,代码来源:MongoDBSessionDataStorageTest.java

示例8: setUpClass

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
/**
 * Initiate the MongoDB server on the default port
 */
@Override
public void setUpClass() throws IOException {
  IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
          .defaultsWithLogger(Command.MongoD, log)
          .processOutput(ProcessOutput.getDefaultInstanceSilent())
          .build();

  MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);

  int port = Network.getFreeServerPort();
  IMongodConfig mongodConfig = new MongodConfigBuilder()
          .version(version)
          .net(new Net(port, Network.localhostIsIPv6())).build();

  // Store Mongo server "host:port" in Hadoop configuration
  // so that MongoStore will be able to get it latter
  conf.set(MongoStoreParameters.PROP_MONGO_SERVERS, "127.0.0.1:" + port);

  log.info("Starting embedded Mongodb server on {} port.", port);
  try {

    _mongodExe = runtime.prepare(mongodConfig);
    _mongod = _mongodExe.start();

    _mongo = new MongoClient("localhost", port);
  } catch (Exception e) {
    log.error("Error starting embedded Mongodb server... tearing down test driver.");
    tearDownClass();
  }
}
 
开发者ID:apache,项目名称:gora,代码行数:34,代码来源:GoraMongodbTestDriver.java

示例9: before

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
@Override
public void before() throws Throwable {
  LOG.info("Graphite Mock before...");
  server = ServerSocketChannel.open();
  server.configureBlocking(false);
  port = Network.getFreeServerPort();
  LOG.info("GraphiteMockServer starting : port={}", port);
  server.socket().bind(new InetSocketAddress(port));
  selector = Selector.open();
  server.register(selector, SelectionKey.OP_ACCEPT);

  thread = new Thread(this);
  thread.start();
  LOG.info("... done Graphite Mock before");
}
 
开发者ID:ImmobilienScout24,项目名称:appmon4j,代码行数:16,代码来源:GraphiteMockServer.java

示例10: before

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
@Override
public void before() throws Throwable {
  server = ServerSocketChannel.open();
  server.configureBlocking(false);

  int maxTries = 3;
  int sleepInSec = 2;
  for (int i = 0; i < maxTries; i++) {
    try {
      port = Network.getFreeServerPort();
      server.socket().bind(new InetSocketAddress(port));
      LOG.info("StatsdMockServer started : port={}", port);
    } catch (Throwable e) {
      int lastTry = maxTries - 1;
      if (i < lastTry) {
        LOG.warn(format("Starting StatsdMockServer: try %s of %s failed. Retry after %s seconds.", i + 1, maxTries,
            sleepInSec), e);
        sleep(sleepInSec * 1000);
      } else {
        LOG.error(format("Starting StatsdMockServer: %s of %s failed. No retries left.", i + 1, maxTries));
        throw e;
      }
    }
  }

  selector = Selector.open();
  server.register(selector, SelectionKey.OP_ACCEPT);

  thread = new Thread(this);
  thread.start();
}
 
开发者ID:ImmobilienScout24,项目名称:appmon4j,代码行数:32,代码来源:StatsdMockServer.java

示例11: setUpClass

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
@Override
public void setUpClass() throws Exception {
    port = Network.getFreeServerPort();
    log.info("Starting embedded Mongodb server on {} port.", port);
    doStart();
}
 
开发者ID:apache,项目名称:gora,代码行数:7,代码来源:GoraMongodbAuthenticationTestDriver.java

示例12: setPort

import de.flapdoodle.embed.process.runtime.Network; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void setPort(int port) throws ContextException {

	int portToUse = port;

	// If port is equal to 0 we pick a free port number
	if (port == 0) {

		try {

			portToUse = Network.getFreeServerPort();

		} catch (IOException ioex) {

			throw new ContextException(ioex);

		}

	}

	boolean ipv6 = false;

	try {

		ipv6 = Network.localhostIsIPv6();

	} catch (UnknownHostException uhex) {

		throw new ContextException(uhex);

	}

	this.net = new Net(portToUse, ipv6);

	// Re-creates the Mongod configuration
	this.createMongodConfig();
}
 
开发者ID:gomoob,项目名称:embedded-mongo,代码行数:40,代码来源:MongoContext.java


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