Search in sources :

Example 11 with DseRequirement

use of com.datastax.oss.driver.api.testinfra.DseRequirement in project java-driver by datastax.

the class ProtocolVersionInitialNegotiationIT method should_downgrade_to_v4_dse.

@DseRequirement(min = "5.0", max = "5.1", description = "Only DSE in [5.0,5.1[ has V4 as its highest version")
@Test
public void should_downgrade_to_v4_dse() {
    try (CqlSession session = SessionUtils.newSession(ccm)) {
        assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(4);
        session.execute("select * from system.local");
    }
}
Also used : CqlSession(com.datastax.oss.driver.api.core.CqlSession) DseRequirement(com.datastax.oss.driver.api.testinfra.DseRequirement) Test(org.junit.Test)

Example 12 with DseRequirement

use of com.datastax.oss.driver.api.testinfra.DseRequirement in project java-driver by datastax.

the class BaseCcmRule method apply.

@Override
public Statement apply(Statement base, Description description) {
    // If test is annotated with CassandraRequirement or DseRequirement, ensure configured CCM
    // cluster meets those requirements.
    CassandraRequirement cassandraRequirement = description.getAnnotation(CassandraRequirement.class);
    if (cassandraRequirement != null) {
        // if the configured cassandra cassandraRequirement exceeds the one being used skip this test.
        if (!cassandraRequirement.min().isEmpty()) {
            Version minVersion = Version.parse(cassandraRequirement.min());
            if (minVersion.compareTo(ccmBridge.getCassandraVersion()) > 0) {
                return buildErrorStatement(minVersion, cassandraRequirement.description(), false, false);
            }
        }
        if (!cassandraRequirement.max().isEmpty()) {
            // if the test version exceeds the maximum configured one, fail out.
            Version maxVersion = Version.parse(cassandraRequirement.max());
            if (maxVersion.compareTo(ccmBridge.getCassandraVersion()) <= 0) {
                return buildErrorStatement(maxVersion, cassandraRequirement.description(), true, false);
            }
        }
    }
    DseRequirement dseRequirement = description.getAnnotation(DseRequirement.class);
    if (dseRequirement != null) {
        Optional<Version> dseVersionOption = ccmBridge.getDseVersion();
        if (!dseVersionOption.isPresent()) {
            return new Statement() {

                @Override
                public void evaluate() {
                    throw new AssumptionViolatedException("Test Requires DSE but C* is configured.");
                }
            };
        } else {
            Version dseVersion = dseVersionOption.get();
            if (!dseRequirement.min().isEmpty()) {
                Version minVersion = Version.parse(dseRequirement.min());
                if (minVersion.compareTo(dseVersion) > 0) {
                    return buildErrorStatement(minVersion, dseRequirement.description(), false, true);
                }
            }
            if (!dseRequirement.max().isEmpty()) {
                Version maxVersion = Version.parse(dseRequirement.max());
                if (maxVersion.compareTo(dseVersion) <= 0) {
                    return buildErrorStatement(maxVersion, dseRequirement.description(), true, true);
                }
            }
        }
    }
    return super.apply(base, description);
}
Also used : DseRequirement(com.datastax.oss.driver.api.testinfra.DseRequirement) DefaultProtocolVersion(com.datastax.oss.driver.api.core.DefaultProtocolVersion) Version(com.datastax.oss.driver.api.core.Version) ProtocolVersion(com.datastax.oss.driver.api.core.ProtocolVersion) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Aggregations

DseRequirement (com.datastax.oss.driver.api.testinfra.DseRequirement)12 CqlSession (com.datastax.oss.driver.api.core.CqlSession)10 Test (org.junit.Test)10 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)5 Version (com.datastax.oss.driver.api.core.Version)2 CassandraRequirement (com.datastax.oss.driver.api.testinfra.CassandraRequirement)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 DefaultProtocolVersion (com.datastax.oss.driver.api.core.DefaultProtocolVersion)1 ProtocolVersion (com.datastax.oss.driver.api.core.ProtocolVersion)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 Description (org.junit.runner.Description)1 Failure (org.junit.runner.notification.Failure)1 Statement (org.junit.runners.model.Statement)1