Skip to content

Commit ce3225b

Browse files
committed
Trying to fix as much of the base CQL stuff as possible.
Big chunks of this are based on/copied wholesale from previous work done by Arthur Landim (datastax#17)
1 parent ecd60a7 commit ce3225b

File tree

2 files changed

+98
-99
lines changed

2 files changed

+98
-99
lines changed

src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatements.scala

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,25 @@ package com.datastax.gatling.plugin.model
99
import java.nio.ByteBuffer
1010

1111
import com.datastax.oss.driver.api.core.cql._
12-
import com.datastax.oss.driver.api.core.`type`.DataType
1312
import com.datastax.gatling.plugin.exceptions.DseCqlStatementException
1413
import com.datastax.gatling.plugin.utils.CqlPreparedStatementUtil
1514
import io.gatling.commons.validation._
16-
import io.gatling.core.session.{Session, _}
15+
import io.gatling.core.session._
1716

1817
import scala.collection.JavaConverters._
19-
import scala.collection.mutable.ArrayBuffer
2018
import scala.util.{Try, Failure => TryFailure, Success => TrySuccess}
2119

2220

23-
trait DseCqlStatement extends DseStatement[Statement] {
24-
def buildFromSession(session: Session): Validation[Statement]
21+
trait DseCqlStatement[T] extends DseStatement[T] {
22+
def buildFromSession(session: Session): Validation[T]
2523
}
2624

2725
/**
2826
* Simple CQL Statement from the java driver
2927
*
3028
* @param statement the statement to execute
3129
*/
32-
case class DseCqlSimpleStatement(statement: SimpleStatement) extends DseCqlStatement {
30+
case class DseCqlSimpleStatement(statement: SimpleStatement) extends DseCqlStatement[SimpleStatement] {
3331
def buildFromSession(gatlingSession: Session): Validation[SimpleStatement] = {
3432
statement.success
3533
}
@@ -41,7 +39,7 @@ case class DseCqlSimpleStatement(statement: SimpleStatement) extends DseCqlState
4139
* @param preparedStatement the prepared statement on which to bind parameters
4240
*/
4341
case class DseCqlBoundStatementNamed(cqlTypes: CqlPreparedStatementUtil, preparedStatement: PreparedStatement)
44-
extends DseCqlStatement {
42+
extends DseCqlStatement[BoundStatement] {
4543

4644
def buildFromSession(gatlingSession: Session): Validation[BoundStatement] =
4745
bindParams(
@@ -58,7 +56,7 @@ case class DseCqlBoundStatementNamed(cqlTypes: CqlPreparedStatementUtil, prepare
5856
* @return
5957
*/
6058
protected def bindParams(gatlingSession: Session, boundStatement: BoundStatement,
61-
queryParams: Map[String, DataType.Name]): BoundStatement = {
59+
queryParams: Map[String, Int]): BoundStatement = {
6260
queryParams.foreach {
6361
case (gatlingSessionKey, valType) =>
6462
cqlTypes.bindParamByName(gatlingSession, boundStatement, valType, gatlingSessionKey)
@@ -75,7 +73,7 @@ case class DseCqlBoundStatementNamed(cqlTypes: CqlPreparedStatementUtil, prepare
7573
*/
7674
case class DseCqlBoundStatementWithPassedParams(cqlTypes: CqlPreparedStatementUtil,
7775
preparedStatement: PreparedStatement,
78-
params: Expression[AnyRef]*) extends DseCqlStatement {
76+
params: Expression[AnyRef]*) extends DseCqlStatement[BoundStatement] {
7977

8078
def buildFromSession(gatlingSession: Session): Validation[BoundStatement] = {
8179
val parsedParams: Seq[Validation[AnyRef]] = params.map(param => param(gatlingSession))
@@ -99,7 +97,7 @@ case class DseCqlBoundStatementWithPassedParams(cqlTypes: CqlPreparedStatementUt
9997
*/
10098
case class DseCqlBoundStatementWithParamList(cqlTypes: CqlPreparedStatementUtil,
10199
preparedStatement: PreparedStatement,
102-
sessionKeys: Seq[String]) extends DseCqlStatement {
100+
sessionKeys: Seq[String]) extends DseCqlStatement[BoundStatement] {
103101

104102
/**
105103
* Apply the Gatling session params to the Prepared statement
@@ -142,16 +140,16 @@ case class DseCqlBoundStatementWithParamList(cqlTypes: CqlPreparedStatementUtil,
142140
* @param statements CQL Prepared Statements
143141
*/
144142
case class DseCqlBoundBatchStatement(cqlTypes: CqlPreparedStatementUtil, statements: Seq[PreparedStatement])
145-
extends DseCqlStatement {
143+
extends DseCqlStatement[BatchStatement] {
146144

147145
def buildFromSession(gatlingSession: Session): Validation[BatchStatement] = {
148146

149-
val batch = new BatchStatement()
147+
val batch = BatchStatement.builder(DefaultBatchType.LOGGED)
150148

151149
statements.foreach(s =>
152-
batch.add(bindParams(gatlingSession, s, cqlTypes.getParamsMap(s))))
150+
batch.addStatement(bindParams(gatlingSession, s, cqlTypes.getParamsMap(s))))
153151

154-
batch.success
152+
batch.build().success
155153
}
156154

157155

@@ -164,7 +162,7 @@ case class DseCqlBoundBatchStatement(cqlTypes: CqlPreparedStatementUtil, stateme
164162
* @return
165163
*/
166164
protected def bindParams(gatlingSession: Session, statement: PreparedStatement,
167-
queryParams: Map[String, DataType.Name]): BoundStatement = {
165+
queryParams: Map[String, Int]): BoundStatement = {
168166

169167
val boundStatement = statement.bind()
170168

@@ -185,17 +183,18 @@ case class DseCqlBoundBatchStatement(cqlTypes: CqlPreparedStatementUtil, stateme
185183
* @param statement SimpleStaten
186184
* @param payloadRef session variable for custom payload
187185
*/
188-
case class DseCqlCustomPayloadStatement(statement: SimpleStatement, payloadRef: String) extends DseCqlStatement {
186+
case class DseCqlCustomPayloadStatement(statement: SimpleStatement, payloadRef: String)
187+
extends DseCqlStatement[SimpleStatement] {
189188

190-
def buildFromSession(gatlingSession: Session): Validation[Statement] = {
189+
def buildFromSession(gatlingSession: Session): Validation[SimpleStatement] = {
191190

192191
if (!gatlingSession.contains(payloadRef)) {
193192
throw new DseCqlStatementException(s"Passed sessionKey: {$payloadRef} does not exist in Session.")
194193
}
195194

196195
Try {
197196
val payload = gatlingSession(payloadRef).as[Map[String, ByteBuffer]].asJava
198-
statement.setOutgoingPayload(payload)
197+
statement.setCustomPayload(payload)
199198
} match {
200199
case TrySuccess(stmt) => stmt.success
201200
case TryFailure(error) => error.getMessage.failure
@@ -210,7 +209,8 @@ case class DseCqlCustomPayloadStatement(statement: SimpleStatement, payloadRef:
210209
*
211210
* @param sessionKey the session key which is associated to a PreparedStatement
212211
*/
213-
case class DseCqlBoundStatementNamedFromSession(cqlTypes: CqlPreparedStatementUtil, sessionKey: String) extends DseCqlStatement {
212+
case class DseCqlBoundStatementNamedFromSession(cqlTypes: CqlPreparedStatementUtil, sessionKey: String)
213+
extends DseCqlStatement[BoundStatement] {
214214

215215
def buildFromSession(gatlingSession: Session): Validation[BoundStatement] = {
216216
if (!gatlingSession.contains(sessionKey)) {

0 commit comments

Comments
 (0)