Search in sources :

Example 21 with CassandraRequirement

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

the class ProtocolVersionInitialNegotiationIT method should_use_explicitly_provided_v3_oss.

@CassandraRequirement(min = "2.1", description = "Only C* in [2.1,*[ has V3 supported")
@Test
public void should_use_explicitly_provided_v3_oss() {
    Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V3").build();
    try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
        assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(3);
        session.execute("select * from system.local");
    }
}
Also used : DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 22 with CassandraRequirement

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

the class ProtocolVersionInitialNegotiationIT method should_fail_if_provided_v5_is_not_supported_oss.

@CassandraRequirement(min = "2.1", max = "4.0-rc1", description = "Only C* in [2.1,4.0-rc1[ has V5 unsupported or supported as beta")
@Test
public void should_fail_if_provided_v5_is_not_supported_oss() {
    Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V5").build();
    try (CqlSession ignored = SessionUtils.newSession(ccm, loader)) {
        fail("Expected an AllNodesFailedException");
    } catch (AllNodesFailedException anfe) {
        Throwable cause = anfe.getAllErrors().values().iterator().next().get(0);
        assertThat(cause).isInstanceOf(UnsupportedProtocolVersionException.class);
        UnsupportedProtocolVersionException unsupportedException = (UnsupportedProtocolVersionException) cause;
        assertThat(unsupportedException.getAttemptedVersions()).containsOnly(DefaultProtocolVersion.V5);
    }
}
Also used : AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) UnsupportedProtocolVersionException(com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 23 with CassandraRequirement

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

the class ProtocolVersionInitialNegotiationIT method should_use_explicitly_provided_v4_oss.

@CassandraRequirement(min = "2.2", description = "Only C* in [2.2,*[ has V4 supported")
@Test
public void should_use_explicitly_provided_v4_oss() {
    Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V4").build();
    try (CqlSession session = SessionUtils.newSession(ccm, loader)) {
        assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(4);
        session.execute("select * from system.local");
    }
}
Also used : DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 24 with CassandraRequirement

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

the class ProtocolVersionInitialNegotiationIT method should_downgrade_to_v3_oss.

@CassandraRequirement(min = "2.1", max = "2.2", description = "Only C* in [2.1,2.2[ has V3 as its highest version")
@Test
public void should_downgrade_to_v3_oss() {
    Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
    try (CqlSession session = SessionUtils.newSession(ccm)) {
        assertThat(session.getContext().getProtocolVersion().getCode()).isEqualTo(3);
        session.execute("select * from system.local");
    }
}
Also used : CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 25 with CassandraRequirement

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

the class SchemaIT method should_get_virtual_metadata.

@CassandraRequirement(min = "4.0", description = "virtual tables introduced in 4.0")
@Test
public void should_get_virtual_metadata() {
    skipIfDse60();
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withStringList(DefaultDriverOption.METADATA_SCHEMA_REFRESHED_KEYSPACES, Collections.singletonList("system_views")).build();
    try (CqlSession session = SessionUtils.newSession(ccmRule, loader)) {
        Metadata md = session.getMetadata();
        KeyspaceMetadata kmd = md.getKeyspace("system_views").get();
        // Keyspace name should be set, marked as virtual, and have at least sstable_tasks table.
        // All other values should be defaulted since they are not defined in the virtual schema
        // tables.
        assertThat(kmd.getTables().size()).isGreaterThanOrEqualTo(1);
        assertThat(kmd.isVirtual()).isTrue();
        assertThat(kmd.isDurableWrites()).isFalse();
        assertThat(kmd.getName().asCql(true)).isEqualTo("system_views");
        // Virtual tables lack User Types, Functions, Views and Aggregates
        assertThat(kmd.getUserDefinedTypes().size()).isEqualTo(0);
        assertThat(kmd.getFunctions().size()).isEqualTo(0);
        assertThat(kmd.getViews().size()).isEqualTo(0);
        assertThat(kmd.getAggregates().size()).isEqualTo(0);
        assertThat(kmd.describe(true)).isEqualTo("/* VIRTUAL KEYSPACE system_views WITH replication = { 'class' : 'null' } " + "AND durable_writes = false; */");
        // Table name should be set, marked as virtual, and it should have columns set.
        // indexes, views, clustering column, clustering order and id are not defined in the virtual
        // schema tables.
        TableMetadata tm = kmd.getTable("sstable_tasks").get();
        assertThat(tm).isNotNull();
        assertThat(tm.getName().toString()).isEqualTo("sstable_tasks");
        assertThat(tm.isVirtual()).isTrue();
        // DSE 6.8+ reports 7 columns, Cassandra 4+ reports 8 columns
        assertThat(tm.getColumns().size()).isGreaterThanOrEqualTo(7);
        assertThat(tm.getIndexes().size()).isEqualTo(0);
        assertThat(tm.getPartitionKey().size()).isEqualTo(1);
        assertThat(tm.getPartitionKey().get(0).getName().toString()).isEqualTo("keyspace_name");
        assertThat(tm.getClusteringColumns().size()).isEqualTo(2);
        assertThat(tm.getId().isPresent()).isFalse();
        assertThat(tm.getOptions().size()).isEqualTo(0);
        assertThat(tm.getKeyspace()).isEqualTo(kmd.getName());
        assertThat(tm.describe(true)).isIn(// DSE 6.8+
        "/* VIRTUAL TABLE system_views.sstable_tasks (\n" + "    keyspace_name text,\n" + "    table_name text,\n" + "    task_id uuid,\n" + "    kind text,\n" + "    progress bigint,\n" + "    total bigint,\n" + "    unit text,\n" + "    PRIMARY KEY (keyspace_name, table_name, task_id)\n" + "); */", // Cassandra 4.0
        "/* VIRTUAL TABLE system_views.sstable_tasks (\n" + "    keyspace_name text,\n" + "    table_name text,\n" + "    task_id uuid,\n" + "    completion_ratio double,\n" + "    kind text,\n" + "    progress bigint,\n" + "    total bigint,\n" + "    unit text,\n" + "    PRIMARY KEY (keyspace_name, table_name, task_id)\n" + "); */");
        // ColumnMetadata is as expected
        ColumnMetadata cm = tm.getColumn("progress").get();
        assertThat(cm).isNotNull();
        assertThat(cm.getParent()).isEqualTo(tm.getName());
        assertThat(cm.getType()).isEqualTo(DataTypes.BIGINT);
        assertThat(cm.getName().toString()).isEqualTo("progress");
    }
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) CqlSession(com.datastax.oss.driver.api.core.CqlSession) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Aggregations

CassandraRequirement (com.datastax.oss.driver.api.testinfra.CassandraRequirement)29 Test (org.junit.Test)27 CqlSession (com.datastax.oss.driver.api.core.CqlSession)21 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)8 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)7 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)6 Row (com.datastax.oss.driver.api.core.cql.Row)6 ByteBuffer (java.nio.ByteBuffer)5 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)3 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)3 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)3 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)3 AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)2 UnsupportedProtocolVersionException (com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException)2 Version (com.datastax.oss.driver.api.core.Version)2 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)2 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)2 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)2 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)2 DseRequirement (com.datastax.oss.driver.api.testinfra.DseRequirement)2