Skip to content

Commit 26bc5d4

Browse files
committed
Fix ConfigTests tests
Added implementation for functions in `testing.cpp` used in `ConfigTests` tests: * get_connect_timeout_from_cluster * get_port_from_cluster * get_contact_points_from_cluster To avoid generating bindings for functions that are directly under namespaces and may return objects of custom types, `testing_utils` header is added as median between the Rust implementation of those functions and the `testing.hpp` header. Added `ConfigTests` tests to GitHub Actions for Cassandra and ScyllaDB.
1 parent 3e56f66 commit 26bc5d4

File tree

8 files changed

+125
-7
lines changed

8 files changed

+125
-7
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
:SslNoClusterTests*:SslNoSslOnClusterTests*\
4545
:SchemaMetadataTest.*KeyspaceMetadata:SchemaMetadataTest.*MetadataIterator\
4646
:TracingTests.*\
47+
:ConfigTests.*\
4748
:-PreparedTests.Integration_Cassandra_PreparedIDUnchangedDuringReprepare\
4849
:*5.Integration_Cassandra_*\
4950
:*19.Integration_Cassandra_*"

.github/workflows/cassandra.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
:SslClientAuthenticationTests*:SslNoClusterTests*:SslNoSslOnClusterTests*:SslTests*\
5050
:SchemaMetadataTest.*KeyspaceMetadata:SchemaMetadataTest.*MetadataIterator\
5151
:TracingTests.*\
52+
:ConfigTests.*\
5253
:-PreparedTests.Integration_Cassandra_PreparedIDUnchangedDuringReprepare\
5354
:*5.Integration_Cassandra_*\
5455
:*19.Integration_Cassandra_*\

