Search in sources :

Example 11 with Version

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());
    }
}
Also used : MongoCluster(com.antwerkz.bottlerocket.clusters.MongoCluster) Version(com.github.zafarkhaja.semver.Version) Builder(com.mongodb.MongoClientSettings.Builder) IOException(java.io.IOException) File(java.io.File) ReplicaSet(com.antwerkz.bottlerocket.clusters.ReplicaSet) SkipException(org.testng.SkipException) IOException(java.io.IOException) SingleNode(com.antwerkz.bottlerocket.clusters.SingleNode)

Example 12 with Version

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);
    }
}
Also used : MongoClient(com.mongodb.MongoClient) Version(com.github.zafarkhaja.semver.Version) ExecutionException(java.util.concurrent.ExecutionException) RetryException(com.github.rholder.retry.RetryException) RetryListener(com.github.rholder.retry.RetryListener)

Example 13 with Version

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\"");
}
Also used : Version(com.github.zafarkhaja.semver.Version) Test(org.junit.Test)

Example 14 with Version

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();
}
Also used : Version(com.github.zafarkhaja.semver.Version) Test(org.junit.Test)

Example 15 with Version

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"));
}
Also used : Version(com.github.zafarkhaja.semver.Version) Test(org.junit.Test)

Aggregations

Version (com.github.zafarkhaja.semver.Version)27 Test (org.junit.Test)6 File (java.io.File)4 IOException (java.io.IOException)4 BrokerFilterBadVersionException (org.apache.pulsar.broker.loadbalance.BrokerFilterBadVersionException)3 JsonWriter (com.serotonin.json.JsonWriter)2 JsonObject (com.serotonin.json.type.JsonObject)2 JsonString (com.serotonin.json.type.JsonString)2 JsonTypeReader (com.serotonin.json.type.JsonTypeReader)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 BrokerData (org.apache.pulsar.broker.BrokerData)2 Plugin (org.syncany.plugins.Plugin)2 UpgradeServerVersion (org.talend.dataprep.api.service.upgrade.UpgradeServerVersion)2 NonNull (android.support.annotation.NonNull)1 MongoCluster (com.antwerkz.bottlerocket.clusters.MongoCluster)1