Skip to content

Commit 24fd7d1

Browse files
authored
Merge pull request #163 from muzarski/fix-config-tests
ci: enable `ConfigTests`
2 parents d349cc8 + 9bb33ad commit 24fd7d1

File tree

7 files changed

+121
-5
lines changed

7 files changed

+121
-5
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
# Ignored tests are added in the end, after the "-" sign.
4141
Tests: "ClusterTests.*\
4242
:BasicsTests.*\
43+
:ConfigTests.*\
4344
:PreparedTests.*\
4445
:CassandraTypes/CassandraTypesTests/*.Integration_Cassandra_*\
4546
:BatchSingleNodeClusterTests*:BatchCounterSingleNodeClusterTests*:BatchCounterThreeNodeClusterTests*\

.github/workflows/cassandra.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
# Ignored tests are added in the end, after the "-" sign.
4343
Tests: "ClusterTests.*\
4444
:BasicsTests.*\
45+
:ConfigTests.*\
4546
:PreparedTests.*\
4647
:CassandraTypes/CassandraTypesTests/*.Integration_Cassandra_*\
4748
:ErrorTests.*\

scylla-rust-wrapper/src/cluster.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use scylla::load_balancing::{DefaultPolicyBuilder, LoadBalancingPolicy};
1616
use scylla::retry_policy::RetryPolicy;
1717
use scylla::speculative_execution::SimpleSpeculativeExecutionPolicy;
1818
use scylla::statement::{Consistency, SerialConsistency};
19-
use scylla::SessionBuilder;
19+
use scylla::{SessionBuilder, SessionConfig};
2020
use std::collections::HashMap;
2121
use std::convert::TryInto;
2222
use std::future::Future;
@@ -91,6 +91,21 @@ impl CassCluster {
9191
pub(crate) fn execution_profile_map(&self) -> &HashMap<ExecProfileName, CassExecProfile> {
9292
&self.execution_profile_map
9393
}
94+
95+
#[inline]
96+
pub(crate) fn get_session_config(&self) -> &SessionConfig {
97+
&self.session_builder.config
98+
}
99+
100+
#[inline]
101+
pub(crate) fn get_port(&self) -> u16 {
102+
self.port
103+
}
104+
105+
#[inline]
106+
pub(crate) fn get_contact_points(&self) -> &[String] {
107+
&self.contact_points
108+
}
94109
}
95110

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

179-
if contact_points.peek().is_none() {
195+
if contact_points.peek().is_none() || contact_points.peek().unwrap().is_empty() {
180196
// If cass_cluster_set_contact_points() is called with empty
181197
// set of contact points, the contact points should be cleared.
182198
cluster.contact_points.clear();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use std::ffi::{c_char, CString};
2+
3+
use crate::{
4+
argconv::ptr_to_ref,
5+
cluster::CassCluster,
6+
types::{cass_int32_t, cass_uint16_t, size_t},
7+
};
8+
9+
#[no_mangle]
10+
pub unsafe extern "C" fn testing_cluster_get_connect_timeout(
11+
cluster_raw: *const CassCluster,
12+
) -> cass_uint16_t {
13+
let cluster = ptr_to_ref(cluster_raw);
14+
15+
cluster.get_session_config().connect_timeout.as_millis() as cass_uint16_t
16+
}
17+
18+
#[no_mangle]
19+
pub unsafe extern "C" fn testing_cluster_get_port(cluster_raw: *const CassCluster) -> cass_int32_t {
20+
let cluster = ptr_to_ref(cluster_raw);
21+
22+
cluster.get_port() as cass_int32_t
23+
}
24+
25+
#[no_mangle]
26+
pub unsafe extern "C" fn testing_cluster_get_contact_points(
27+
cluster_raw: *const CassCluster,
28+
contact_points: *mut *mut c_char,
29+
contact_points_length: *mut size_t,
30+
) {
31+
let cluster = ptr_to_ref(cluster_raw);
32+
33+
let contact_points_string = cluster.get_contact_points().join(",");
34+
let length = contact_points_string.len();
35+
36+
match CString::new(contact_points_string) {
37+
Ok(cstring) => {
38+
*contact_points = cstring.into_raw();
39+
*contact_points_length = length as size_t;
40+
}
41+
Err(_) => {
42+
// The contact points string contained a nul byte in the middle.
43+
*contact_points = std::ptr::null_mut();
44+
*contact_points_length = 0;
45+
}
46+
}
47+
}
48+
49+
#[no_mangle]
50+
pub unsafe extern "C" fn testing_free_contact_points(contact_points: *mut c_char) {
51+
let _ = CString::from_raw(contact_points);
52+
}

scylla-rust-wrapper/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod exec_profile;
1818
mod external;
1919
pub mod future;
2020
pub mod inet;
21+
pub mod integration_testing;
2122
mod logging;
2223
pub mod metadata;
2324
pub mod prepared;

src/testing.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include "get_time.hpp"
2222
#include "logger.hpp"
2323
#include "murmur3.hpp"
24+
#include <iostream>
25+
26+
extern "C" {
27+
#include "testing_rust_impls.h"
28+
}
2429

2530
namespace datastax { namespace internal { namespace testing {
2631

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

3742
unsigned get_connect_timeout_from_cluster(CassCluster* cluster) {
38-
throw std::runtime_error("Unimplemented 'get_connect_timeout_from_cluster'!");
43+
return testing_cluster_get_connect_timeout(cluster);
3944
}
4045

4146
int get_port_from_cluster(CassCluster* cluster) {
42-
throw std::runtime_error("Unimplemented 'get_port_from_cluster'!");
47+
return testing_cluster_get_port(cluster);
4348
}
4449

4550
String get_contact_points_from_cluster(CassCluster* cluster) {
46-
throw std::runtime_error("Unimplemented 'get_contact_points_from_cluster'!");
51+
char* contact_points;
52+
size_t contact_points_length;
53+
testing_cluster_get_contact_points(cluster, &contact_points, &contact_points_length);
54+
55+
if (contact_points == nullptr) {
56+
throw std::runtime_error("CassCluster returned a null contact points string.\
57+
This means that one of the contact points contained a nul byte in it.");
58+
}
59+
60+
std::string contact_points_str(contact_points, contact_points_length);
61+
OStringStream ss;
62+
ss << contact_points_str;
63+
64+
testing_free_contact_points(contact_points);
65+
66+
return ss.str();
4767
}
4868

4969
int64_t create_murmur3_hash_from_string(const String& value) {

src/testing_rust_impls.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef CPP_RUST_DRIVER_TESTING_RUST_IMPLS_HPP
2+
#define CPP_RUST_DRIVER_TESTING_RUST_IMPLS_HPP
3+
4+
#include "cassandra.h"
5+
6+
extern "C" {
7+
// Retrieves a connect timeout from cluster config.
8+
CASS_EXPORT cass_uint16_t testing_cluster_get_connect_timeout(CassCluster *cluster);
9+
10+
// Retrieves a CQL connection port from cluster config.
11+
CASS_EXPORT cass_int32_t testing_cluster_get_port(CassCluster* cluster);
12+
13+
// Retrieves a contact points string. The contact points are delimited with ','.
14+
//
15+
// This function can fail, if any of the contact points contains a nul byte.
16+
// Then, the resulting pointer is set to null.
17+
//
18+
// On success, this function allocates a contact points string, which needs to be then
19+
// freed with `testing_free_contact_points`.
20+
CASS_EXPORT void testing_cluster_get_contact_points(CassCluster *cluster, char **contact_points, size_t *contact_points_length);
21+
22+
CASS_EXPORT void testing_free_contact_points(char *contact_points);
23+
}
24+
25+
#endif

0 commit comments

Comments
 (0)