scylla-rust-wrapper/src/cluster.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ enum CassClusterChildLoadBalancingPolicy {
2525

2626
#[derive(Clone)]
2727
pub struct CassCluster {
28-
session_builder: SessionBuilder,
28+
pub session_builder: SessionBuilder,
2929

30-
contact_points: Vec<String>,
31-
port: u16,
30+
pub contact_points: Vec<String>,
31+
pub port: u16,
3232

3333
child_load_balancing_policy: CassClusterChildLoadBalancingPolicy,
3434
token_aware_policy_enabled: bool,
@@ -123,9 +123,10 @@ unsafe fn cluster_set_contact_points(
123123
let mut contact_points = ptr_to_cstr_n(contact_points_raw, contact_points_length)
124124
.ok_or(CassError::CASS_ERROR_LIB_BAD_PARAMS)?
125125
.split(',')
126+
.filter(|s| !s.is_empty()) // Extra commas should be ignored
126127
.peekable();
127128

128-
if contact_points.peek().is_none() {
129+
if contact_points.peek().is_none() || contact_points.peek().unwrap().is_empty() {
129130
// If cass_cluster_set_contact_points() is called with empty
130131
// set of contact points, the contact points should be cleared.
131132
cluster.contact_points.clear();

scylla-rust-wrapper/src/testing.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1+
use crate::argconv::{free_boxed, ptr_to_ref, write_str_to_c};
2+
use crate::cluster::CassCluster;
3+
use crate::types::*;
4+
use std::os::raw::c_char;
15

6+
#[no_mangle]
7+
pub unsafe extern "C" fn testing_get_connect_timeout_from_cluster(
8+
cluster: *mut CassCluster,
9+
) -> cass_uint16_t {
10+
let cluster = ptr_to_ref(cluster);
11+
cluster.session_builder.config.connect_timeout.as_millis() as cass_uint16_t
12+
}
13+
14+
#[no_mangle]
15+
pub unsafe extern "C" fn testing_get_contact_points_from_cluster(
16+
cluster: *mut CassCluster,
17+
contact_points: *mut *const c_char,
18+
contact_points_length: *mut size_t,
19+
contact_points_boxed: *mut *const String,
20+
) {
21+
let cluster = ptr_to_ref(cluster);
22+
let str = Box::new(cluster.contact_points.join(","));
23+
let result = str.as_str();
24+
25+
write_str_to_c(result, contact_points, contact_points_length);
26+
*contact_points_boxed = Box::into_raw(str);
27+
}
28+
29+
#[no_mangle]
30+
pub unsafe extern "C" fn testing_free_contact_points_string(contact_points_boxed: *mut String) {
31+
free_boxed(contact_points_boxed)
32+
}
33+
34+
#[no_mangle]
35+
pub unsafe extern "C" fn testing_get_port_from_cluster(cluster: *mut CassCluster) -> cass_int32_t {
36+
let cluster = ptr_to_ref(cluster);
37+
38+
cluster.port as cass_int32_t
39+
}

src/testing.cpp

Lines changed: 19 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_utils.h"
28+
}
2429

2530
namespace datastax { namespace internal { namespace testing {
2631

@@ -35,15 +40,26 @@ 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_get_connect_timeout_from_cluster(cluster);
3944
}
4045

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

4550
String get_contact_points_from_cluster(CassCluster* cluster) {
46-
throw std::runtime_error("Unimplemented 'get_contact_points_from_cluster'!");
51+
const char* contact_points;
52+
size_t contact_points_length;
53+
void *contact_points_boxed;
54+
testing_get_contact_points_from_cluster(cluster, &contact_points, &contact_points_length, &contact_points_boxed);
55+
56+
std::string contact_points_str(contact_points, contact_points_length);
57+
OStringStream ss;
58+
ss << contact_points_str;
59+
60+
testing_free_contact_points_string(contact_points_boxed);
61+
62+
return ss.str();
4763
}
4864

4965
int64_t create_murmur3_hash_from_string(const String& value) {

src/testing_utils.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "testing_utils.h"
2+
#include <stdexcept>
3+
4+
CASS_EXPORT CassConsistency testing_get_consistency(const CassStatement* statement) {
5+
throw std::runtime_error("UNIMPLEMENTED testing_get_consistency\n");
6+
}
7+
8+
CASS_EXPORT CassConsistency testing_get_serial_consistency(const CassStatement* statement) {
9+
throw std::runtime_error("UNIMPLEMENTED testing_get_serial_consistency\n");
10+
}
11+
12+
CASS_EXPORT cass_uint64_t testing_get_request_timeout_ms(const CassStatement* statement) {
13+
throw std::runtime_error("UNIMPLEMENTED testing_get_request_timeout_ms\n");
14+
}
15+
16+
CASS_EXPORT const CassRetryPolicy* testing_get_retry_policy(const CassStatement* statement) {
17+
throw std::runtime_error("UNIMPLEMENTED testing_get_retry_policy\n");
18+
}
19+
20+
CASS_EXPORT const char* testing_get_server_name(CassFuture* future) {
21+
throw std::runtime_error("UNIMPLEMENTED testing_get_server_name\n");
22+
}
23+
24+
CASS_EXPORT void testing_set_record_attempted_hosts(CassStatement* statement, cass_bool_t enable) {
25+
throw std::runtime_error("UNIMPLEMENTED testing_set_record_attempted_hosts\n");
26+
}

src/testing_utils.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef CPPDRIVERV2_TESTING_UTILS_H
2+
#define CPPDRIVERV2_TESTING_UTILS_H
3+
4+
#include "cassandra.h"
5+
6+
extern "C" {
7+
CASS_EXPORT cass_uint16_t testing_get_connect_timeout_from_cluster(CassCluster* cluster);
8+
9+
CASS_EXPORT cass_int32_t testing_get_port_from_cluster(CassCluster* cluster);
10+
11+
CASS_EXPORT void
12+
testing_get_contact_points_from_cluster(
13+
CassCluster* cluster,
14+
const char** contact_points,
15+
size_t* contact_points_length,
16+
void** contact_points_boxed
17+
);
18+
19+
CASS_EXPORT void testing_free_contact_points_string(void* box);
20+
21+
CASS_EXPORT CassConsistency testing_get_consistency(const CassStatement* statement);
22+
23+
CASS_EXPORT CassConsistency testing_get_serial_consistency(const CassStatement* statement);
24+
25+
CASS_EXPORT cass_uint64_t testing_get_request_timeout_ms(const CassStatement* statement);
26+
27+
CASS_EXPORT const CassRetryPolicy* testing_get_retry_policy(const CassStatement* statement);
28+
29+
CASS_EXPORT const char* testing_get_server_name(CassFuture* future);
30+
31+
CASS_EXPORT void testing_set_record_attempted_hosts(CassStatement* statement, cass_bool_t enable);
32+
}
33+
34+
#endif //CPPDRIVERV2_TESTING_UTILS_H

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ set(CPP_DRIVER_SOURCE_FILES
124124
${CASS_SRC_DIR}/testing.cpp
125125
${CASS_SRC_DIR}/logger.cpp
126126
${CASS_SRC_DIR}/testing_unimplemented.cpp
127+
${CASS_SRC_DIR}/testing_utils.cpp
127128
)
128129
if(APPLE)
129130
list(REMOVE_ITEM CPP_DRIVER_SOURCE_FILES ${CASS_SRC_DIR}/get_time-unix.cpp ${CASS_SRC_DIR}/get_time-win.cpp)

0 commit comments

Comments
 (0)