use of com.github.zafarkhaja.semver.Version in project morphia by mongodb.
the class TestBase method startMongo.
private void startMongo() {
String mongodb = System.getenv("MONGODB");
Builder builder = MongoClientSettings.builder();
try {
builder.uuidRepresentation(mapperOptions.getUuidRepresentation());
} catch (Exception ignored) {
// not a 4.0 driver
}
if (mongodb != null) {
File mongodbRoot = new File("target/mongo");
try {
FileUtils.deleteDirectory(mongodbRoot);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
Version version = Version.valueOf(mongodb);
final MongoCluster cluster = version.lessThan(Version.valueOf("4.0.0")) ? new SingleNode(mongodbRoot, "morphia_test", version) : new ReplicaSet(mongodbRoot, "morphia_test", version);
cluster.configure(c -> {
c.systemLog(s -> {
s.setTraceAllExceptions(true);
s.setVerbosity(Verbosity.FIVE);
return null;
});
return null;
});
cluster.clean();
cluster.start();
mongoClient = cluster.getClient(builder);
} else {
mongoClient = MongoClients.create(builder.build());
}
}
use of com.github.zafarkhaja.semver.Version in project graylog2-server by Graylog2.
the class MongoDBPreflightCheck method runCheck.
@Override
public void runCheck() throws PreflightCheckException {
try {
final Version mongoVersion = RetryerBuilder.<Version>newBuilder().retryIfResult(Objects::isNull).retryIfExceptionOfType(MongoTimeoutException.class).retryIfRuntimeException().withRetryListener(new RetryListener() {
@Override
public <V> void onRetry(Attempt<V> attempt) {
if (attempt.hasResult()) {
return;
}
if (mongoVersionProbeAttempts == 0) {
LOG.info("MongoDB is not available. Retry #{}", attempt.getAttemptNumber());
} else {
LOG.info("MongoDB is not available. Retry #{}/{}", attempt.getAttemptNumber(), mongoVersionProbeAttempts);
}
}
}).withWaitStrategy(WaitStrategies.fixedWait(2, TimeUnit.SECONDS)).withStopStrategy(mongoVersionProbeAttempts == 0 ? StopStrategies.neverStop() : StopStrategies.stopAfterAttempt(mongoVersionProbeAttempts)).build().call(() -> {
try (MongoClient mongoClient = (MongoClient) mongoConnection.connect()) {
return MongoDBVersionCheck.getVersion(mongoClient);
}
});
MongoDBVersionCheck.assertCompatibleVersion(mongoVersion);
LOG.info("Connected to MongoDB version {}", mongoVersion);
} catch (ExecutionException | RetryException e) {
throw new PreflightCheckException("Failed to retrieve MongoDB version.", e);
}
}
use of com.github.zafarkhaja.semver.Version in project graylog2-server by Graylog2.
the class VersionSerializerTest method successfullySerializesVersion.
@Test
public void successfullySerializesVersion() throws JsonProcessingException {
final Version version = Version.valueOf("1.3.7-rc.2+build.2.b8f12d7");
final String s = objectMapper.writeValueAsString(version);
assertThat(s).isEqualTo("\"1.3.7-rc.2+build.2.b8f12d7\"");
}
use of com.github.zafarkhaja.semver.Version in project graylog2-server by Graylog2.
the class VersionDeserializerTest method successfullyDeserializesNull.
@Test
public void successfullyDeserializesNull() throws IOException {
final Version version = objectMapper.readValue("null", Version.class);
assertThat(version).isNull();
}
use of com.github.zafarkhaja.semver.Version in project graylog2-server by Graylog2.
the class VersionDeserializerTest method successfullyDeserializesString.
@Test
public void successfullyDeserializesString() throws IOException {
final Version version = objectMapper.readValue("\"1.3.7-rc.2+build.2.b8f12d7\"", Version.class);
assertThat(version).isEqualTo(Version.valueOf("1.3.7-rc.2+build.2.b8f12d7"));
}
Aggregations