Skip to content

ci: enable ConfigTests #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
# Ignored tests are added in the end, after the "-" sign.
Tests: "ClusterTests.*\
:BasicsTests.*\
:ConfigTests.*\
:PreparedTests.*\
:CassandraTypes/CassandraTypesTests/*.Integration_Cassandra_*\
:BatchSingleNodeClusterTests*:BatchCounterSingleNodeClusterTests*:BatchCounterThreeNodeClusterTests*\
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cassandra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
# Ignored tests are added in the end, after the "-" sign.
Tests: "ClusterTests.*\
:BasicsTests.*\
:ConfigTests.*\
:PreparedTests.*\
:CassandraTypes/CassandraTypesTests/*.Integration_Cassandra_*\
:ErrorTests.*\
Expand Down
20 changes: 18 additions & 2 deletions scylla-rust-wrapper/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use scylla::load_balancing::{DefaultPolicyBuilder, LoadBalancingPolicy};
use scylla::retry_policy::RetryPolicy;
use scylla::speculative_execution::SimpleSpeculativeExecutionPolicy;
use scylla::statement::{Consistency, SerialConsistency};
use scylla::SessionBuilder;
use scylla::{SessionBuilder, SessionConfig};
use std::collections::HashMap;
use std::convert::TryInto;
use std::future::Future;
Expand Down Expand Up @@ -91,6 +91,21 @@ impl CassCluster {
pub(crate) fn execution_profile_map(&self) -> &HashMap<ExecProfileName, CassExecProfile> {
&self.execution_profile_map
}

#[inline]
pub(crate) fn get_session_config(&self) -> &SessionConfig {
&self.session_builder.config
}

#[inline]
pub(crate) fn get_port(&self) -> u16 {
self.port
}

#[inline]
pub(crate) fn get_contact_points(&self) -> &[String] {
&self.contact_points
}
}

pub struct CassCustomPayload;
Expand Down Expand Up @@ -174,9 +189,10 @@ unsafe fn cluster_set_contact_points(
let mut contact_points = ptr_to_cstr_n(contact_points_raw, contact_points_length)
.ok_or(CassError::CASS_ERROR_LIB_BAD_PARAMS)?
.split(',')
.filter(|s| !s.is_empty()) // Extra commas should be ignored.
.peekable();

if contact_points.peek().is_none() {
if contact_points.peek().is_none() || contact_points.peek().unwrap().is_empty() {
// If cass_cluster_set_contact_points() is called with empty
// set of contact points, the contact points should be cleared.
cluster.contact_points.clear();
Expand Down
52 changes: 52 additions & 0 deletions scylla-rust-wrapper/src/integration_testing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::ffi::{c_char, CString};

use crate::{
argconv::ptr_to_ref,
cluster::CassCluster,
types::{cass_int32_t, cass_uint16_t, size_t},
};

#[no_mangle]
pub unsafe extern "C" fn testing_cluster_get_connect_timeout(
cluster_raw: *const CassCluster,
) -> cass_uint16_t {
let cluster = ptr_to_ref(cluster_raw);

cluster.get_session_config().connect_timeout.as_millis() as cass_uint16_t
}

#[no_mangle]
pub unsafe extern "C" fn testing_cluster_get_port(cluster_raw: *const CassCluster) -> cass_int32_t {
let cluster = ptr_to_ref(cluster_raw);

cluster.get_port() as cass_int32_t
}

#[no_mangle]
pub unsafe extern "C" fn testing_cluster_get_contact_points(
cluster_raw: *const CassCluster,
contact_points: *mut *mut c_char,
contact_points_length: *mut size_t,
) {
let cluster = ptr_to_ref(cluster_raw);

let contact_points_string = cluster.get_contact_points().join(",");
let length = contact_points_string.len();

match CString::new(contact_points_string) {
Ok(cstring) => {
*contact_points = cstring.into_raw();
*contact_points_length = length as size_t;
}
Err(_) => {
// The contact points string contained a nul byte in the middle.
*contact_points = std::ptr::null_mut();
*contact_points_length = 0;
}
}
}

#[no_mangle]
pub unsafe extern "C" fn testing_free_contact_points(contact_points: *mut c_char) {
let _ = CString::from_raw(contact_points);
}
1 change: 1 addition & 0 deletions scylla-rust-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod exec_profile;
mod external;
pub mod future;
pub mod inet;
pub mod integration_testing;
mod logging;
pub mod metadata;
pub mod prepared;
Expand Down
26 changes: 23 additions & 3 deletions src/testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#include "get_time.hpp"
#include "logger.hpp"
#include "murmur3.hpp"
#include <iostream>

extern "C" {
#include "testing_rust_impls.h"
}

namespace datastax { namespace internal { namespace testing {

Expand All @@ -35,15 +40,30 @@ StringVec get_attempted_hosts_from_future(CassFuture* future) {
}

unsigned get_connect_timeout_from_cluster(CassCluster* cluster) {
throw std::runtime_error("Unimplemented 'get_connect_timeout_from_cluster'!");
return testing_cluster_get_connect_timeout(cluster);
}

int get_port_from_cluster(CassCluster* cluster) {
throw std::runtime_error("Unimplemented 'get_port_from_cluster'!");
return testing_cluster_get_port(cluster);
}

String get_contact_points_from_cluster(CassCluster* cluster) {
throw std::runtime_error("Unimplemented 'get_contact_points_from_cluster'!");
char* contact_points;
size_t contact_points_length;
testing_cluster_get_contact_points(cluster, &contact_points, &contact_points_length);

if (contact_points == nullptr) {
throw std::runtime_error("CassCluster returned a null contact points string.\
This means that one of the contact points contained a nul byte in it.");
}

std::string contact_points_str(contact_points, contact_points_length);
OStringStream ss;
ss << contact_points_str;

testing_free_contact_points(contact_points);

return ss.str();
}

int64_t create_murmur3_hash_from_string(const String& value) {
Expand Down
25 changes: 25 additions & 0 deletions src/testing_rust_impls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef CPP_RUST_DRIVER_TESTING_RUST_IMPLS_HPP
#define CPP_RUST_DRIVER_TESTING_RUST_IMPLS_HPP

#include "cassandra.h"

extern "C" {
// Retrieves a connect timeout from cluster config.
CASS_EXPORT cass_uint16_t testing_cluster_get_connect_timeout(CassCluster *cluster);

// Retrieves a CQL connection port from cluster config.
CASS_EXPORT cass_int32_t testing_cluster_get_port(CassCluster* cluster);

// Retrieves a contact points string. The contact points are delimited with ','.
//
// This function can fail, if any of the contact points contains a nul byte.
// Then, the resulting pointer is set to null.
//
// On success, this function allocates a contact points string, which needs to be then
// freed with `testing_free_contact_points`.
CASS_EXPORT void testing_cluster_get_contact_points(CassCluster *cluster, char **contact_points, size_t *contact_points_length);

CASS_EXPORT void testing_free_contact_points(char *contact_points);
}

#endif
Loading