org.influxdb.InfluxDB.ping()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(258)

本文整理了Java中org.influxdb.InfluxDB.ping()方法的一些代码示例,展示了InfluxDB.ping()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InfluxDB.ping()方法的具体详情如下:
包路径:org.influxdb.InfluxDB
类名称:InfluxDB
方法名:ping

InfluxDB.ping介绍

[英]Ping this influxDB.
[中]Ping此XDB。

代码示例

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void checkVersion() {
  InfluxDB actual = influxDBContainer.getNewInfluxDB();
  assertThat(actual, notNullValue());
  assertThat(actual.ping(), notNullValue());
  assertThat(actual.ping().getVersion(), is(TEST_VERSION));
  assertThat(actual.version(), is(TEST_VERSION));
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void getNewInfluxDB() {
  InfluxDB actual = influxDBContainer.getNewInfluxDB();
  assertThat(actual, notNullValue());
  assertThat(actual.ping(), notNullValue());
}

代码示例来源:origin: apache/cloudstack

/**
 * Sends metrics to influxdb host. This method supports both VM and Host metrics
 */
protected void sendMetricsToInfluxdb(Map<Object, Object> metrics) {
  InfluxDB influxDbConnection = createInfluxDbConnection();
  Pong response = influxDbConnection.ping();
  if (response.getVersion().equalsIgnoreCase("unknown")) {
    throw new CloudRuntimeException(String.format("Cannot ping influxdb host %s:%s.", externalStatsHost, externalStatsPort));
  }
  Collection<Object> metricsObjects = metrics.values();
  List<Point> points = new ArrayList<>();
  s_logger.debug(String.format("Sending stats to %s host %s:%s", externalStatsType, externalStatsHost, externalStatsPort));
  for (Object metricsObject : metricsObjects) {
    Point vmPoint = creteInfluxDbPoint(metricsObject);
    points.add(vmPoint);
  }
  writeBatches(influxDbConnection, databaseName, points);
}

代码示例来源:origin: org.springframework.boot/spring-boot-actuator

@Override
protected void doHealthCheck(Health.Builder builder) {
  Pong pong = this.influxDb.ping();
  builder.up().withDetail("version", pong.getVersion());
}

代码示例来源:origin: inspectIT/inspectIT

/**
 * Checks if the remote influxDB instance is available.
 *
 * @return Returns true if the influxDB is available.
 */
private boolean isAvailable() {
  try {
    influxDB.ping();
    return true;
  } catch (Exception e) {
    if (log.isTraceEnabled()) {
      log.trace("Ping to the influxDB failed.", e);
    }
    return false;
  }
}

代码示例来源:origin: miwurster/spring-data-influxdb

@Override
public Pong ping()
{
 return getConnection().ping();
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void isNotActive() {
  availabilityChecker.run();
  verify(influxDb).ping();
  verifyNoMoreInteractions(influxDb);
  verifyZeroInteractions(listener);
  verifyZeroInteractions(executorService);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
@SuppressWarnings("unchecked")
public void isNotAvailable() {
  availabilityChecker.activate();
  when(influxDb.ping()).thenThrow(Exception.class);
  availabilityChecker.run();
  verify(executorService).schedule(eq(availabilityChecker), eq(0L), any(TimeUnit.class));
  verify(executorService).schedule(eq(availabilityChecker), eq(5L), any(TimeUnit.class));
  verifyNoMoreInteractions(executorService);
  verify(influxDb).ping();
  verifyNoMoreInteractions(influxDb);
  verifyZeroInteractions(listener);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void isAvailable() {
  availabilityChecker.activate();
  availabilityChecker.run();
  verify(executorService).schedule(eq(availabilityChecker), eq(0L), any(TimeUnit.class));
  verify(executorService).schedule(eq(availabilityChecker), eq(5L), any(TimeUnit.class));
  verifyNoMoreInteractions(executorService);
  verify(influxDb).ping();
  verifyNoMoreInteractions(influxDb);
  verifyZeroInteractions(listener);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void isAvailableAndWasAvailable() {
  availabilityChecker.activate();
  availabilityChecker.run();
  availabilityChecker.run();
  verify(executorService).schedule(eq(availabilityChecker), eq(0L), any(TimeUnit.class));
  verify(executorService, times(2)).schedule(eq(availabilityChecker), eq(5L), any(TimeUnit.class));
  verifyNoMoreInteractions(executorService);
  verify(influxDb, times(2)).ping();
  verifyNoMoreInteractions(influxDb);
  verifyZeroInteractions(listener);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
@SuppressWarnings("unchecked")
public void isNotAvailableAndWasNotAvailable() {
  availabilityChecker.activate();
  when(influxDb.ping()).thenThrow(Exception.class);
  availabilityChecker.run();
  availabilityChecker.run();
  verify(executorService).schedule(eq(availabilityChecker), eq(0L), any(TimeUnit.class));
  verify(executorService).schedule(eq(availabilityChecker), eq(5L), any(TimeUnit.class));
  verify(executorService).schedule(eq(availabilityChecker), eq(15L), any(TimeUnit.class));
  verifyNoMoreInteractions(executorService);
  verify(influxDb, times(2)).ping();
  verifyNoMoreInteractions(influxDb);
  verifyZeroInteractions(listener);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
@SuppressWarnings("unchecked")
public void isNotAvailableAndWasAvailable() {
  availabilityChecker.activate();
  when(influxDb.ping()).thenReturn(mock(Pong.class)).thenThrow(Exception.class);
  availabilityChecker.run();
  availabilityChecker.run();
  verify(executorService).schedule(eq(availabilityChecker), eq(0L), any(TimeUnit.class));
  verify(executorService, times(2)).schedule(eq(availabilityChecker), eq(5L), any(TimeUnit.class));
  verifyNoMoreInteractions(executorService);
  verify(influxDb, times(2)).ping();
  verifyNoMoreInteractions(influxDb);
  verify(listener).onDisconnection();
  verifyNoMoreInteractions(listener);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
@SuppressWarnings("unchecked")
public void isAvailableAndWasNotAvailable() {
  availabilityChecker.activate();
  when(influxDb.ping()).thenThrow(Exception.class).thenReturn(mock(Pong.class));
  availabilityChecker.run();
  availabilityChecker.run();
  verify(executorService).schedule(eq(availabilityChecker), eq(0L), any(TimeUnit.class));
  verify(executorService).schedule(eq(availabilityChecker), eq(5L), any(TimeUnit.class));
  verify(executorService).schedule(eq(availabilityChecker), eq(15L), any(TimeUnit.class));
  verifyNoMoreInteractions(executorService);
  verify(influxDb, times(2)).ping();
  verifyNoMoreInteractions(influxDb);
  verify(listener).onReconnection();
  verifyNoMoreInteractions(listener);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
@SuppressWarnings("unchecked")
public void unexcpectedException() {
  availabilityChecker.activate();
  when(influxDb.ping()).thenThrow(Exception.class).thenReturn(mock(Pong.class));
  doThrow(RuntimeException.class).when(listener).onReconnection();
  availabilityChecker.run();
  availabilityChecker.run();
  verify(executorService).schedule(eq(availabilityChecker), eq(0L), any(TimeUnit.class));
  verify(executorService, times(2)).schedule(eq(availabilityChecker), eq(5L), any(TimeUnit.class));
  verifyNoMoreInteractions(executorService);
  verify(influxDb, times(2)).ping();
  verifyNoMoreInteractions(influxDb);
  verify(listener).onReconnection();
  verifyNoMoreInteractions(listener);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void writeTestFailsDatabaseCreationSucceeds() {
  influxDao.active = true;
  Mockito.doThrow(new RuntimeException()).when(influxDb).write(any(String.class), any(String.class), any(Point.class));
  influxDao.propertiesUpdated();
  assertThat(influxDao.isConnected(), is(true));
  verify(executor, times(1)).submit(any(Runnable.class));
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(clientFactory).createClient();
  verify(influxDb).describeDatabases();
  verify(influxDb).createDatabase(any(String.class));
  verify(influxDb, times(1)).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(influxDb).ping();
  verify(availabilityChecker, times(1)).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verifyNoMoreInteractions(future, influxDb, executor, clientFactory);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void enableInflux() {
  influxDao.active = true;
  influxDao.propertiesUpdated();
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceType(), is(ExternalServiceType.INFLUXDB));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(executor, times(1)).submit(any(Runnable.class));
  verify(influxDb).ping();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).query(any(Query.class));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(influxDb, availabilityChecker, executor, clientFactory);
  verifyZeroInteractions(future);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void enableInfluxDatabaseExists() {
  influxDao.active = true;
  when(influxDb.describeDatabases()).thenReturn(Arrays.asList(influxDao.database));
  influxDao.propertiesUpdated();
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(executor, times(1)).submit(any(Runnable.class));
  verify(influxDb).ping();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).query(any(Query.class));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(influxDb, availabilityChecker, executor, clientFactory);
  verifyZeroInteractions(future);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void executeNullQuery() {
  influxDao.active = true;
  influxDao.propertiesUpdated();
  influxDao.query(null);
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(influxDb).ping();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(influxDb).query(any(Query.class));
  verify(executor).submit(any(Runnable.class));
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(clientFactory, availabilityChecker, executor, influxDb);
  verifyZeroInteractions(future);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void insertNull() {
  influxDao.active = true;
  influxDao.propertiesUpdated();
  influxDao.insert(null);
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(executor).submit(any(Runnable.class));
  verify(influxDb).ping();
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(executor, availabilityChecker, clientFactory);
  verifyZeroInteractions(future, dataPoint);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void insertPoint() {
  influxDao.active = true;
  influxDao.propertiesUpdated();
  influxDao.insert(dataPoint);
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(executor).submit(any(Runnable.class));
  verify(influxDb).write(influxDao.database, influxDao.retentionPolicy, dataPoint);
  verify(influxDb).ping();
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(availabilityChecker).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verify(clientFactory).createClient();
  verifyNoMoreInteractions(executor, availabilityChecker, clientFactory);
  verifyZeroInteractions(future, dataPoint);
}

相关文章