Skip to content

Commit

Permalink
allow setting per-statement request timeout (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Rick Newton-Rogers <[email protected]>
  • Loading branch information
yim-lee and rnro authored Nov 14, 2022
1 parent f42a51d commit 6a9c284
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 14 additions & 2 deletions Sources/CassandraClient/Statement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ extension CassandraClient {
if let consistency = options.consistency {
try checkResult { cass_statement_set_consistency(self.rawPointer, consistency.cassConsistency) }
}

if let requestTimeout = options.requestTimeout {
try checkResult { cass_statement_set_request_timeout(self.rawPointer, requestTimeout) }
}
}

func setPagingSize(_ pagingSize: Int32) throws {
Expand Down Expand Up @@ -118,13 +122,21 @@ extension CassandraClient {
public struct Options: CustomStringConvertible {
/// Sets the statement's consistency level. Default is `.localOne`.
public var consistency: CassandraClient.Consistency?
/// Sets the statement's request timeout in milliseconds. Default is `CASS_UINT64_MAX`
public var requestTimeout: UInt64?

public init(consistency: CassandraClient.Consistency? = .none) {
public init(consistency: CassandraClient.Consistency? = nil, requestTimeout: UInt64? = nil) {
self.consistency = consistency
self.requestTimeout = requestTimeout
}

public var description: String {
"Options { consistency: \(String(describing: self.consistency)) }"
"""
Options {
consistency: \(String(describing: self.consistency)),
requestTimeout: \(String(describing: self.requestTimeout))
}
"""
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/CassandraClientTests/CassandraClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ final class Tests: XCTestCase {
let tableName = "test_\(DispatchTime.now().uptimeNanoseconds)"
XCTAssertNoThrow(try self.cassandraClient.run("create table \(tableName) (id int primary key, data text);").wait())

var options = CassandraClient.Statement.Options()
options.consistency = .localQuorum
let options = CassandraClient.Statement.Options(consistency: .localQuorum)

let count = Int.random(in: 5000 ... 6000)
var futures = [EventLoopFuture<Void>]()
Expand Down

0 comments on commit 6a9c284

Please sign in to comment.