From 312aca8a92ae53c06f3c2fad7657081aafd6ca68 Mon Sep 17 00:00:00 2001 From: Arthur Landim Date: Thu, 4 Jul 2019 13:13:14 -0300 Subject: [PATCH 1/3] [wip] Upgrade java dse driver to 2.x --- build.sbt | 6 +- .../datastax/gatling/plugin/DseProtocol.scala | 3 +- .../com/datastax/gatling/plugin/Predef.scala | 7 +- .../gatling/plugin/checks/CqlChecks.scala | 2 +- .../gatling/plugin/checks/GenericChecks.scala | 16 ++- .../gatling/plugin/checks/GraphChecks.scala | 11 +- .../plugin/model/DseCqlAttributes.scala | 11 +- .../model/DseCqlAttributesBuilder.scala | 19 +-- .../model/DseCqlStatementBuilders.scala | 34 ++--- .../plugin/model/DseCqlStatements.scala | 44 +++--- .../plugin/model/DseGraphAttributes.scala | 9 +- .../model/DseGraphAttributesBuilder.scala | 9 +- .../model/DseGraphStatementBuilders.scala | 5 +- .../plugin/model/DseGraphStatements.scala | 34 ++--- .../plugin/request/CqlRequestAction.scala | 25 ++-- .../request/CqlRequestActionBuilder.scala | 2 +- .../plugin/request/DseRequestActor.scala | 10 +- .../plugin/request/GraphRequestAction.scala | 16 ++- .../gatling/plugin/response/DseResponse.scala | 54 ++++---- .../plugin/response/DseResponseHandler.scala | 14 +- .../utils/CqlPreparedStatementUtil.scala | 128 +++++++++--------- .../gatling/plugin/utils/FutureUtils.scala | 26 ++-- .../gatling/plugin/DseCqlStatementSpec.scala | 13 +- .../plugin/request/CqlRequestActionSpec.scala | 8 +- version.sbt | 2 +- 25 files changed, 266 insertions(+), 242 deletions(-) diff --git a/build.sbt b/build.sbt index cc5ed16..37c9391 100644 --- a/build.sbt +++ b/build.sbt @@ -4,11 +4,13 @@ val gatlingVersion = "2.3.0" scalacOptions += "-target:jvm-1.8" -libraryDependencies += "com.datastax.dse" % "dse-java-driver-core" % "1.6.8" -libraryDependencies += "com.datastax.dse" % "dse-java-driver-graph" % "1.6.8" +libraryDependencies += "com.datastax.dse" % "dse-java-driver-core" % "2.0.1" +libraryDependencies += "com.datastax.dse" % "dse-java-driver-graph" % "1.8.1" libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "2.18.0" libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.9.1" libraryDependencies += "org.hdrhistogram" % "HdrHistogram" % "2.1.10" +libraryDependencies += "com.google.guava" % "guava" % "23.0" + libraryDependencies += "io.gatling.highcharts" % "gatling-charts-highcharts" % gatlingVersion % Provided diff --git a/src/main/scala/com/datastax/gatling/plugin/DseProtocol.scala b/src/main/scala/com/datastax/gatling/plugin/DseProtocol.scala index e1c8863..efd628d 100644 --- a/src/main/scala/com/datastax/gatling/plugin/DseProtocol.scala +++ b/src/main/scala/com/datastax/gatling/plugin/DseProtocol.scala @@ -11,7 +11,7 @@ import java.util.concurrent.atomic.AtomicLong import akka.Done import akka.actor.ActorSystem -import com.datastax.driver.dse.DseSession +import com.datastax.dse.driver.api.core.DseSession import com.datastax.gatling.plugin.metrics.MetricsLogger import com.datastax.gatling.plugin.request.{CqlRequestActionBuilder, GraphRequestActionBuilder} import com.datastax.gatling.plugin.utils.GatlingTimingSource @@ -132,4 +132,3 @@ object DseProtocolBuilder { case class DseProtocolBuilder(session: DseSession) { def build = DseProtocol(session) } - diff --git a/src/main/scala/com/datastax/gatling/plugin/Predef.scala b/src/main/scala/com/datastax/gatling/plugin/Predef.scala index ac3f89f..0c43cac 100644 --- a/src/main/scala/com/datastax/gatling/plugin/Predef.scala +++ b/src/main/scala/com/datastax/gatling/plugin/Predef.scala @@ -7,8 +7,9 @@ package com.datastax.gatling.plugin import com.datastax.gatling.plugin.checks.DseCheckSupport -import com.datastax.gatling.plugin.model.{DseCqlAttributesBuilder, DseCqlStatementBuilder, DseGraphStatementBuilder, DseGraphAttributesBuilder} +import com.datastax.gatling.plugin.model.{DseCqlAttributesBuilder, DseCqlStatementBuilder, DseGraphAttributesBuilder, DseGraphStatementBuilder} import com.datastax.gatling.plugin.request._ +import com.datastax.oss.driver.api.core.cql.SimpleStatement import io.gatling.core.action.builder.ActionBuilder import scala.language.implicitConversions @@ -30,13 +31,13 @@ trait DsePredefBase extends DseCheckSupport { @deprecated("use dseProtocolBuilder instead, will be removed in future versions") val cql: DseProtocolBuilder.type = dseProtocolBuilder - def cql(tag: String): DseCqlStatementBuilder = DseCqlStatementBuilder(tag) + def cql(tag: String): DseCqlStatementBuilder[SimpleStatement] = DseCqlStatementBuilder(tag) def graph(tag: String): DseGraphStatementBuilder = DseGraphStatementBuilder(tag) implicit def protocolBuilder2DseProtocol(builder: DseProtocolBuilder): DseProtocol = builder.build - implicit def cqlRequestAttributes2ActionBuilder(builder: DseCqlAttributesBuilder): ActionBuilder = builder.build() + implicit def cqlRequestAttributes2ActionBuilder(builder: DseCqlAttributesBuilder[SimpleStatement]): ActionBuilder = builder.build() implicit def graphRequestAttributes2ActionBuilder(builder: DseGraphAttributesBuilder): ActionBuilder = builder.build() } diff --git a/src/main/scala/com/datastax/gatling/plugin/checks/CqlChecks.scala b/src/main/scala/com/datastax/gatling/plugin/checks/CqlChecks.scala index 567f533..f4ace84 100644 --- a/src/main/scala/com/datastax/gatling/plugin/checks/CqlChecks.scala +++ b/src/main/scala/com/datastax/gatling/plugin/checks/CqlChecks.scala @@ -6,7 +6,7 @@ package com.datastax.gatling.plugin.checks -import com.datastax.driver.core.{ResultSet, Row} +import com.datastax.oss.driver.api.core.cql.{ResultSet, Row} import com.datastax.gatling.plugin.response.CqlResponse import io.gatling.commons.validation.{SuccessWrapper, Validation} import io.gatling.core.check._ diff --git a/src/main/scala/com/datastax/gatling/plugin/checks/GenericChecks.scala b/src/main/scala/com/datastax/gatling/plugin/checks/GenericChecks.scala index 13ea365..8fe1919 100644 --- a/src/main/scala/com/datastax/gatling/plugin/checks/GenericChecks.scala +++ b/src/main/scala/com/datastax/gatling/plugin/checks/GenericChecks.scala @@ -6,7 +6,9 @@ package com.datastax.gatling.plugin.checks -import com.datastax.driver.core._ +import com.datastax.oss.driver.api.core.cql._ +import com.datastax.oss.driver.api.core._ +import com.datastax.oss.driver.api.core.metadata._ import com.datastax.gatling.plugin.response.DseResponse import io.gatling.commons.validation.{SuccessWrapper, Validation} import io.gatling.core.check.extractor.{Extractor, SingleArity} @@ -14,6 +16,7 @@ import io.gatling.core.check._ import io.gatling.core.session.{Expression, ExpressionSuccessWrapper, Session} import scala.collection.mutable +import java.nio.ByteBuffer /** * This class allows to execute checks on either CQL or Graph responses. @@ -61,7 +64,7 @@ object GenericChecks { .toCheckBuilder val queriedHost = - new GenericResponseExtractor[Host]( + new GenericResponseExtractor[Node]( "queriedHost", r => r.queriedHost()) .toCheckBuilder @@ -69,7 +72,7 @@ object GenericChecks { val achievedConsistencyLevel = new GenericResponseExtractor[ConsistencyLevel]( "achievedConsistencyLevel", - r => r.achievedConsistencyLevel()) + r => r.executionInfo().getStatement.getConsistencyLevel()) .toCheckBuilder val speculativeExecutionsExtractor = @@ -79,13 +82,13 @@ object GenericChecks { .toCheckBuilder val pagingState = - new GenericResponseExtractor[PagingState]( + new GenericResponseExtractor[ByteBuffer]( "pagingState", r => r.pagingState()) .toCheckBuilder val triedHosts = - new GenericResponseExtractor[List[Host]]( + new GenericResponseExtractor[List[Node]]( "triedHost", r => r.triedHosts()) .toCheckBuilder @@ -123,7 +126,6 @@ object GenericChecks { val exhausted = new GenericResponseExtractor[Boolean]( "exhausted", - r => r.exhausted()) + r => r.applied()) .toCheckBuilder } - diff --git a/src/main/scala/com/datastax/gatling/plugin/checks/GraphChecks.scala b/src/main/scala/com/datastax/gatling/plugin/checks/GraphChecks.scala index d3ed9ac..643e8b8 100644 --- a/src/main/scala/com/datastax/gatling/plugin/checks/GraphChecks.scala +++ b/src/main/scala/com/datastax/gatling/plugin/checks/GraphChecks.scala @@ -6,12 +6,15 @@ package com.datastax.gatling.plugin.checks -import com.datastax.driver.dse.graph._ +import com.datastax.dse.driver.api.core.graph._ +import org.apache.tinkerpop.gremlin.structure.Property import com.datastax.gatling.plugin.response.GraphResponse import io.gatling.commons.validation.{SuccessWrapper, Validation} import io.gatling.core.check.extractor.{Extractor, SingleArity} import io.gatling.core.check._ import io.gatling.core.session.{Expression, ExpressionSuccessWrapper, Session} +import org.apache.tinkerpop.gremlin.structure._ +import org.apache.tinkerpop.gremlin.process.traversal.Path import scala.collection.mutable @@ -89,14 +92,14 @@ object GraphChecks { .toCheckBuilder def properties(column: String) = - new GraphResponseExtractor[Seq[Property]]( + new GraphResponseExtractor[Seq[Property[String]]]( "properties", r => r.getProperties(column)) .toCheckBuilder def vertexProperties(column: String) = - new GraphResponseExtractor[Seq[Property]]( + new GraphResponseExtractor[Seq[Property[String]]]( "vertexProperties", r => r.getVertexProperties(column)) .toCheckBuilder -} \ No newline at end of file +} diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributes.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributes.scala index 455b820..e2f8cb7 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributes.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributes.scala @@ -8,8 +8,9 @@ package com.datastax.gatling.plugin.model import java.nio.ByteBuffer -import com.datastax.driver.core.policies.RetryPolicy -import com.datastax.driver.core.{ConsistencyLevel, PagingState, Statement} +import com.datastax.oss.driver.api.core.retry.RetryPolicy +import com.datastax.oss.driver.api.core.ConsistencyLevel +import com.datastax.oss.driver.api.core.cql.Statement import com.datastax.gatling.plugin.response.{CqlResponse, DseResponse} import io.gatling.core.check.Check @@ -36,8 +37,8 @@ import io.gatling.core.check.Check * @param cqlStatements String version of the CQL statement that is sent * */ -case class DseCqlAttributes(tag: String, - statement: DseStatement[Statement], +case class DseCqlAttributes[T](tag: String, + statement: DseCqlStatement[T], cl: Option[ConsistencyLevel] = None, cqlChecks: List[Check[CqlResponse]] = List.empty, genericChecks: List[Check[DseResponse]] = List.empty, @@ -50,5 +51,5 @@ case class DseCqlAttributes(tag: String, serialCl: Option[ConsistencyLevel] = None, fetchSize: Option[Int] = None, retryPolicy: Option[RetryPolicy] = None, - pagingState: Option[PagingState] = None, + pagingState: Option[ByteBuffer] = None, cqlStatements: Seq[String] = Seq.empty) diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributesBuilder.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributesBuilder.scala index b8283ad..fa0aa17 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributesBuilder.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributesBuilder.scala @@ -6,11 +6,12 @@ package com.datastax.gatling.plugin.model -import com.datastax.driver.core.policies.RetryPolicy -import com.datastax.driver.core.{ConsistencyLevel, PagingState} +import java.nio.ByteBuffer + import com.datastax.gatling.plugin.checks.{DseCqlCheck, GenericCheck} import com.datastax.gatling.plugin.request.CqlRequestActionBuilder -import io.gatling.core.action.builder.ActionBuilder +import com.datastax.oss.driver.api.core.ConsistencyLevel +import com.datastax.oss.driver.api.core.retry.RetryPolicy /** @@ -18,13 +19,13 @@ import io.gatling.core.action.builder.ActionBuilder * * @param attr Addition Attributes */ -case class DseCqlAttributesBuilder(attr: DseCqlAttributes) { +case class DseCqlAttributesBuilder[T](attr: DseCqlAttributes[T]) { /** * Builds to final action to run * * @return */ - def build(): CqlRequestActionBuilder = new CqlRequestActionBuilder(attr) + def build(): CqlRequestActionBuilder[T] = new CqlRequestActionBuilder(attr) /** * Set Consistency Level @@ -39,8 +40,8 @@ case class DseCqlAttributesBuilder(attr: DseCqlAttributes) { * * This permission MUST be granted to the currently logged in user using the CQL statement: `GRANT PROXY.EXECUTE ON * ROLE someRole TO alice`. The user MUST be logged in with - * [[com.datastax.driver.dse.auth.DsePlainTextAuthProvider]] or - * [[com.datastax.driver.dse.auth.DseGSSAPIAuthProvider]] + * [[com.datastax.dse.driver.internal.core.auth.DsePlainTextAuthProvider]] or + * [[com.datastax.dse.driver.internal.core.auth.DseGssApiAuthProvider]] * * @param userOrRole String * @return @@ -83,7 +84,7 @@ case class DseCqlAttributesBuilder(attr: DseCqlAttributes) { /** - * Define the [[com.datastax.driver.core.policies.RetryPolicy]] to be used for query + * Define the [[com.datastax.oss.driver.api.core.retry.RetryPolicy]] to be used for query * * @param retryPolicy DataStax drivers retry policy * @return @@ -113,7 +114,7 @@ case class DseCqlAttributesBuilder(attr: DseCqlAttributes) { * @param pagingState CQL Paging state * @return */ - def withPagingState(pagingState: PagingState) = DseCqlAttributesBuilder(attr.copy(pagingState = Some(pagingState))) + def withPagingState(pagingState: ByteBuffer) = DseCqlAttributesBuilder(attr.copy(pagingState = Some(pagingState))) /** diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatementBuilders.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatementBuilders.scala index 1812102..51c2fe4 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatementBuilders.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatementBuilders.scala @@ -6,9 +6,9 @@ package com.datastax.gatling.plugin.model -import com.datastax.driver.core.{PreparedStatement, SimpleStatement} import com.datastax.gatling.plugin._ import com.datastax.gatling.plugin.utils.CqlPreparedStatementUtil +import com.datastax.oss.driver.api.core.cql.{BatchableStatement, BoundStatement, PreparedStatement, SimpleStatement} import io.gatling.core.session.Expression /** @@ -20,7 +20,7 @@ import io.gatling.core.session.Expression * * @param tag Name of the CQL query to execute */ -case class DseCqlStatementBuilder(tag: String) { +case class DseCqlStatementBuilder[T](tag: String) { /** * Execute a simple Statement built from a CQL string. @@ -29,7 +29,7 @@ case class DseCqlStatementBuilder(tag: String) { * @return */ @deprecated("Replaced by executeStatement(String)") - def executeCql(query: String): DseCqlAttributesBuilder = + def executeCql(query: String): DseCqlAttributesBuilder[SimpleStatement] = executeStatement(query) /** @@ -38,8 +38,8 @@ case class DseCqlStatementBuilder(tag: String) { * @param query Simple string query * @return */ - def executeStatement(query: String): DseCqlAttributesBuilder = - executeStatement(new SimpleStatement(query)) + def executeStatement(query: String): DseCqlAttributesBuilder[SimpleStatement] = + executeStatement(SimpleStatement.newInstance(query)) /** * Execute a Simple Statement @@ -47,12 +47,12 @@ case class DseCqlStatementBuilder(tag: String) { * @param statement SimpleStatement * @return */ - def executeStatement(statement: SimpleStatement): DseCqlAttributesBuilder = + def executeStatement(statement: SimpleStatement): DseCqlAttributesBuilder[SimpleStatement] = DseCqlAttributesBuilder( DseCqlAttributes( tag, DseCqlSimpleStatement(statement), - cqlStatements = Seq(statement.getQueryString)) + cqlStatements = Seq(statement.getQuery)) ) /** @@ -90,7 +90,7 @@ case class DseCqlStatementBuilder(tag: String) { * * @param preparedStatement CQL Prepared statement with named parameters */ - def executeNamed(preparedStatement: PreparedStatement): DseCqlAttributesBuilder = + def executeNamed(preparedStatement: PreparedStatement): DseCqlAttributesBuilder[BoundStatement] = DsePreparedCqlStatementBuilder(tag, preparedStatement).withSessionParams() /** @@ -102,7 +102,7 @@ case class DseCqlStatementBuilder(tag: String) { DseCqlAttributes( tag, DseCqlBoundBatchStatement(CqlPreparedStatementUtil, preparedStatements), - cqlStatements = preparedStatements.map(_.getQueryString) + cqlStatements = preparedStatements.map(_.getQuery) ) ) @@ -113,14 +113,14 @@ case class DseCqlStatementBuilder(tag: String) { * @param payloadSessionKey Session key of the payload from session/feed * @return */ - def executeCustomPayload(statement: SimpleStatement, payloadSessionKey: String): DseCqlAttributesBuilder = + def executeCustomPayload(statement: SimpleStatement, payloadSessionKey: String): DseCqlAttributesBuilder[SimpleStatement] = DseCqlAttributesBuilder( DseCqlAttributes( tag, DseCqlCustomPayloadStatement(statement, payloadSessionKey), - cqlStatements = Seq(statement.getQueryString))) + cqlStatements = Seq(statement.getQuery))) - def executePreparedFromSession(key: String): DseCqlAttributesBuilder = + def executePreparedFromSession(key: String): DseCqlAttributesBuilder[SimpleStatement] = DseCqlAttributesBuilder( DseCqlAttributes( tag, @@ -140,12 +140,12 @@ case class DsePreparedCqlStatementBuilder(tag: String, prepared: PreparedStateme * * @return */ - def withSessionParams(): DseCqlAttributesBuilder = + def withSessionParams(): DseCqlAttributesBuilder[BoundStatement] = DseCqlAttributesBuilder( DseCqlAttributes( tag, DseCqlBoundStatementNamed(CqlPreparedStatementUtil, prepared), - cqlStatements = Seq(prepared.getQueryString))) + cqlStatements = Seq(prepared.getQuery))) /** * Bind Gatling Session Values to CQL Prepared Statement @@ -153,12 +153,12 @@ case class DsePreparedCqlStatementBuilder(tag: String, prepared: PreparedStateme * @param params Gatling Session variables * @return */ - def withParams(params: Expression[AnyRef]*): DseCqlAttributesBuilder = + def withParams(params: Expression[AnyRef]*): DseCqlAttributesBuilder[BoundStatement] = DseCqlAttributesBuilder( DseCqlAttributes( tag, DseCqlBoundStatementWithPassedParams(CqlPreparedStatementUtil, prepared, params: _*), - cqlStatements = Seq(prepared.getQueryString)) + cqlStatements = Seq(prepared.getQuery)) ) /** @@ -172,6 +172,6 @@ case class DsePreparedCqlStatementBuilder(tag: String, prepared: PreparedStateme DseCqlAttributes( tag, DseCqlBoundStatementWithParamList(CqlPreparedStatementUtil, prepared, sessionKeys), - cqlStatements = Seq(prepared.getQueryString)) + cqlStatements = Seq(prepared.getQuery)) ) } diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatements.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatements.scala index 1561482..7a76409 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatements.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatements.scala @@ -8,19 +8,18 @@ package com.datastax.gatling.plugin.model import java.nio.ByteBuffer -import com.datastax.driver.core._ import com.datastax.gatling.plugin.exceptions.DseCqlStatementException import com.datastax.gatling.plugin.utils.CqlPreparedStatementUtil +import com.datastax.oss.driver.api.core.cql.{BatchStatement, BatchableStatement, BoundStatement, DefaultBatchType, PreparedStatement, SimpleStatement, Statement} import io.gatling.commons.validation._ import io.gatling.core.session.{Session, _} import scala.collection.JavaConverters._ -import scala.collection.mutable.ArrayBuffer import scala.util.{Try, Failure => TryFailure, Success => TrySuccess} -trait DseCqlStatement extends DseStatement[Statement] { - def buildFromSession(session: Session): Validation[Statement] +trait DseCqlStatement[T] extends DseStatement[T] { + def buildFromSession(session: Session): Validation[T] } /** @@ -28,10 +27,9 @@ trait DseCqlStatement extends DseStatement[Statement] { * * @param statement the statement to execute */ -case class DseCqlSimpleStatement(statement: SimpleStatement) extends DseCqlStatement { - def buildFromSession(gatlingSession: Session): Validation[SimpleStatement] = { +case class DseCqlSimpleStatement(statement: SimpleStatement) extends DseCqlStatement[SimpleStatement] { + def buildFromSession(gatlingSession: Session): Validation[SimpleStatement] = statement.success - } } /** @@ -40,13 +38,13 @@ case class DseCqlSimpleStatement(statement: SimpleStatement) extends DseCqlState * @param preparedStatement the prepared statement on which to bind parameters */ case class DseCqlBoundStatementNamed(cqlTypes: CqlPreparedStatementUtil, preparedStatement: PreparedStatement) - extends DseCqlStatement { + extends DseCqlStatement[BoundStatement] { def buildFromSession(gatlingSession: Session): Validation[BoundStatement] = bindParams( gatlingSession, preparedStatement.bind(), - cqlTypes.getParamsMap(preparedStatement)).success + cqlTypes.getParamsMap(preparedStatement)).asInstanceOf[BoundStatement].success /** * Bind Gatling Session Params to CQL Statement by Name and Type @@ -57,12 +55,12 @@ case class DseCqlBoundStatementNamed(cqlTypes: CqlPreparedStatementUtil, prepare * @return */ protected def bindParams(gatlingSession: Session, boundStatement: BoundStatement, - queryParams: Map[String, DataType.Name]): BoundStatement = { + queryParams: Map[String, Int]): PreparedStatement = { queryParams.foreach { case (gatlingSessionKey, valType) => cqlTypes.bindParamByName(gatlingSession, boundStatement, valType, gatlingSessionKey) } - boundStatement + boundStatement.getPreparedStatement } } @@ -74,7 +72,7 @@ case class DseCqlBoundStatementNamed(cqlTypes: CqlPreparedStatementUtil, prepare */ case class DseCqlBoundStatementWithPassedParams(cqlTypes: CqlPreparedStatementUtil, preparedStatement: PreparedStatement, - params: Expression[AnyRef]*) extends DseCqlStatement { + params: Expression[AnyRef]*) extends DseCqlStatement[BoundStatement] { def buildFromSession(gatlingSession: Session): Validation[BoundStatement] = { val parsedParams: Seq[Validation[AnyRef]] = params.map(param => param(gatlingSession)) @@ -98,7 +96,7 @@ case class DseCqlBoundStatementWithPassedParams(cqlTypes: CqlPreparedStatementUt */ case class DseCqlBoundStatementWithParamList(cqlTypes: CqlPreparedStatementUtil, preparedStatement: PreparedStatement, - sessionKeys: Seq[String]) extends DseCqlStatement { + sessionKeys: Seq[String]) extends DseCqlStatement[BoundStatement] { /** * Apply the Gatling session params to the Prepared statement @@ -141,16 +139,16 @@ case class DseCqlBoundStatementWithParamList(cqlTypes: CqlPreparedStatementUtil, * @param statements CQL Prepared Statements */ case class DseCqlBoundBatchStatement(cqlTypes: CqlPreparedStatementUtil, statements: Seq[PreparedStatement]) - extends DseCqlStatement { + extends DseCqlStatement[BatchStatement] { def buildFromSession(gatlingSession: Session): Validation[BatchStatement] = { - val batch = new BatchStatement() + val batchBuilder = BatchStatement.builder(DefaultBatchType.LOGGED) statements.foreach(s => - batch.add(bindParams(gatlingSession, s, cqlTypes.getParamsMap(s)))) + batchBuilder.addStatement(bindParams(gatlingSession, s, cqlTypes.getParamsMap(s)))) - batch.success + batchBuilder.build().success } @@ -163,7 +161,7 @@ case class DseCqlBoundBatchStatement(cqlTypes: CqlPreparedStatementUtil, stateme * @return */ protected def bindParams(gatlingSession: Session, statement: PreparedStatement, - queryParams: Map[String, DataType.Name]): BoundStatement = { + queryParams: Map[String, Int]): BoundStatement = { val boundStatement = statement.bind() @@ -184,9 +182,10 @@ case class DseCqlBoundBatchStatement(cqlTypes: CqlPreparedStatementUtil, stateme * @param statement SimpleStaten * @param payloadRef session variable for custom payload */ -case class DseCqlCustomPayloadStatement(statement: SimpleStatement, payloadRef: String) extends DseCqlStatement { +case class DseCqlCustomPayloadStatement(statement: SimpleStatement, payloadRef: String) + extends DseCqlStatement[SimpleStatement] { - def buildFromSession(gatlingSession: Session): Validation[Statement] = { + def buildFromSession(gatlingSession: Session): Validation[SimpleStatement] = { if (!gatlingSession.contains(payloadRef)) { throw new DseCqlStatementException(s"Passed sessionKey: {$payloadRef} does not exist in Session.") @@ -194,7 +193,7 @@ case class DseCqlCustomPayloadStatement(statement: SimpleStatement, payloadRef: Try { val payload = gatlingSession(payloadRef).as[Map[String, ByteBuffer]].asJava - statement.setOutgoingPayload(payload) + statement.setCustomPayload(payload) } match { case TrySuccess(stmt) => stmt.success case TryFailure(error) => error.getMessage.failure @@ -209,7 +208,8 @@ case class DseCqlCustomPayloadStatement(statement: SimpleStatement, payloadRef: * * @param sessionKey the session key which is associated to a PreparedStatement */ -case class DseCqlBoundStatementNamedFromSession(cqlTypes: CqlPreparedStatementUtil, sessionKey: String) extends DseCqlStatement { +case class DseCqlBoundStatementNamedFromSession(cqlTypes: CqlPreparedStatementUtil, sessionKey: String) + extends DseCqlStatement[BoundStatement] { def buildFromSession(gatlingSession: Session): Validation[BoundStatement] = { if (!gatlingSession.contains(sessionKey)) { diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributes.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributes.scala index ad1e45f..9aa02b8 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributes.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributes.scala @@ -6,14 +6,15 @@ package com.datastax.gatling.plugin.model -import com.datastax.driver.core.{ConsistencyLevel, Row} -import com.datastax.driver.dse.graph.{GraphNode, GraphStatement} +import com.datastax.dse.driver.api.core.graph.{GraphNode, GraphStatement, ScriptGraphStatement} import com.datastax.gatling.plugin.checks.{DseGraphCheck, GenericCheck} +import com.datastax.oss.driver.api.core.ConsistencyLevel +import com.datastax.oss.driver.api.core.cql.Row /** * Graph Query Attributes to be applied to the current query * - * See [[GraphStatement]] for documentation on each option. + * See [[com.datastax.dse.driver.api.core.graph.GraphStatement]] for documentation on each option. * * @param tag Name of Query to include in reports * @param statement Graph Statement to be sent to Cluster @@ -34,7 +35,7 @@ import com.datastax.gatling.plugin.checks.{DseGraphCheck, GenericCheck} * @param graphTransformResults Function to use in order to transform a row into a Graph node */ case class DseGraphAttributes(tag: String, - statement: DseStatement[GraphStatement], + statement: DseStatement[GraphStatement[ScriptGraphStatement]], cl: Option[ConsistencyLevel] = None, graphChecks: List[DseGraphCheck] = List.empty, genericChecks: List[GenericCheck] = List.empty, diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributesBuilder.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributesBuilder.scala index 427b7e9..6705a66 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributesBuilder.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributesBuilder.scala @@ -6,10 +6,11 @@ package com.datastax.gatling.plugin.model -import com.datastax.driver.core.{ConsistencyLevel, Row} -import com.datastax.driver.dse.graph.GraphNode +import com.datastax.dse.driver.api.core.graph.GraphNode import com.datastax.gatling.plugin.checks.{DseGraphCheck, GenericCheck} import com.datastax.gatling.plugin.request.GraphRequestActionBuilder +import com.datastax.oss.driver.api.core.ConsistencyLevel +import com.datastax.oss.driver.api.core.cql.Row import io.gatling.core.action.builder.ActionBuilder @@ -39,8 +40,8 @@ case class DseGraphAttributesBuilder(attr: DseGraphAttributes) { * * This permission MUST be granted to the currently logged in user using the CQL statement: `GRANT PROXY.EXECUTE ON * ROLE someRole TO alice`. The user MUST be logged in with - * [[com.datastax.driver.dse.auth.DsePlainTextAuthProvider]] or - * [[com.datastax.driver.dse.auth.DseGSSAPIAuthProvider]] + * [[com.datastax.dse.driver.internal.core.auth.DsePlainTextAuthProvider]] or + * [[com.datastax.dse.driver.internal.core.auth.DseGssApiAuthProvider]] * * @param userOrRole String * @return diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatementBuilders.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatementBuilders.scala index f559562..73f1844 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatementBuilders.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatementBuilders.scala @@ -6,7 +6,8 @@ package com.datastax.gatling.plugin.model -import com.datastax.driver.dse.graph.{GraphStatement, SimpleGraphStatement} +import com.datastax.dse.driver.api.core.graph.ScriptGraphStatement +import com.datastax.dse.graph.api._ import io.gatling.core.session.{Expression, Session} /** @@ -34,7 +35,7 @@ case class DseGraphStatementBuilder(tag: String) { * @return */ @deprecated("Replaced by executeGraph(SimpleGraphStatement)") - def executeGraphStatement(gStatement: SimpleGraphStatement) = + def executeGraphStatement(gStatement: ScriptGraphStatement) = executeGraph(gStatement) /** diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatements.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatements.scala index af2be96..cd167a8 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatements.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatements.scala @@ -6,7 +6,7 @@ package com.datastax.gatling.plugin.model -import com.datastax.driver.dse.graph.{GraphStatement, SimpleGraphStatement} +import com.datastax.dse.driver.api.core.graph.{FluentGraphStatement, GraphStatement, ScriptGraphStatement} import com.datastax.dse.graph.api.DseGraph import com.datastax.gatling.plugin.exceptions.DseGraphStatementException import io.gatling.commons.validation._ @@ -16,8 +16,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal import scala.util.{Try, Failure => TryFailure, Success => TrySuccess} -trait DseGraphStatement extends DseStatement[GraphStatement] { - def buildFromSession(session: Session): Validation[GraphStatement] +trait DseGraphStatement[T] extends DseStatement[T] { + def buildFromSession(session: Session): Validation[T] } /** @@ -25,9 +25,9 @@ trait DseGraphStatement extends DseStatement[GraphStatement] { * * @param statement the Gremlin String to execute */ -case class GraphStringStatement(statement: Expression[String]) extends DseGraphStatement { - def buildFromSession(gatlingSession: Session): Validation[GraphStatement] = { - statement(gatlingSession).flatMap(stmt => new SimpleGraphStatement(stmt).success) +case class GraphStringStatement(statement: Expression[String]) extends DseGraphStatement[ScriptGraphStatement] { + def buildFromSession(gatlingSession: Session): Validation[ScriptGraphStatement] = { + statement(gatlingSession).flatMap(stmt => ScriptGraphStatement.builder(stmt).build().success) } } @@ -36,8 +36,8 @@ case class GraphStringStatement(statement: Expression[String]) extends DseGraphS * * @param statement the Fluent Statement */ -case class GraphFluentStatement(statement: GraphStatement) extends DseGraphStatement { - def buildFromSession(gatlingSession: Session): Validation[GraphStatement] = { +case class GraphFluentStatement(statement: FluentGraphStatement) extends DseGraphStatement[FluentGraphStatement] { + def buildFromSession(gatlingSession: Session): Validation[FluentGraphStatement] = { statement.success } } @@ -49,8 +49,8 @@ case class GraphFluentStatement(statement: GraphStatement) extends DseGraphState * @param lambda Scala lambda that takes a Gatling User Session (from which it can retrieve parameters) * and returns a fluent Graph Statement */ -case class GraphFluentStatementFromScalaLambda(lambda: Session => GraphStatement) extends DseGraphStatement { - def buildFromSession(gatlingSession: Session): Validation[GraphStatement] = { +case class GraphFluentStatementFromScalaLambda(lambda: Session => FluentGraphStatement) extends DseGraphStatement[FluentGraphStatement] { + def buildFromSession(gatlingSession: Session): Validation[FluentGraphStatement] = { lambda(gatlingSession).success } } @@ -61,16 +61,16 @@ case class GraphFluentStatementFromScalaLambda(lambda: Session => GraphStatement * * @param sessionKey Place a GraphTraversal in your session with this key name */ -case class GraphFluentSessionKey(sessionKey: String) extends DseGraphStatement { +case class GraphFluentSessionKey(sessionKey: String) extends DseGraphStatement[FluentGraphStatement] { - def buildFromSession(gatlingSession: Session): Validation[GraphStatement] = { + def buildFromSession(gatlingSession: Session): Validation[FluentGraphStatement] = { if (!gatlingSession.contains(sessionKey)) { throw new DseGraphStatementException(s"Passed sessionKey: {$sessionKey} does not exist in Session.") } Try { - DseGraph.statementFromTraversal(gatlingSession(sessionKey).as[GraphTraversal[_, _]]) + FluentGraphStatement.newInstance(gatlingSession(sessionKey).as[GraphTraversal[_, _]]) } match { case TrySuccess(stmt) => stmt.success case TryFailure(error) => error.getMessage.failure @@ -85,7 +85,7 @@ case class GraphFluentSessionKey(sessionKey: String) extends DseGraphStatement { * @param statement SimpleGraphStatement * @param sessionKeys Gatling session param keys mapped to their bind name, to allow name override */ -case class GraphBoundStatement(statement: SimpleGraphStatement, sessionKeys: Map[String, String]) extends DseGraphStatement { +case class GraphBoundStatement(statement: ScriptGraphStatement, sessionKeys: Map[String, String]) extends DseGraphStatement[ScriptGraphStatement] { /** * Apply the Gatling session params passed to the GraphStatement @@ -93,7 +93,7 @@ case class GraphBoundStatement(statement: SimpleGraphStatement, sessionKeys: Map * @param gatlingSession Gatling Session * @return */ - def buildFromSession(gatlingSession: Session): Validation[GraphStatement] = { + def buildFromSession(gatlingSession: Session): Validation[ScriptGraphStatement] = { Try { sessionKeys.foreach((tuple: (String, String)) => setParam(gatlingSession, tuple._1, tuple._2)).success statement @@ -114,7 +114,7 @@ case class GraphBoundStatement(statement: SimpleGraphStatement, sessionKeys: Map * @param overriddenParamName Parameter name used to bind the statement * @return gStatement */ - private def setParam(gatlingSession: Session, paramName: String, overriddenParamName: String): GraphStatement = { - statement.set(overriddenParamName, gatlingSession(paramName).as[Object]) + private def setParam(gatlingSession: Session, paramName: String, overriddenParamName: String): ScriptGraphStatement = { + statement.setQueryParam(overriddenParamName, gatlingSession(paramName).as[Object]) } } \ No newline at end of file diff --git a/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestAction.scala b/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestAction.scala index bbf630a..af85bc8 100644 --- a/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestAction.scala +++ b/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestAction.scala @@ -7,16 +7,19 @@ package com.datastax.gatling.plugin.request import java.lang.Boolean +import java.time.Duration import java.util.UUID import java.util.concurrent.ExecutorService import java.util.concurrent.TimeUnit.MICROSECONDS import akka.actor.ActorSystem +import com.datastax.dse.driver.api.core.DseSession import com.datastax.gatling.plugin.DseProtocol import com.datastax.gatling.plugin.metrics.MetricsLogger import com.datastax.gatling.plugin.model.DseCqlAttributes import com.datastax.gatling.plugin.response.CqlResponseHandler import com.datastax.gatling.plugin.utils._ +import com.datastax.oss.driver.api.core.cql.SimpleStatement import io.gatling.commons.stats.KO import io.gatling.commons.validation.safely import io.gatling.core.action.{Action, ExitableAction} @@ -49,7 +52,7 @@ class CqlRequestAction(val name: String, val system: ActorSystem, val statsEngine: StatsEngine, val protocol: DseProtocol, - val dseAttributes: DseCqlAttributes, + val dseAttributes: DseCqlAttributes[SimpleStatement], val metricsLogger: MetricsLogger, val dseExecutorService: ExecutorService, val gatlingTimingSource: GatlingTimingSource) @@ -79,25 +82,27 @@ class CqlRequestAction(val name: String, stmt.onSuccess({ stmt => // global options dseAttributes.cl.map(stmt.setConsistencyLevel) - dseAttributes.userOrRole.map(stmt.executingAs) - dseAttributes.readTimeout.map(stmt.setReadTimeoutMillis) - dseAttributes.idempotent.map(stmt.setIdempotent) - dseAttributes.defaultTimestamp.map(stmt.setDefaultTimestamp) + // TODO refactored + //dseAttributes.userOrRole.map(stmt.executingAs) + dseAttributes.readTimeout.map( timeout => stmt.setTimeout(Duration.ofMillis(timeout))) + dseAttributes.idempotent.map( idempotent => stmt.setIdempotent(idempotent)) + dseAttributes.defaultTimestamp.map(stmt.setQueryTimestamp) // CQL Only Options - dseAttributes.outGoingPayload.map(x => stmt.setOutgoingPayload(x.asJava)) + dseAttributes.outGoingPayload.map(x => stmt.setCustomPayload(x.asJava)) dseAttributes.serialCl.map(stmt.setSerialConsistencyLevel) - dseAttributes.retryPolicy.map(stmt.setRetryPolicy) - dseAttributes.fetchSize.map(stmt.setFetchSize) + //TODO find equivalent methods + //dseAttributes.retryPolicy.map(stmt.setRetryPolicy) + //dseAttributes.fetchSize.map(stmt.setFetchSize) dseAttributes.pagingState.map(stmt.setPagingState) if (dseAttributes.enableTrace.isDefined && dseAttributes.enableTrace.get) { - stmt.enableTracing + stmt.isTracing } val responseHandler = new CqlResponseHandler(next, session, system, statsEngine, responseTimeBuilder, stmt, dseAttributes, metricsLogger) implicit val sameThreadExecutionContext: ExecutionContextExecutor = ExecutionContext.fromExecutorService(dseExecutorService) FutureUtils - .toScalaFuture(protocol.session.executeAsync(stmt)) + .toScalaFuture(session.executeAsync(stmt)) .onComplete(t => DseRequestActor.recordResult(RecordResult(t, responseHandler))) }) } diff --git a/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestActionBuilder.scala b/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestActionBuilder.scala index 455d1bd..eb8b6b9 100644 --- a/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestActionBuilder.scala +++ b/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestActionBuilder.scala @@ -13,7 +13,7 @@ import io.gatling.core.action.builder.ActionBuilder import io.gatling.core.structure.ScenarioContext import io.gatling.core.util.NameGen -class CqlRequestActionBuilder(val dseAttributes: DseCqlAttributes) extends ActionBuilder with +class CqlRequestActionBuilder[T](val dseAttributes: DseCqlAttributes[T]) extends ActionBuilder with NameGen { def build(ctx: ScenarioContext, next: Action): Action = { diff --git a/src/main/scala/com/datastax/gatling/plugin/request/DseRequestActor.scala b/src/main/scala/com/datastax/gatling/plugin/request/DseRequestActor.scala index c55c996..be9cc74 100644 --- a/src/main/scala/com/datastax/gatling/plugin/request/DseRequestActor.scala +++ b/src/main/scala/com/datastax/gatling/plugin/request/DseRequestActor.scala @@ -8,17 +8,15 @@ package com.datastax.gatling.plugin.request import akka.actor.Actor -import com.datastax.driver.core.ResultSet -import com.datastax.driver.dse.graph.GraphResultSet +import com.datastax.dse.driver.api.core.DseSession import com.google.common.util.concurrent.FutureCallback import com.typesafe.scalalogging.StrictLogging -import io.gatling.core.session.Session import scala.concurrent.ExecutionException import scala.util.{Failure, Success, Try} -case class SendCqlQuery(dseRequestAction: CqlRequestAction, session: Session) -case class SendGraphQuery(dseRequestAction: GraphRequestAction, session: Session) +case class SendCqlQuery(dseRequestAction: CqlRequestAction, session: DseSession) +case class SendGraphQuery(dseRequestAction: GraphRequestAction, session: DseSession) case class RecordResult[T](t: Try[T], callback: FutureCallback[T]) @@ -41,4 +39,4 @@ object DseRequestActor extends StrictLogging { callback.onFailure(exception) } } -} \ No newline at end of file +} diff --git a/src/main/scala/com/datastax/gatling/plugin/request/GraphRequestAction.scala b/src/main/scala/com/datastax/gatling/plugin/request/GraphRequestAction.scala index e4abe66..691c7b6 100644 --- a/src/main/scala/com/datastax/gatling/plugin/request/GraphRequestAction.scala +++ b/src/main/scala/com/datastax/gatling/plugin/request/GraphRequestAction.scala @@ -7,11 +7,13 @@ package com.datastax.gatling.plugin.request import java.lang.Boolean +import java.time.Duration import java.util.UUID import java.util.concurrent.ExecutorService import java.util.concurrent.TimeUnit.MICROSECONDS import akka.actor.ActorSystem +import com.datastax.dse.driver.api.core.DseSession import com.datastax.gatling.plugin.DseProtocol import com.datastax.gatling.plugin.metrics.MetricsLogger import com.datastax.gatling.plugin.model.DseGraphAttributes @@ -19,7 +21,6 @@ import com.datastax.gatling.plugin.response.GraphResponseHandler import com.datastax.gatling.plugin.utils._ import io.gatling.commons.stats.KO import io.gatling.core.action.{Action, ExitableAction} -import io.gatling.core.session.Session import io.gatling.core.stats.StatsEngine import scala.concurrent.{ExecutionContext, ExecutionContextExecutor} @@ -53,14 +54,14 @@ class GraphRequestAction(val name: String, val gatlingTimingSource: GatlingTimingSource) extends ExitableAction { - def execute(session: Session): Unit = { + def execute(session: DseSession): Unit = { dseExecutorService.submit(new Runnable { override def run(): Unit = sendQuery(session) }) } - def sendQuery(session: Session): Unit = { + def sendQuery(session: DseSession): Unit = { val enableCO = Boolean.getBoolean("gatling.dse.plugin.measure_service_time") val responseTimeBuilder: ResponseTimeBuilder = if (enableCO) { // The throughput checker is useless in CO affected scenarios since throughput is not known in advance @@ -86,10 +87,11 @@ class GraphRequestAction(val name: String, stmt.onSuccess({ gStmt => // global options dseAttributes.cl.map(gStmt.setConsistencyLevel) - dseAttributes.defaultTimestamp.map(gStmt.setDefaultTimestamp) - dseAttributes.userOrRole.map(gStmt.executingAs) - dseAttributes.readTimeout.map(gStmt.setReadTimeoutMillis) - dseAttributes.idempotent.map(gStmt.setIdempotent) + dseAttributes.defaultTimestamp.map(gStmt.setTimestamp) + //TODO find equivalent + //dseAttributes.userOrRole.map(gStmt.executingAs) + dseAttributes.readTimeout.map(timeout => gStmt.setTimeout(Duration.ofMillis(timeout))) + dseAttributes.idempotent.map(idempotent => gStmt.setIdempotent(idempotent)) // Graph only Options dseAttributes.readCL.map(gStmt.setGraphReadConsistencyLevel) diff --git a/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala b/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala index db03c27..e9d0e36 100644 --- a/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala +++ b/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala @@ -6,24 +6,26 @@ package com.datastax.gatling.plugin.response -import com.datastax.driver.core._ -import com.datastax.driver.dse.graph._ +import com.datastax.oss.driver.api.core.cql._ +import com.datastax.oss.driver.api.core.metadata._ +import com.datastax.dse.driver.api.core.graph._ import com.datastax.gatling.plugin.model.{DseCqlAttributes, DseGraphAttributes} import com.typesafe.scalalogging.LazyLogging -import scala.collection.JavaConverters._ import scala.util.Try +import java.nio.ByteBuffer +import org.apache.tinkerpop.gremlin.structure._ +import org.apache.tinkerpop.gremlin.process.traversal.Path +import java.util.stream.Collectors -abstract class DseResponse { - def executionInfo(): ExecutionInfo +abstract class DseResponse[E] { + def executionInfo(): E def rowCount(): Int def applied(): Boolean - def exhausted(): Boolean - def queriedHost(): Host = executionInfo().getQueriedHost - def achievedConsistencyLevel(): ConsistencyLevel = executionInfo().getAchievedConsistencyLevel - def speculativeExecutions(): Int = executionInfo().getSpeculativeExecutions - def pagingState(): PagingState = executionInfo().getPagingState - def triedHosts(): List[Host] = executionInfo().getTriedHosts.asScala.toList + def queriedHost(): Node = executionInfo().getCoordinator() + def speculativeExecutions(): Int = executionInfo().getSpeculativeExecutionCount + def pagingState(): ByteBuffer = executionInfo().getPagingState + def triedHosts(): List[Node] = executionInfo().getErrors.stream.map(_.getKey).collect(Collectors.toList[Node]).asScala.toList def warnings(): List[String] = executionInfo().getWarnings.asScala.toList def successFullExecutionIndex(): Int = executionInfo().getSuccessfulExecutionIndex def schemaInAgreement(): Boolean = executionInfo().isSchemaInAgreement @@ -33,9 +35,10 @@ abstract class DseResponse { class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttributes) extends DseResponse with LazyLogging { private lazy val allGraphNodes: Seq[GraphNode] = collection.JavaConverters.asScalaBuffer(graphResultSet.all()) - override def executionInfo(): ExecutionInfo = graphResultSet.getExecutionInfo() + def graphExecutionInfo(): GraphExecutionInfo = graphResultSet.getExecutionInfo() + override def executionInfo(): ExecutionInfo = null override def applied(): Boolean = false // graph doesn't support LWTs so always return false - override def exhausted(): Boolean = graphResultSet.isExhausted() + //override def exhausted(): Boolean = isFullyFetched() /** * Get the number of all rows returned by the query. @@ -57,7 +60,7 @@ class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttri def getGraphResultColumnValues(column: String): Seq[Any] = { if (allGraphNodes.isEmpty) return Seq.empty - allGraphNodes.map(node => if (node.get(column) != null) node.get(column)) + allGraphNodes.map(node => if (node.getByKey(column) != null) node.getByKey(column)) } @@ -65,8 +68,8 @@ class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttri val columnValues = collection.mutable.Buffer[Edge]() graphResultSet.forEach { n => Try( - if (n.get(name).isEdge) { - columnValues.append(n.get(name).asEdge()) + if (n.getByKey(name).isEdge) { + columnValues.append(n.getByKey(name).asEdge()) } ) } @@ -76,40 +79,39 @@ class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttri def getVertexes(name: String): Seq[Vertex] = { val columnValues = collection.mutable.Buffer[Vertex]() - graphResultSet.forEach { n => Try(if (n.get(name).isVertex) columnValues.append(n.get(name).asVertex())) } + graphResultSet.forEach { n => Try(if (n.getByKey(name).isVertex) columnValues.append(n.getByKey(name).asVertex())) } columnValues } def getPaths(name: String): Seq[Path] = { val columnValues = collection.mutable.Buffer[Path]() - graphResultSet.forEach { n => Try(columnValues.append(n.get(name).asPath())) } + graphResultSet.forEach { n => Try(columnValues.append(n.getByKey(name).asPath())) } columnValues } - def getProperties(name: String): Seq[Property] = { - val columnValues = collection.mutable.Buffer[Property]() - graphResultSet.forEach { n => Try(columnValues.append(n.get(name).asProperty())) } + def getProperties(name: String): Seq[Property[String]] = { + val columnValues = collection.mutable.Buffer[Property[String]]() + graphResultSet.forEach { n => Try(columnValues.append(n.getByKey(name).asProperty())) } columnValues } - def getVertexProperties(name: String): Seq[VertexProperty] = { - val columnValues = collection.mutable.Buffer[VertexProperty]() - graphResultSet.forEach { n => Try(columnValues.append(n.get(name).asVertexProperty())) } + def getVertexProperties(name: String): Seq[VertexProperty[String]] = { + val columnValues = collection.mutable.Buffer[VertexProperty[String]]() + graphResultSet.forEach { n => Try(columnValues.append(n.getByKey(name).asVertexProperty())) } columnValues } def getDseAttributes: DseGraphAttributes = dseAttributes } -class CqlResponse(cqlResultSet: ResultSet, dseAttributes: DseCqlAttributes) extends DseResponse with LazyLogging { +class CqlResponse[T](cqlResultSet: ResultSet, dseAttributes: DseCqlAttributes[T]) extends DseResponse with LazyLogging { private lazy val allCqlRows: Seq[Row] = collection.JavaConverters.asScalaBuffer(cqlResultSet.all()) override def executionInfo(): ExecutionInfo = cqlResultSet.getExecutionInfo() override def applied(): Boolean = cqlResultSet.wasApplied() - override def exhausted(): Boolean = cqlResultSet.isExhausted() /** * Get the number of all rows returned by the query. diff --git a/src/main/scala/com/datastax/gatling/plugin/response/DseResponseHandler.scala b/src/main/scala/com/datastax/gatling/plugin/response/DseResponseHandler.scala index ebd589e..f67eb48 100644 --- a/src/main/scala/com/datastax/gatling/plugin/response/DseResponseHandler.scala +++ b/src/main/scala/com/datastax/gatling/plugin/response/DseResponseHandler.scala @@ -10,11 +10,11 @@ import java.util.UUID import java.util.concurrent.TimeUnit.MICROSECONDS import akka.actor.ActorSystem -import com.datastax.driver.core._ -import com.datastax.driver.dse.graph.{GraphProtocol, GraphResultSet, GraphStatement} +import com.datastax.dse.driver.api.core.graph.{GraphResultSet, GraphStatement, ScriptGraphStatement} import com.datastax.gatling.plugin.metrics.MetricsLogger import com.datastax.gatling.plugin.model.{DseCqlAttributes, DseGraphAttributes} import com.datastax.gatling.plugin.utils.{ResponseTime, ResponseTimeBuilder} +import com.datastax.oss.driver.api.core.cql.{BatchableStatement, ResultSet, Statement} import com.google.common.util.concurrent.FutureCallback import com.typesafe.scalalogging.StrictLogging import io.gatling.commons.stats._ @@ -141,7 +141,7 @@ class GraphResponseHandler(val next: Action, val system: ActorSystem, val statsEngine: StatsEngine, val responseTimeBuilder: ResponseTimeBuilder, - val stmt: GraphStatement, + val stmt: GraphStatement[ScriptGraphStatement], val dseAttributes: DseGraphAttributes, val metricsLogger: MetricsLogger) extends DseResponseHandler[GraphResultSet, GraphResponse] { @@ -150,7 +150,7 @@ class GraphResponseHandler(val next: Action, override protected def specificChecks: List[Check[GraphResponse]] = dseAttributes.graphChecks override protected def genericChecks: List[Check[DseResponse]] = dseAttributes.genericChecks override protected def newResponse(rs: GraphResultSet): GraphResponse = new GraphResponse(rs, dseAttributes) - override protected def queriedHost(rs: GraphResultSet): String = rs.getExecutionInfo.getQueriedHost.toString + override protected def queriedHost(rs: GraphResultSet): String = rs.getExecutionInfo.getCoordinator.toString } class CqlResponseHandler(val next: Action, @@ -158,8 +158,8 @@ class CqlResponseHandler(val next: Action, val system: ActorSystem, val statsEngine: StatsEngine, val responseTimeBuilder: ResponseTimeBuilder, - val stmt: Statement, - val dseAttributes: DseCqlAttributes, + val stmt: Statement[BatchableStatement], + val dseAttributes: DseCqlAttributes[BatchableStatement], val metricsLogger: MetricsLogger) extends DseResponseHandler[ResultSet, CqlResponse] { override protected def tag: String = dseAttributes.tag @@ -167,5 +167,5 @@ class CqlResponseHandler(val next: Action, override protected def specificChecks: List[Check[CqlResponse]] = dseAttributes.cqlChecks override protected def genericChecks: List[Check[DseResponse]] = dseAttributes.genericChecks override protected def newResponse(rs: ResultSet): CqlResponse = new CqlResponse(rs, dseAttributes) - override protected def queriedHost(rs: ResultSet): String = rs.getExecutionInfo.getQueriedHost.toString + override protected def queriedHost(rs: ResultSet): String = rs.getExecutionInfo.getCoordinator.toString } diff --git a/src/main/scala/com/datastax/gatling/plugin/utils/CqlPreparedStatementUtil.scala b/src/main/scala/com/datastax/gatling/plugin/utils/CqlPreparedStatementUtil.scala index 9596de1..a6dd881 100644 --- a/src/main/scala/com/datastax/gatling/plugin/utils/CqlPreparedStatementUtil.scala +++ b/src/main/scala/com/datastax/gatling/plugin/utils/CqlPreparedStatementUtil.scala @@ -10,14 +10,16 @@ import java.math.BigInteger import java.net.InetAddress import java.nio.ByteBuffer import java.util -import java.util.Date import java.util.concurrent.TimeUnit +import java.time.LocalDate +import java.time.LocalTime +import java.time.Instant -import com.datastax.driver.core.DataType.Name._ -import com.datastax.driver.core._ -import com.datastax.driver.dse.geometry._ -import com.datastax.driver.dse.geometry.codecs.PointCodec +import com.datastax.oss.protocol.internal.ProtocolConstants.DataType._ +import com.datastax.oss.driver.api.core.cql._ +import com.datastax.dse.driver.api.core.data.geometry._ import com.datastax.gatling.plugin.exceptions.CqlTypeException +import com.datastax.oss.driver.api.core.data.{TupleValue, UdtValue} import com.github.nscala_time.time.Imports.DateTime import io.gatling.core.session.Session @@ -31,15 +33,15 @@ trait CqlPreparedStatementUtil { protected val hourMinSecNanoRegEx: Regex = """(\d+):(\d+):(\d+).(\d+{1,9})""".r def bindParamByOrder(gatlingSession: Session, - boundStatement: BoundStatement, paramType: DataType.Name, + boundStatement: BoundStatement, paramType: Int, paramName: String, key: Int): BoundStatement - def bindParamByName(gatlingSession: Session, boundStatement: BoundStatement, paramType: DataType.Name, + def bindParamByName(gatlingSession: Session, boundStatement: BoundStatement, paramType: Int, paramName: String): BoundStatement - def getParamsMap(preparedStatement: PreparedStatement): Map[String, DataType.Name] + def getParamsMap(preparedStatement: PreparedStatement): Map[String, Int] - def getParamsList(preparedStatement: PreparedStatement): List[DataType.Name] + def getParamsList(preparedStatement: PreparedStatement): List[Int] } /** @@ -57,7 +59,7 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { * @param paramName Gatling Session Attribute Name * @param key Key/Order of param */ - def bindParamByOrder(gatlingSession: Session, boundStatement: BoundStatement, paramType: DataType.Name, + def bindParamByOrder(gatlingSession: Session, boundStatement: BoundStatement, paramType: Int, paramName: String, key: Int): BoundStatement = { if (!gatlingSession.attributes.contains(paramName)) { @@ -78,50 +80,50 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { boundStatement case _ => paramType match { - case (VARCHAR | TEXT | ASCII) => + case (VARCHAR | ASCII) => boundStatement.setString(key, asString(gatlingSession, paramName)) case INT => boundStatement.setInt(key, asInteger(gatlingSession, paramName)) case BOOLEAN => - boundStatement.setBool(key, asBoolean(gatlingSession, paramName)) + boundStatement.setBoolean(key, asBoolean(gatlingSession, paramName)) case (UUID | TIMEUUID) => - boundStatement.setUUID(key, asUuid(gatlingSession, paramName)) + boundStatement.setUuid(key, asUuid(gatlingSession, paramName)) case FLOAT => boundStatement.setFloat(key, asFloat(gatlingSession, paramName)) case DOUBLE => boundStatement.setDouble(key, asDouble(gatlingSession, paramName)) case DECIMAL => - boundStatement.setDecimal(key, asDecimal(gatlingSession, paramName)) + boundStatement.setBigDecimal(key, asDecimal(gatlingSession, paramName)) case INET => - boundStatement.setInet(key, asInet(gatlingSession, paramName)) + boundStatement.setInetAddress(key, asInet(gatlingSession, paramName)) case TIMESTAMP => - boundStatement.setTimestamp(key, asTimestamp(gatlingSession, paramName)) + boundStatement.setInstant(paramName, asInstant(gatlingSession, paramName)) case COUNTER => boundStatement.setLong(key, asCounter(gatlingSession, paramName)) case BIGINT => boundStatement.setLong(key, asBigInt(gatlingSession, paramName)) case BLOB => - boundStatement.setBytes(key, asByte(gatlingSession, paramName)) + boundStatement.setByteBuffer(key, asByte(gatlingSession, paramName)) case VARINT => - boundStatement.setVarint(key, asVarInt(gatlingSession, paramName)) + boundStatement.setBigInteger(key, asVarInt(gatlingSession, paramName)) case LIST => - boundStatement.setList(key, asList(gatlingSession, paramName)) + boundStatement.setList(key, asList(gatlingSession, paramName), Class[String]) case SET => - boundStatement.setSet(key, asSet(gatlingSession, paramName)) + boundStatement.setSet(key, asSet(gatlingSession, paramName), Class[String]) case MAP => - boundStatement.setMap(key, asMap(gatlingSession, paramName)) + boundStatement.setMap(key, asMap(gatlingSession, paramName), Class[String], Class[String]) case UDT => - boundStatement.setUDTValue(key, asUdt(gatlingSession, paramName)) + boundStatement.setUdtValue(key, asUdt(gatlingSession, paramName)) case TUPLE => boundStatement.setTupleValue(key, asTuple(gatlingSession, paramName)) case DATE => - boundStatement.setDate(key, asDate(gatlingSession, paramName)) + boundStatement.setLocalDate(key, asLocalDate(gatlingSession, paramName)) case SMALLINT => boundStatement.setShort(key, asSmallInt(gatlingSession, paramName)) case TINYINT => boundStatement.setByte(key, asTinyInt(gatlingSession, paramName)) case TIME => - boundStatement.setTime(key, asTime(gatlingSession, paramName)) + boundStatement.setLocalTime(key, asLocalTime(gatlingSession, paramName)) case CUSTOM => gatlingSession.attributes.get(paramName) match { case Some(p: Point) => @@ -147,7 +149,7 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { * @param paramType Type of param ie String, int, boolean * @param paramName Gatling Session Attribute Value */ - def bindParamByName(gatlingSession: Session, boundStatement: BoundStatement, paramType: DataType.Name, + def bindParamByName(gatlingSession: Session, boundStatement: BoundStatement, paramType: Int, paramName: String): BoundStatement = { if (!gatlingSession.attributes.contains(paramName)) { @@ -168,50 +170,50 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { boundStatement case _ => paramType match { - case (VARCHAR | TEXT | ASCII) => + case (VARCHAR | ASCII) => boundStatement.setString(paramName, asString(gatlingSession, paramName)) case INT => boundStatement.setInt(paramName, asInteger(gatlingSession, paramName)) case BOOLEAN => - boundStatement.setBool(paramName, asBoolean(gatlingSession, paramName)) + boundStatement.setBoolean(paramName, asBoolean(gatlingSession, paramName)) case (UUID | TIMEUUID) => - boundStatement.setUUID(paramName, asUuid(gatlingSession, paramName)) + boundStatement.setUuid(paramName, asUuid(gatlingSession, paramName)) case FLOAT => boundStatement.setFloat(paramName, asFloat(gatlingSession, paramName)) case DOUBLE => boundStatement.setDouble(paramName, asDouble(gatlingSession, paramName)) case DECIMAL => - boundStatement.setDecimal(paramName, asDecimal(gatlingSession, paramName)) + boundStatement.setBigDecimal(paramName, asDecimal(gatlingSession, paramName)) case INET => - boundStatement.setInet(paramName, asInet(gatlingSession, paramName)) + boundStatement.setInetAddress(paramName, asInet(gatlingSession, paramName)) case TIMESTAMP => - boundStatement.setTimestamp(paramName, asTimestamp(gatlingSession, paramName)) + boundStatement.setInstant(paramName, asInstant(gatlingSession, paramName)) case BIGINT => boundStatement.setLong(paramName, asBigInt(gatlingSession, paramName)) case COUNTER => boundStatement.setLong(paramName, asCounter(gatlingSession, paramName)) case BLOB => - boundStatement.setBytes(paramName, asByte(gatlingSession, paramName)) + boundStatement.setByteBuffer(paramName, asByte(gatlingSession, paramName)) case VARINT => - boundStatement.setVarint(paramName, asVarInt(gatlingSession, paramName)) + boundStatement.setBigInteger(paramName, asVarInt(gatlingSession, paramName)) case LIST => - boundStatement.setList(paramName, asList(gatlingSession, paramName)) + boundStatement.setList(paramName, asList(gatlingSession, paramName), Class[String]) case SET => - boundStatement.setSet(paramName, asSet(gatlingSession, paramName)) + boundStatement.setSet(paramName, asSet(gatlingSession, paramName), Class[String]) case MAP => - boundStatement.setMap(paramName, asMap(gatlingSession, paramName)) + boundStatement.setMap(paramName, asMap(gatlingSession, paramName), Class[String], Class[String]) case UDT => - boundStatement.setUDTValue(paramName, asUdt(gatlingSession, paramName)) + boundStatement.setUdtValue(paramName, asUdt(gatlingSession, paramName)) case TUPLE => boundStatement.setTupleValue(paramName, asTuple(gatlingSession, paramName)) case DATE => - boundStatement.setDate(paramName, asDate(gatlingSession, paramName)) + boundStatement.setLocalDate(paramName, asLocalDate(gatlingSession, paramName)) case SMALLINT => boundStatement.setShort(paramName, asSmallInt(gatlingSession, paramName)) case TINYINT => boundStatement.setByte(paramName, asTinyInt(gatlingSession, paramName)) case TIME => - boundStatement.setTime(paramName, asTime(gatlingSession, paramName)) + boundStatement.setLocalTime(paramName, asLocalTime(gatlingSession, paramName)) case CUSTOM => gatlingSession.attributes.get(paramName) match { case Some(p: Point) => @@ -236,10 +238,10 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { * @param preparedStatement CQL Prepared Stated * @return */ - def getParamsMap(preparedStatement: PreparedStatement): Map[String, DataType.Name] = { - val paramVariables = preparedStatement.getVariables + def getParamsMap(preparedStatement: PreparedStatement): Map[String, Int] = { + val paramVariables = preparedStatement.getVariableDefinitions val paramIterator = paramVariables.iterator.asScala - paramIterator.map(p => (p.getName, p.getType.getName)).toMap + paramIterator.map(p => (p.getName.asCql(true), p.getType.getProtocolCode)).toMap } @@ -249,9 +251,9 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { * @param preparedStatement CQL Prepared Stated * @return */ - def getParamsList(preparedStatement: PreparedStatement): List[DataType.Name] = { - val paramVariables = preparedStatement.getVariables - paramVariables.iterator.asScala.map(p => p.getType.getName).toList + def getParamsList(preparedStatement: PreparedStatement): List[Int] = { + val paramVariables = preparedStatement.getVariableDefinitions + paramVariables.iterator.asScala.map(p => p.getType.getProtocolCode).toList } @@ -484,13 +486,13 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { * @param paramName CQL prepared statement parameter name * @return */ - def asTimestamp(gatlingSession: Session, paramName: String): java.util.Date = { + def asInstant(gatlingSession: Session, paramName: String): Instant = { gatlingSession.attributes.get(paramName).flatMap(Option(_)) match { case Some(l: Long) => - new Date(l) + Instant.ofEpochMilli(l) case Some(s: String) => - DateTime.parse(s).toDate - case Some(d: Date) => + Instant.parse(s) + case Some(d: Instant) => d case _ => throw new CqlTypeException(s"$paramName expected to be type of Long, String or java.util.Date") @@ -695,10 +697,12 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { * @param paramName CQL prepared statement parameter name * @return */ - def asTime(gatlingSession: Session, paramName: String): Long = { + def asLocalTime(gatlingSession: Session, paramName: String): LocalTime = { gatlingSession.attributes.get(paramName).flatMap(Option(_)) match { - case Some(l: Long) => + case Some(l: LocalTime) => l + case Some(l: Long) => + LocalTime.ofNanoOfDay(l) case Some(s: String) => s.trim match { case hourMinSecNanoRegEx(hour, min, second, nano) => parseTime(paramName, hour, min, second, nano) @@ -740,13 +744,7 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { throw new CqlTypeException(s"$paramName Seconds out of bounds.") } - var rawTime: Long = 0 - rawTime += TimeUnit.HOURS.toNanos(hour) - rawTime += TimeUnit.MINUTES.toNanos(min) - rawTime += TimeUnit.SECONDS.toNanos(sec) - rawTime += nanos - - rawTime + LocalTime.of(hour, min, sec, nanos) } @@ -761,16 +759,16 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { * @param paramName CQL prepared statement parameter name * @return */ - def asDate(gatlingSession: Session, paramName: String): com.datastax.driver.core.LocalDate = { + def asLocalDate(gatlingSession: Session, paramName: String): LocalDate = { gatlingSession.attributes.get(paramName).flatMap(Option(_)) match { case Some(s: String) => val dateSplit = s.split("-").toList - LocalDate.fromYearMonthDay(dateSplit.head.toInt, dateSplit(1).toInt, dateSplit(2).toInt) + LocalDate.of(dateSplit.head.toInt, dateSplit(1).toInt, dateSplit(2).toInt) case Some(l: Long) => - LocalDate.fromMillisSinceEpoch(l) + LocalDate.ofEpochDay(l) case Some(i: Int) => - LocalDate.fromDaysSinceEpoch(i) - case Some(ld: com.datastax.driver.core.LocalDate) => + LocalDate.ofEpochDay(i) + case Some(ld: LocalDate) => ld case _ => throw new CqlTypeException(s"$paramName expected to be type of String, Long, Int or LocalDate") @@ -807,9 +805,9 @@ object CqlPreparedStatementUtil extends CqlPreparedStatementUtil { * @param paramName CQL prepared statement parameter name * @return */ - def asUdt(gatlingSession: Session, paramName: String): UDTValue = { + def asUdt(gatlingSession: Session, paramName: String): UdtValue = { gatlingSession.attributes.get(paramName).flatMap(Option(_)) match { - case Some(udt: UDTValue) => + case Some(udt: UdtValue) => udt case _ => throw new CqlTypeException(s"$paramName expected to be type of UDTValue") diff --git a/src/main/scala/com/datastax/gatling/plugin/utils/FutureUtils.scala b/src/main/scala/com/datastax/gatling/plugin/utils/FutureUtils.scala index 8111056..a79f12f 100644 --- a/src/main/scala/com/datastax/gatling/plugin/utils/FutureUtils.scala +++ b/src/main/scala/com/datastax/gatling/plugin/utils/FutureUtils.scala @@ -6,8 +6,13 @@ package com.datastax.gatling.plugin.utils -import com.google.common.util.concurrent.{FutureCallback, Futures, ListenableFuture} +import java.util.concurrent.{CompletableFuture, CompletionStage} + +import com.datastax.oss.driver.shaded.guava.common.util.concurrent.{FutureCallback, Futures} +import org.asynchttpclient.ListenableFuture + +import scala.concurrent.java8.FuturesConvertersImpl._ import scala.concurrent.{Future, Promise} object FutureUtils { @@ -24,16 +29,13 @@ object FutureUtils { * @return a Scala [[Future]] that will be completed when the Guava future * completes */ - def toScalaFuture[T](guavaFuture: ListenableFuture[T]): Future[T] = { - val scalaPromise = Promise[T]() - Futures.addCallback( - guavaFuture, - new FutureCallback[T] { - def onSuccess(result: T): Unit = scalaPromise.success(result) - - def onFailure(exception: Throwable): Unit = scalaPromise.failure(exception) - } - ) - scalaPromise.future + def toScalaFuture[T](guavaFuture: CompletionStage[T]): Future[T] = { + guavaFuture match { + case cf: CF[T] => cf.wrapped + case _ => + val p = new P[T](guavaFuture) + guavaFuture whenComplete p + p.future + } } } diff --git a/src/test/scala/com/datastax/gatling/plugin/DseCqlStatementSpec.scala b/src/test/scala/com/datastax/gatling/plugin/DseCqlStatementSpec.scala index 632b445..2bc45da 100644 --- a/src/test/scala/com/datastax/gatling/plugin/DseCqlStatementSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/DseCqlStatementSpec.scala @@ -2,16 +2,17 @@ package com.datastax.gatling.plugin import java.nio.ByteBuffer -import com.datastax.driver.core.ColumnDefinitions.Definition -import com.datastax.driver.core._ import com.datastax.gatling.plugin.base.BaseSpec import com.datastax.gatling.plugin.exceptions.DseCqlStatementException import com.datastax.gatling.plugin.model._ import com.datastax.gatling.plugin.utils.CqlPreparedStatementUtil +import com.datastax.oss.driver.api.core.cql.{BoundStatement, ColumnDefinitions, PreparedStatement} +import com.datastax.oss.protocol.internal.ProtocolConstants.DataType import io.gatling.commons.validation._ import io.gatling.core.session.Session import io.gatling.core.session.el.ElCompiler import org.easymock.EasyMock._ +import org.scalatest.enablers.Definition import scala.collection.JavaConverters._ @@ -93,14 +94,14 @@ class DseCqlStatementSpec extends BaseSpec { describe("DseCqlBoundStatementWithParamList") { val validParamList = Seq("foo", "bar") - val paramsList = List[DataType.Name](DataType.Name.TEXT, DataType.Name.INT) + val paramsList = List[Integer](DataType.VARCHAR, DataType.INT) it("correctly bind values to a prepared statement") { expecting { prepared.bind().andReturn(mockBoundStatement) mockCqlTypes.getParamsList(prepared).andReturn(paramsList) - mockCqlTypes.bindParamByOrder(validGatlingSession, mockBoundStatement, DataType.Name.TEXT, "foo", 0) + mockCqlTypes.bindParamByOrder(validGatlingSession, mockBoundStatement, DataType.TEXT, "foo", 0) .andReturn(mockBoundStatement) mockCqlTypes.bindParamByOrder(validGatlingSession, mockBoundStatement, DataType.Name.INT, "bar", 1) .andReturn(mockBoundStatement) @@ -121,7 +122,7 @@ class DseCqlStatementSpec extends BaseSpec { expecting { prepared.bind().andReturn(mockBoundStatement) - mockCqlTypes.getParamsMap(prepared).andReturn(Map(fooKey -> DataType.Name.INT)) + mockCqlTypes.getParamsMap(prepared).andReturn(Map(fooKey -> DataType.INT)) mockCqlTypes.bindParamByName(validGatlingSession, mockBoundStatement, DataType.Name.INT, "foo") .andReturn(mockBoundStatement) } @@ -141,7 +142,7 @@ class DseCqlStatementSpec extends BaseSpec { val sessionWithStatement: Session = validGatlingSession.set("statementKey", prepared) expecting { prepared.bind().andReturn(mockBoundStatement) - mockCqlTypes.getParamsMap(prepared).andReturn(Map(fooKey -> DataType.Name.INT)) + mockCqlTypes.getParamsMap(prepared).andReturn(Map(fooKey -> DataType.INT)) mockCqlTypes.bindParamByName(sessionWithStatement, mockBoundStatement, DataType.Name.INT, "foo") .andReturn(mockBoundStatement) } diff --git a/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala b/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala index 553e778..b6f7608 100644 --- a/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala @@ -1,5 +1,6 @@ package com.datastax.gatling.plugin.request +import java.nio.ByteBuffer import java.util.concurrent.{Executor, TimeUnit} import akka.actor.{ActorSystem, Props} @@ -10,11 +11,14 @@ import ch.qos.logback.core.read.ListAppender import com.datastax.driver.core._ import com.datastax.driver.core.policies.FallthroughRetryPolicy import com.datastax.driver.dse.DseSession +import com.datastax.dse.driver.api.core.DseSession import com.datastax.gatling.plugin.base.BaseSpec import com.datastax.gatling.plugin.metrics.NoopMetricsLogger import com.datastax.gatling.plugin.utils.GatlingTimingSource import com.datastax.gatling.plugin.DseProtocol import com.datastax.gatling.plugin.model.{DseCqlAttributes, DseCqlStatement} +import com.datastax.oss.driver.api.core.cql.{ResultSet, SimpleStatement, Statement} +import com.datastax.oss.protocol.internal.ProtocolConstants.ConsistencyLevel import com.google.common.util.concurrent.{Futures, ListenableFuture} import io.gatling.commons.validation.SuccessWrapper import io.gatling.core.action.Exit @@ -30,7 +34,7 @@ class CqlRequestActionSpec extends BaseSpec with TestKitBase { val gatlingTestConfig: GatlingConfiguration = GatlingConfiguration.loadForTest() val dseSession: DseSession = mock[DseSession] val dseCqlStatement: DseCqlStatement = mock[DseCqlStatement] - val pagingState: PagingState = mock[PagingState] + val pagingState: ByteBuffer = mock[ByteBuffer] val statsEngine: StatsEngine = mock[StatsEngine] val gatlingSession = Session("scenario", 1) @@ -68,7 +72,7 @@ class CqlRequestActionSpec extends BaseSpec with TestKitBase { } describe("CQL") { - val statementCapture = EasyMock.newCapture[RegularStatement] + val statementCapture = EasyMock.newCapture[Statement] it("should have default CQL attributes set if nothing passed") { val cqlAttributesWithDefaults = DseCqlAttributes( "test", diff --git a/version.sbt b/version.sbt index 0fd3b43..38ba6eb 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version := "1.3.5-SNAPSHOT" +version := "1.4.0-SNAPSHOT" From ea39ee2bf229145c4a98c254fd110c17861aa647 Mon Sep 17 00:00:00 2001 From: Arthur Landim Date: Mon, 8 Jul 2019 15:55:13 -0300 Subject: [PATCH 2/3] [wip] fix the cql simulations --- build.sbt | 1 - .../com/datastax/gatling/plugin/Predef.scala | 50 ++-- .../gatling/plugin/checks/CqlChecks.scala | 32 +-- .../plugin/checks/DseCheckSupport.scala | 16 -- .../gatling/plugin/checks/GenericChecks.scala | 57 ++--- .../gatling/plugin/checks/GraphChecks.scala | 2 +- .../plugin/model/DseCqlAttributes.scala | 36 ++- .../model/DseCqlAttributesBuilder.scala | 11 +- .../model/DseCqlStatementBuilders.scala | 2 +- .../plugin/model/DseGraphAttributes.scala | 14 +- .../model/DseGraphAttributesBuilder.scala | 18 +- .../model/DseGraphStatementBuilders.scala | 35 ++- .../plugin/model/DseGraphStatements.scala | 1 - .../plugin/request/CqlRequestAction.scala | 6 +- .../request/CqlRequestActionBuilder.scala | 2 +- .../plugin/request/GraphRequestAction.scala | 4 +- .../gatling/plugin/response/DseResponse.scala | 46 +++- .../gatling/plugin/DseCqlStatementSpec.scala | 29 ++- .../plugin/DseGraphStatementSpec.scala | 13 +- .../plugin/base/BaseCassandraServerSpec.scala | 2 +- .../plugin/base/GatlingDseSession.scala | 13 +- .../model/CqlStatementBuildersSpec.scala | 35 ++- .../plugin/request/CqlRequestActionSpec.scala | 8 +- .../request/GraphRequestActionSpec.scala | 22 +- .../cql/BatchStatementSimulation.scala | 9 +- .../cql/BoundCqlTypesSimulation.scala | 21 +- .../cql/NamedStatementSimulation.scala | 4 +- .../cql/PreparedStatementSimulation.scala | 11 +- .../cql/SimpleStatementSimulation.scala | 2 +- .../cql/UdtStatementSimulation.scala | 12 +- .../graph/GraphStatementSimulation.scala | 15 +- .../utils/CqlPreparedStatementUtilSpec.scala | 214 +++++++++--------- 32 files changed, 391 insertions(+), 352 deletions(-) diff --git a/build.sbt b/build.sbt index 37c9391..25acb11 100644 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,6 @@ val gatlingVersion = "2.3.0" scalacOptions += "-target:jvm-1.8" libraryDependencies += "com.datastax.dse" % "dse-java-driver-core" % "2.0.1" -libraryDependencies += "com.datastax.dse" % "dse-java-driver-graph" % "1.8.1" libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "2.18.0" libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.9.1" libraryDependencies += "org.hdrhistogram" % "HdrHistogram" % "2.1.10" diff --git a/src/main/scala/com/datastax/gatling/plugin/Predef.scala b/src/main/scala/com/datastax/gatling/plugin/Predef.scala index 0c43cac..0b9b503 100644 --- a/src/main/scala/com/datastax/gatling/plugin/Predef.scala +++ b/src/main/scala/com/datastax/gatling/plugin/Predef.scala @@ -6,10 +6,11 @@ package com.datastax.gatling.plugin -import com.datastax.gatling.plugin.checks.DseCheckSupport +import com.datastax.dse.driver.api.core.graph.{GraphExecutionInfo, ScriptGraphStatement} +import com.datastax.gatling.plugin.checks.{CqlChecks, CqlGenericChecks, DseCheckSupport, GraphGenericChecks} import com.datastax.gatling.plugin.model.{DseCqlAttributesBuilder, DseCqlStatementBuilder, DseGraphAttributesBuilder, DseGraphStatementBuilder} import com.datastax.gatling.plugin.request._ -import com.datastax.oss.driver.api.core.cql.SimpleStatement +import com.datastax.oss.driver.api.core.cql.{ExecutionInfo, SimpleStatement} import io.gatling.core.action.builder.ActionBuilder import scala.language.implicitConversions @@ -39,7 +40,7 @@ trait DsePredefBase extends DseCheckSupport { implicit def cqlRequestAttributes2ActionBuilder(builder: DseCqlAttributesBuilder[SimpleStatement]): ActionBuilder = builder.build() - implicit def graphRequestAttributes2ActionBuilder(builder: DseGraphAttributesBuilder): ActionBuilder = builder.build() + implicit def graphRequestAttributes2ActionBuilder(builder: DseGraphAttributesBuilder[ScriptGraphStatement]): ActionBuilder = builder.build() } /** @@ -47,16 +48,39 @@ trait DsePredefBase extends DseCheckSupport { */ object DsePredef extends DsePredefBase {} -/** - * Present for backwards compatibility - */ -@deprecated("use DsePredef instead, will be removed in future versions") -object CqlPredef extends DsePredefBase {} +object CqlPredef extends DsePredefBase { + // start global checks + lazy val exhausted = CqlGenericChecks.exhausted + lazy val applied = CqlGenericChecks.applied + lazy val rowCount = CqlGenericChecks.rowCount + + // execution info and subsets + lazy val executionInfo = CqlGenericChecks.executionInfo + lazy val achievedCL = CqlGenericChecks.achievedConsistencyLevel + lazy val pagingState = CqlGenericChecks.pagingState + lazy val queriedHost = CqlGenericChecks.queriedHost + lazy val schemaAgreement = CqlGenericChecks.schemaInAgreement + lazy val successfulExecutionIndex = CqlGenericChecks.successfulExecutionIndex + lazy val triedHosts = CqlGenericChecks.triedHosts + lazy val warnings = CqlGenericChecks.warnings +} -/** - * Present for backwards compatibility - */ -@deprecated("use DsePredef instead, will be removed in future versions") -object GraphPredef extends DsePredefBase {} +object GraphPredef extends DsePredefBase { + // start global checks + lazy val exhausted = GraphGenericChecks.exhausted + lazy val applied = GraphGenericChecks.applied + lazy val rowCount = GraphGenericChecks.rowCount + + // execution info and subsets + lazy val executionInfo = GraphGenericChecks.executionInfo + lazy val achievedCL = GraphGenericChecks.achievedConsistencyLevel + lazy val pagingState = GraphGenericChecks.pagingState + lazy val queriedHost = GraphGenericChecks.queriedHost + lazy val schemaAgreement = GraphGenericChecks.schemaInAgreement + lazy val successfulExecutionIndex = GraphGenericChecks.successfulExecutionIndex + lazy val triedHosts = GraphGenericChecks.triedHosts + lazy val warnings = GraphGenericChecks.warnings + +} diff --git a/src/main/scala/com/datastax/gatling/plugin/checks/CqlChecks.scala b/src/main/scala/com/datastax/gatling/plugin/checks/CqlChecks.scala index f4ace84..b5b8f9c 100644 --- a/src/main/scala/com/datastax/gatling/plugin/checks/CqlChecks.scala +++ b/src/main/scala/com/datastax/gatling/plugin/checks/CqlChecks.scala @@ -6,7 +6,7 @@ package com.datastax.gatling.plugin.checks -import com.datastax.oss.driver.api.core.cql.{ResultSet, Row} +import com.datastax.oss.driver.api.core.cql.{ExecutionInfo, ResultSet, Row} import com.datastax.gatling.plugin.response.CqlResponse import io.gatling.commons.validation.{SuccessWrapper, Validation} import io.gatling.core.check._ @@ -21,28 +21,28 @@ import scala.collection.mutable * * @param wrapped the underlying check */ -case class DseCqlCheck(wrapped: Check[CqlResponse]) extends Check[CqlResponse] { - override def check(response: CqlResponse, session: Session)(implicit cache: mutable.Map[Any, Any]): Validation[CheckResult] = { +case class DseCqlCheck(wrapped: Check[CqlResponse[ExecutionInfo]]) extends Check[CqlResponse[ExecutionInfo]] { + override def check(response: CqlResponse[ExecutionInfo], session: Session)(implicit cache: mutable.Map[Any, Any]): Validation[CheckResult] = { wrapped.check(response, session) } } -class CqlCheckBuilder[X](extractor: Expression[Extractor[CqlResponse, X]]) - extends FindCheckBuilder[DseCqlCheck, CqlResponse, CqlResponse, X] { +class CqlCheckBuilder[X](extractor: Expression[Extractor[CqlResponse[ExecutionInfo], X]]) + extends FindCheckBuilder[DseCqlCheck, CqlResponse[ExecutionInfo], CqlResponse[ExecutionInfo], X] { - private val cqlResponseExtender: Extender[DseCqlCheck, CqlResponse] = + private val cqlResponseExtender: Extender[DseCqlCheck, CqlResponse[ExecutionInfo]] = wrapped => DseCqlCheck(wrapped) - def find: ValidatorCheckBuilder[DseCqlCheck, CqlResponse, CqlResponse, X] = { + def find: ValidatorCheckBuilder[DseCqlCheck, CqlResponse[ExecutionInfo], CqlResponse[ExecutionInfo], X] = { ValidatorCheckBuilder(cqlResponseExtender, x => x.success, extractor) } } private class CqlResponseExtractor[X](val name: String, - val extractor: CqlResponse => X) - extends Extractor[CqlResponse, X] with SingleArity { + val extractor: CqlResponse[ExecutionInfo] => X) + extends Extractor[CqlResponse[ExecutionInfo], X] with SingleArity { - override def apply(response: CqlResponse): Validation[Option[X]] = { + override def apply(response: CqlResponse[ExecutionInfo]): Validation[Option[X]] = { Some(extractor.apply(response)).success } @@ -51,22 +51,22 @@ private class CqlResponseExtractor[X](val name: String, } } -private abstract class ColumnValueExtractor[X] extends CriterionExtractor[CqlResponse, Any, X] { +private abstract class ColumnValueExtractor[X] extends CriterionExtractor[CqlResponse[ExecutionInfo], Any, X] { val criterionName = "columnValue" } private class SingleColumnValueExtractor(val criterion: String, val occurrence: Int) extends ColumnValueExtractor[Any] with FindArity { - def extract(response: CqlResponse): Validation[Option[Any]] = + def extract(response: CqlResponse[ExecutionInfo]): Validation[Option[Any]] = response.getCqlResultColumnValues(criterion).lift(occurrence).success } private class MultipleColumnValueExtractor(val criterion: String) extends ColumnValueExtractor[Seq[Any]] with FindAllArity { - def extract(response: CqlResponse): Validation[Option[Seq[Any]]] = + def extract(response: CqlResponse[ExecutionInfo]): Validation[Option[Seq[Any]]] = response.getCqlResultColumnValues(criterion).liftSeqOption.success } private class CountColumnValueExtractor(val criterion: String) extends ColumnValueExtractor[Int] with CountArity { - def extract(response: CqlResponse): Validation[Option[Int]] = + def extract(response: CqlResponse[ExecutionInfo]): Validation[Option[Int]] = response.getCqlResultColumnValues(criterion).liftSeqOption.map(_.size).success } @@ -90,8 +90,8 @@ object CqlChecks { .toCheckBuilder def columnValue(columnName: Expression[String]) = { - val cqlResponseExtender: Extender[DseCqlCheck, CqlResponse] = wrapped => DseCqlCheck(wrapped) - new DefaultMultipleFindCheckBuilder[DseCqlCheck, CqlResponse, CqlResponse, Any](cqlResponseExtender, x => x.success) { + val cqlResponseExtender: Extender[DseCqlCheck, CqlResponse[ExecutionInfo]] = wrapped => DseCqlCheck(wrapped) + new DefaultMultipleFindCheckBuilder[DseCqlCheck, CqlResponse[ExecutionInfo], CqlResponse[ExecutionInfo], Any](cqlResponseExtender, x => x.success) { def findExtractor(occurrence: Int) = columnName.map(new SingleColumnValueExtractor(_, occurrence)) def findAllExtractor = columnName.map(new MultipleColumnValueExtractor(_)) def countExtractor = columnName.map(new CountColumnValueExtractor(_)) diff --git a/src/main/scala/com/datastax/gatling/plugin/checks/DseCheckSupport.scala b/src/main/scala/com/datastax/gatling/plugin/checks/DseCheckSupport.scala index fe0e808..7361f6c 100644 --- a/src/main/scala/com/datastax/gatling/plugin/checks/DseCheckSupport.scala +++ b/src/main/scala/com/datastax/gatling/plugin/checks/DseCheckSupport.scala @@ -9,22 +9,6 @@ package com.datastax.gatling.plugin.checks import io.gatling.core.session.ExpressionSuccessWrapper trait DseCheckSupport { - - // start global checks - lazy val exhausted = GenericChecks.exhausted - lazy val applied = GenericChecks.applied - lazy val rowCount = GenericChecks.rowCount - - // execution info and subsets - lazy val executionInfo = GenericChecks.executionInfo - lazy val achievedCL = GenericChecks.achievedConsistencyLevel - lazy val pagingState = GenericChecks.pagingState - lazy val queriedHost = GenericChecks.queriedHost - lazy val schemaAgreement = GenericChecks.schemaInAgreement - lazy val successfulExecutionIndex = GenericChecks.successfulExecutionIndex - lazy val triedHosts = GenericChecks.triedHosts - lazy val warnings = GenericChecks.warnings - // start CQL only checks lazy val resultSet = CqlChecks.resultSet lazy val allRows = CqlChecks.allRows diff --git a/src/main/scala/com/datastax/gatling/plugin/checks/GenericChecks.scala b/src/main/scala/com/datastax/gatling/plugin/checks/GenericChecks.scala index 8fe1919..65a5e0f 100644 --- a/src/main/scala/com/datastax/gatling/plugin/checks/GenericChecks.scala +++ b/src/main/scala/com/datastax/gatling/plugin/checks/GenericChecks.scala @@ -18,6 +18,8 @@ import io.gatling.core.session.{Expression, ExpressionSuccessWrapper, Session} import scala.collection.mutable import java.nio.ByteBuffer +import com.datastax.dse.driver.api.core.graph.GraphExecutionInfo + /** * This class allows to execute checks on either CQL or Graph responses. * @@ -26,106 +28,109 @@ import java.nio.ByteBuffer * would make it possible to execute CQL checks on Graph responses, or * vice-versa. */ -case class GenericCheck(wrapped: Check[DseResponse]) extends Check[DseResponse] { - override def check(response: DseResponse, session: Session)(implicit cache: mutable.Map[Any, Any]): Validation[CheckResult] = { +case class GenericCheck[E](wrapped: Check[DseResponse[E]]) extends Check[DseResponse[E]] { + override def check(response: DseResponse[E], session: Session)(implicit cache: mutable.Map[Any, Any]): Validation[CheckResult] = { wrapped.check(response, session) } } -class GenericCheckBuilder[X](extractor: Expression[Extractor[DseResponse, X]]) - extends FindCheckBuilder[GenericCheck, DseResponse, DseResponse, X] { +class GenericCheckBuilder[X, E](extractor: Expression[Extractor[DseResponse[E], X]]) + extends FindCheckBuilder[GenericCheck[E], DseResponse[E], DseResponse[E], X] { - private val dseResponseExtender: Extender[GenericCheck, DseResponse] = + private val dseResponseExtender: Extender[GenericCheck[E], DseResponse[E]] = wrapped => GenericCheck(wrapped) - def find: ValidatorCheckBuilder[GenericCheck, DseResponse, DseResponse, X] = { + def find: ValidatorCheckBuilder[GenericCheck[E], DseResponse[E], DseResponse[E], X] = { ValidatorCheckBuilder(dseResponseExtender, x => x.success, extractor) } } -private class GenericResponseExtractor[X](val name: String, - val extractor: DseResponse => X) - extends Extractor[DseResponse, X] with SingleArity { +private class GenericResponseExtractor[X, E](val name: String, + val extractor: DseResponse[E] => X) + extends Extractor[DseResponse[E], X] with SingleArity { - override def apply(response: DseResponse): Validation[Option[X]] = { + override def apply(response: DseResponse[E]): Validation[Option[X]] = { Some(extractor.apply(response)).success } - def toCheckBuilder: GenericCheckBuilder[X] = { - new GenericCheckBuilder[X](this.expressionSuccess) + def toCheckBuilder: GenericCheckBuilder[X, E] = { + new GenericCheckBuilder[X, E](this.expressionSuccess) } } -object GenericChecks { +class GenericChecks[T] { val executionInfo = - new GenericResponseExtractor[ExecutionInfo]( + new GenericResponseExtractor[T, T]( "executionInfo", r => r.executionInfo()) .toCheckBuilder val queriedHost = - new GenericResponseExtractor[Node]( + new GenericResponseExtractor[Node, T]( "queriedHost", r => r.queriedHost()) .toCheckBuilder val achievedConsistencyLevel = - new GenericResponseExtractor[ConsistencyLevel]( + new GenericResponseExtractor[ConsistencyLevel, T]( "achievedConsistencyLevel", - r => r.executionInfo().getStatement.getConsistencyLevel()) + r => r.getConsistencyLevel()) .toCheckBuilder val speculativeExecutionsExtractor = - new GenericResponseExtractor[Int]( + new GenericResponseExtractor[Int, T]( "speculativeExecutions", r => r.speculativeExecutions()) .toCheckBuilder val pagingState = - new GenericResponseExtractor[ByteBuffer]( + new GenericResponseExtractor[ByteBuffer, T]( "pagingState", r => r.pagingState()) .toCheckBuilder val triedHosts = - new GenericResponseExtractor[List[Node]]( + new GenericResponseExtractor[List[Node], T]( "triedHost", r => r.triedHosts()) .toCheckBuilder val warnings = - new GenericResponseExtractor[List[String]]( + new GenericResponseExtractor[List[String], T]( "warnings", r => r.warnings()) .toCheckBuilder val successfulExecutionIndex = - new GenericResponseExtractor[Int]( + new GenericResponseExtractor[Int, T]( "successfulExecutionIndex", r => r.successFullExecutionIndex()) .toCheckBuilder val schemaInAgreement = - new GenericResponseExtractor[Boolean]( + new GenericResponseExtractor[Boolean, T]( "schemaInAgreement", r => r.schemaInAgreement()) .toCheckBuilder val rowCount = - new GenericResponseExtractor[Int]( + new GenericResponseExtractor[Int, T]( "rowCount", r => r.rowCount()) .toCheckBuilder val applied = - new GenericResponseExtractor[Boolean]( + new GenericResponseExtractor[Boolean, T]( "applied", r => r.applied()) .toCheckBuilder val exhausted = - new GenericResponseExtractor[Boolean]( + new GenericResponseExtractor[Boolean, T]( "exhausted", r => r.applied()) .toCheckBuilder } + +object CqlGenericChecks extends GenericChecks[ExecutionInfo]; +object GraphGenericChecks extends GenericChecks[GraphExecutionInfo]; diff --git a/src/main/scala/com/datastax/gatling/plugin/checks/GraphChecks.scala b/src/main/scala/com/datastax/gatling/plugin/checks/GraphChecks.scala index 643e8b8..36152eb 100644 --- a/src/main/scala/com/datastax/gatling/plugin/checks/GraphChecks.scala +++ b/src/main/scala/com/datastax/gatling/plugin/checks/GraphChecks.scala @@ -54,7 +54,7 @@ private class GraphResponseExtractor[X](val name: String, } } -object GraphChecks { +object GraphChecks extends GenericChecks[GraphExecutionInfo] { val graphResultSet = new GraphResponseExtractor[GraphResultSet]( "graphResultSet", diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributes.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributes.scala index e2f8cb7..b7c465e 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributes.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributes.scala @@ -8,11 +8,9 @@ package com.datastax.gatling.plugin.model import java.nio.ByteBuffer +import com.datastax.gatling.plugin.checks.{DseCqlCheck, GenericCheck} import com.datastax.oss.driver.api.core.retry.RetryPolicy -import com.datastax.oss.driver.api.core.ConsistencyLevel -import com.datastax.oss.driver.api.core.cql.Statement -import com.datastax.gatling.plugin.response.{CqlResponse, DseResponse} -import io.gatling.core.check.Check +import com.datastax.oss.driver.api.core.cql.{ExecutionInfo, Statement} /** * CQL Query Attributes to be applied to the current query @@ -38,18 +36,18 @@ import io.gatling.core.check.Check * */ case class DseCqlAttributes[T](tag: String, - statement: DseCqlStatement[T], - cl: Option[ConsistencyLevel] = None, - cqlChecks: List[Check[CqlResponse]] = List.empty, - genericChecks: List[Check[DseResponse]] = List.empty, - userOrRole: Option[String] = None, - readTimeout: Option[Int] = None, - idempotent: Option[Boolean] = None, - defaultTimestamp: Option[Long] = None, - enableTrace: Option[Boolean] = None, - outGoingPayload: Option[Map[String, ByteBuffer]] = None, - serialCl: Option[ConsistencyLevel] = None, - fetchSize: Option[Int] = None, - retryPolicy: Option[RetryPolicy] = None, - pagingState: Option[ByteBuffer] = None, - cqlStatements: Seq[String] = Seq.empty) + statement: DseCqlStatement[T], + cl: Option[Int] = None, + cqlChecks: List[DseCqlCheck] = List.empty, + genericChecks: List[GenericCheck[ExecutionInfo]] = List.empty, + userOrRole: Option[String] = None, + readTimeout: Option[Int] = None, + idempotent: Option[Boolean] = None, + defaultTimestamp: Option[Long] = None, + enableTrace: Option[Boolean] = None, + outGoingPayload: Option[Map[String, ByteBuffer]] = None, + serialCl: Option[Int] = None, + fetchSize: Option[Int] = None, + retryPolicy: Option[RetryPolicy] = None, + pagingState: Option[ByteBuffer] = None, + cqlStatements: Seq[String] = Seq.empty) diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributesBuilder.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributesBuilder.scala index fa0aa17..a78fb54 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributesBuilder.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlAttributesBuilder.scala @@ -11,6 +11,7 @@ import java.nio.ByteBuffer import com.datastax.gatling.plugin.checks.{DseCqlCheck, GenericCheck} import com.datastax.gatling.plugin.request.CqlRequestActionBuilder import com.datastax.oss.driver.api.core.ConsistencyLevel +import com.datastax.oss.driver.api.core.cql.ExecutionInfo import com.datastax.oss.driver.api.core.retry.RetryPolicy @@ -33,7 +34,7 @@ case class DseCqlAttributesBuilder[T](attr: DseCqlAttributes[T]) { * @param level ConsistencyLevel * @return */ - def withConsistencyLevel(level: ConsistencyLevel) = DseCqlAttributesBuilder(attr.copy(cl = Some(level))) + def withConsistencyLevel(level: Int) = DseCqlAttributesBuilder(attr.copy(cl = Some(level))) /** * Execute a query as another user or another role, provided the current logged in user has PROXY.EXECUTE permission. @@ -80,7 +81,7 @@ case class DseCqlAttributesBuilder[T](attr: DseCqlAttributes[T]) { * @param level ConsistencyLevel * @return */ - def withSerialConsistencyLevel(level: ConsistencyLevel) = DseCqlAttributesBuilder(attr.copy(serialCl = Some(level))) + def withSerialConsistencyLevel(level: Int) = DseCqlAttributesBuilder(attr.copy(serialCl = Some(level))) /** @@ -124,7 +125,7 @@ case class DseCqlAttributesBuilder[T](attr: DseCqlAttributes[T]) { * @return */ @deprecated("Replaced by withSerialConsistencyLevel") - def serialConsistencyLevel(level: ConsistencyLevel) = withSerialConsistencyLevel(level) + def serialConsistencyLevel(level: Int) = withSerialConsistencyLevel(level) /** @@ -135,7 +136,7 @@ case class DseCqlAttributesBuilder[T](attr: DseCqlAttributes[T]) { * @return */ @deprecated("Replaced by withConsistencyLevel") - def consistencyLevel(level: ConsistencyLevel) = withConsistencyLevel(level) + def consistencyLevel(level: Int) = withConsistencyLevel(level) /** @@ -150,5 +151,5 @@ case class DseCqlAttributesBuilder[T](attr: DseCqlAttributes[T]) { def check(check: DseCqlCheck) = DseCqlAttributesBuilder(attr.copy(cqlChecks = check :: attr.cqlChecks)) - def check(check: GenericCheck) = DseCqlAttributesBuilder(attr.copy(genericChecks = check :: attr.genericChecks)) + def check(check: GenericCheck[ExecutionInfo]) = DseCqlAttributesBuilder(attr.copy(genericChecks = check :: attr.genericChecks)) } diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatementBuilders.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatementBuilders.scala index 51c2fe4..561e9cc 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatementBuilders.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseCqlStatementBuilders.scala @@ -8,7 +8,7 @@ package com.datastax.gatling.plugin.model import com.datastax.gatling.plugin._ import com.datastax.gatling.plugin.utils.CqlPreparedStatementUtil -import com.datastax.oss.driver.api.core.cql.{BatchableStatement, BoundStatement, PreparedStatement, SimpleStatement} +import com.datastax.oss.driver.api.core.cql.{BoundStatement, PreparedStatement, SimpleStatement} import io.gatling.core.session.Expression /** diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributes.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributes.scala index 9aa02b8..d8ca1d2 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributes.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributes.scala @@ -6,7 +6,7 @@ package com.datastax.gatling.plugin.model -import com.datastax.dse.driver.api.core.graph.{GraphNode, GraphStatement, ScriptGraphStatement} +import com.datastax.dse.driver.api.core.graph.{GraphExecutionInfo, GraphNode, GraphStatement, ScriptGraphStatement} import com.datastax.gatling.plugin.checks.{DseGraphCheck, GenericCheck} import com.datastax.oss.driver.api.core.ConsistencyLevel import com.datastax.oss.driver.api.core.cql.Row @@ -34,17 +34,17 @@ import com.datastax.oss.driver.api.core.cql.Row * @param graphInternalOptions Query-specific options not available in the driver public API * @param graphTransformResults Function to use in order to transform a row into a Graph node */ -case class DseGraphAttributes(tag: String, - statement: DseStatement[GraphStatement[ScriptGraphStatement]], - cl: Option[ConsistencyLevel] = None, +case class DseGraphAttributes[G](tag: String, + statement: GraphStatement[G], + cl: Option[Int] = None, graphChecks: List[DseGraphCheck] = List.empty, - genericChecks: List[GenericCheck] = List.empty, + genericChecks: List[GenericCheck[GraphExecutionInfo]] = List.empty, userOrRole: Option[String] = None, readTimeout: Option[Int] = None, idempotent: Option[Boolean] = None, defaultTimestamp: Option[Long] = None, - readCL: Option[ConsistencyLevel] = None, - writeCL: Option[ConsistencyLevel] = None, + readCL: Option[Int] = None, + writeCL: Option[Int] = None, graphName: Option[String] = None, graphLanguage: Option[String] = None, graphSource: Option[String] = None, diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributesBuilder.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributesBuilder.scala index 6705a66..19065c2 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributesBuilder.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphAttributesBuilder.scala @@ -6,11 +6,11 @@ package com.datastax.gatling.plugin.model -import com.datastax.dse.driver.api.core.graph.GraphNode +import com.datastax.dse.driver.api.core.graph.{GraphExecutionInfo, GraphNode} import com.datastax.gatling.plugin.checks.{DseGraphCheck, GenericCheck} import com.datastax.gatling.plugin.request.GraphRequestActionBuilder -import com.datastax.oss.driver.api.core.ConsistencyLevel import com.datastax.oss.driver.api.core.cql.Row +import com.datastax.oss.protocol.internal.ProtocolConstants.ConsistencyLevel import io.gatling.core.action.builder.ActionBuilder @@ -19,13 +19,13 @@ import io.gatling.core.action.builder.ActionBuilder * * @param attr Addition Attributes */ -case class DseGraphAttributesBuilder(attr: DseGraphAttributes) { +case class DseGraphAttributesBuilder[G](attr: DseGraphAttributes[G]) { /** * Builds to final action to run * * @return */ - def build(): ActionBuilder = new GraphRequestActionBuilder(attr) + def build(): ActionBuilder = new GraphRequestActionBuilder(attr[G]) /** * Set Consistency Level @@ -33,7 +33,7 @@ case class DseGraphAttributesBuilder(attr: DseGraphAttributes) { * @param level ConsistencyLevel * @return */ - def withConsistencyLevel(level: ConsistencyLevel) = DseGraphAttributesBuilder(attr.copy(cl = Some(level))) + def withConsistencyLevel(level: Int) = DseGraphAttributesBuilder(attr.copy(cl = Some(level))) /** * Execute a query as another user or another role, provided the current logged in user has PROXY.EXECUTE permission. @@ -140,7 +140,7 @@ case class DseGraphAttributesBuilder(attr: DseGraphAttributes) { * @param readCL Consistency Level to use * @return */ - def withReadConsistency(readCL: ConsistencyLevel) = DseGraphAttributesBuilder(attr.copy(readCL = Some(readCL))) + def withReadConsistency(readCL: Int) = DseGraphAttributesBuilder(attr.copy(readCL = Some(readCL))) /** * Define [[ConsistencyLevel]] to be used for write queries @@ -148,7 +148,7 @@ case class DseGraphAttributesBuilder(attr: DseGraphAttributes) { * @param writeCL Consistency Level to use * @return */ - def withWriteConsistency(writeCL: ConsistencyLevel) = DseGraphAttributesBuilder(attr.copy(writeCL = Some(writeCL))) + def withWriteConsistency(writeCL: Int) = DseGraphAttributesBuilder(attr.copy(writeCL = Some(writeCL))) /** @@ -159,7 +159,7 @@ case class DseGraphAttributesBuilder(attr: DseGraphAttributes) { * @return */ @deprecated("use withConsistencyLevel() instead, will be removed in future version") - def consistencyLevel(level: ConsistencyLevel) = withConsistencyLevel(level) + def consistencyLevel(level: Int) = withConsistencyLevel(level) /** @@ -173,5 +173,5 @@ case class DseGraphAttributesBuilder(attr: DseGraphAttributes) { def executeAs(userOrRole: String) = withUserOrRole(userOrRole: String) def check(check: DseGraphCheck) = DseGraphAttributesBuilder(attr.copy(graphChecks = check :: attr.graphChecks)) - def check(check: GenericCheck) = DseGraphAttributesBuilder(attr.copy(genericChecks = check :: attr.genericChecks)) + def check(check: GenericCheck[GraphExecutionInfo]) = DseGraphAttributesBuilder(attr.copy(genericChecks = check :: attr.genericChecks)) } diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatementBuilders.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatementBuilders.scala index 73f1844..a99832a 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatementBuilders.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatementBuilders.scala @@ -5,9 +5,7 @@ */ package com.datastax.gatling.plugin.model - -import com.datastax.dse.driver.api.core.graph.ScriptGraphStatement -import com.datastax.dse.graph.api._ +import com.datastax.dse.driver.api.core.graph.{FluentGraphStatement, GraphStatement, ScriptGraphStatement} import io.gatling.core.session.{Expression, Session} /** @@ -23,9 +21,9 @@ case class DseGraphStatementBuilder(tag: String) { * @param strStatement Graph Query String * @return */ - def executeGraph(strStatement: Expression[String]) = { - DseGraphAttributesBuilder(DseGraphAttributes(tag, GraphStringStatement(strStatement))) - } + def executeGraph(strStatement: Expression[String]) = + DseGraphAttributesBuilder[ScriptGraphStatement](DseGraphAttributes[ScriptGraphStatement](tag, ScriptGraphStatement.newInstance(strStatement.toString()))) + /** * Execute a Simple Graph Statement, which can include named params @@ -35,7 +33,7 @@ case class DseGraphStatementBuilder(tag: String) { * @return */ @deprecated("Replaced by executeGraph(SimpleGraphStatement)") - def executeGraphStatement(gStatement: ScriptGraphStatement) = + def executeGraphStatement(gStatement: GraphStatement[ScriptGraphStatement]) = executeGraph(gStatement) /** @@ -45,7 +43,7 @@ case class DseGraphStatementBuilder(tag: String) { * @param gStatement Simple Graph Statement * @return */ - def executeGraph(gStatement: SimpleGraphStatement) = { + def executeGraph(gStatement: GraphStatement[ScriptGraphStatement]) = { DseGraphParametrizedStatementBuilder(tag, gStatement) } @@ -55,8 +53,8 @@ case class DseGraphStatementBuilder(tag: String) { * @param gStatement Graph Statement from a Fluent API builder * @return */ - def executeGraphFluent(gStatement: GraphStatement) = { - DseGraphAttributesBuilder(DseGraphAttributes(tag, GraphFluentStatement(gStatement))) + def executeGraphFluent(gStatement: GraphStatement[FluentGraphStatement]) = { + DseGraphAttributesBuilder[GraphFluentStatement](DseGraphAttributes(tag, gStatement)) } /** @@ -72,7 +70,7 @@ case class DseGraphStatementBuilder(tag: String) { * @param gLambda The lambda * @return */ - def executeGraphFluent(gLambda: Session => GraphStatement) = { + def executeGraphFluent(gLambda: Session => FluentGraphStatement) = { DseGraphAttributesBuilder(DseGraphAttributes(tag, GraphFluentStatementFromScalaLambda(gLambda))) } @@ -83,9 +81,8 @@ case class DseGraphStatementBuilder(tag: String) { * @return */ @deprecated("Replaced by executeGraphFluent{session => session(feederKey)}") - def executeGraphFeederTraversal(feederKey: String): DseGraphAttributesBuilder = { - DseGraphAttributesBuilder(DseGraphAttributes(tag, GraphFluentSessionKey(feederKey))) - } + def executeGraphFeederTraversal(feederKey: String): DseGraphAttributesBuilder[FluentGraphStatement] = + DseGraphAttributesBuilder[FluentGraphStatement](DseGraphAttributes(tag, GraphFluentSessionKey(feederKey))) } /** @@ -94,7 +91,7 @@ case class DseGraphStatementBuilder(tag: String) { * @param tag Query tag * @param gStatement Simple Graph Staetment */ -case class DseGraphParametrizedStatementBuilder(tag: String, gStatement: SimpleGraphStatement) { +case class DseGraphParametrizedStatementBuilder(tag: String, gStatement: GraphStringStatement) { /** * Included for compatibility @@ -103,7 +100,7 @@ case class DseGraphParametrizedStatementBuilder(tag: String, gStatement: SimpleG * @return */ @deprecated("Replaced by withParams") - def withSetParams(paramNames: Array[String]): DseGraphAttributesBuilder = withParams(paramNames.toList) + def withSetParams(paramNames: Array[String]): DseGraphAttributesBuilder[ScriptGraphStatement] = withParams(paramNames.toList) /** * Params to set from strings @@ -111,7 +108,7 @@ case class DseGraphParametrizedStatementBuilder(tag: String, gStatement: SimpleG * @param paramNames List of strings to use * @return */ - def withParams(paramNames: String*): DseGraphAttributesBuilder = + def withParams(paramNames: String*): DseGraphAttributesBuilder[ScriptGraphStatement] = withParams(paramNames.toList) /** @@ -120,8 +117,8 @@ case class DseGraphParametrizedStatementBuilder(tag: String, gStatement: SimpleG * @param paramNames List of strings to use * @return */ - def withParams(paramNames: List[String]): DseGraphAttributesBuilder = DseGraphAttributesBuilder( - DseGraphAttributes(tag, GraphBoundStatement(gStatement, paramNames.map(key => key -> key).toMap)) + def withParams(paramNames: List[String]): DseGraphAttributesBuilder[ScriptGraphStatement] = DseGraphAttributesBuilder( + DseGraphAttributes[ScriptGraphStatement](tag, GraphBoundStatement(gStatement, paramNames.map(key => key -> key).toMap)) ) /** diff --git a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatements.scala b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatements.scala index cd167a8..764916c 100644 --- a/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatements.scala +++ b/src/main/scala/com/datastax/gatling/plugin/model/DseGraphStatements.scala @@ -7,7 +7,6 @@ package com.datastax.gatling.plugin.model import com.datastax.dse.driver.api.core.graph.{FluentGraphStatement, GraphStatement, ScriptGraphStatement} -import com.datastax.dse.graph.api.DseGraph import com.datastax.gatling.plugin.exceptions.DseGraphStatementException import io.gatling.commons.validation._ import io.gatling.core.session.{Expression, Session} diff --git a/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestAction.scala b/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestAction.scala index af85bc8..10e5a65 100644 --- a/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestAction.scala +++ b/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestAction.scala @@ -19,7 +19,9 @@ import com.datastax.gatling.plugin.metrics.MetricsLogger import com.datastax.gatling.plugin.model.DseCqlAttributes import com.datastax.gatling.plugin.response.CqlResponseHandler import com.datastax.gatling.plugin.utils._ +import com.datastax.oss.driver.api.core.DefaultConsistencyLevel import com.datastax.oss.driver.api.core.cql.SimpleStatement +import com.datastax.oss.protocol.internal.ProtocolConstants.ConsistencyLevel import io.gatling.commons.stats.KO import io.gatling.commons.validation.safely import io.gatling.core.action.{Action, ExitableAction} @@ -81,7 +83,7 @@ class CqlRequestAction(val name: String, stmt.onSuccess({ stmt => // global options - dseAttributes.cl.map(stmt.setConsistencyLevel) + dseAttributes.cl.map(cl => stmt.setConsistencyLevel(DefaultConsistencyLevel.fromCode(cl))) // TODO refactored //dseAttributes.userOrRole.map(stmt.executingAs) dseAttributes.readTimeout.map( timeout => stmt.setTimeout(Duration.ofMillis(timeout))) @@ -90,7 +92,7 @@ class CqlRequestAction(val name: String, // CQL Only Options dseAttributes.outGoingPayload.map(x => stmt.setCustomPayload(x.asJava)) - dseAttributes.serialCl.map(stmt.setSerialConsistencyLevel) + dseAttributes.serialCl.map(serialCl => stmt.setSerialConsistencyLevel(DefaultConsistencyLevel.fromCode(serialCl))) //TODO find equivalent methods //dseAttributes.retryPolicy.map(stmt.setRetryPolicy) //dseAttributes.fetchSize.map(stmt.setFetchSize) diff --git a/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestActionBuilder.scala b/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestActionBuilder.scala index eb8b6b9..930c5b3 100644 --- a/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestActionBuilder.scala +++ b/src/main/scala/com/datastax/gatling/plugin/request/CqlRequestActionBuilder.scala @@ -24,7 +24,7 @@ class CqlRequestActionBuilder[T](val dseAttributes: DseCqlAttributes[T]) extends ctx.system, ctx.coreComponents.statsEngine, dseComponents.dseProtocol, - dseAttributes, + dseAttributes[T], dseComponents.metricsLogger, dseComponents.dseExecutorService, dseComponents.gatlingTimingSource) diff --git a/src/main/scala/com/datastax/gatling/plugin/request/GraphRequestAction.scala b/src/main/scala/com/datastax/gatling/plugin/request/GraphRequestAction.scala index 691c7b6..97da6fa 100644 --- a/src/main/scala/com/datastax/gatling/plugin/request/GraphRequestAction.scala +++ b/src/main/scala/com/datastax/gatling/plugin/request/GraphRequestAction.scala @@ -43,12 +43,12 @@ import scala.concurrent.{ExecutionContext, ExecutionContextExecutor} * work includes recording it in HDR histograms through non-blocking data structures, and forwarding the result to * other Gatling data writers, like the console reporter. */ -class GraphRequestAction(val name: String, +class GraphRequestAction[G](val name: String, val next: Action, val system: ActorSystem, val statsEngine: StatsEngine, val protocol: DseProtocol, - val dseAttributes: DseGraphAttributes, + val dseAttributes: DseGraphAttributes[G], val metricsLogger: MetricsLogger, val dseExecutorService: ExecutorService, val gatlingTimingSource: GatlingTimingSource) diff --git a/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala b/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala index e9d0e36..5fee93d 100644 --- a/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala +++ b/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala @@ -14,31 +14,45 @@ import com.typesafe.scalalogging.LazyLogging import scala.util.Try import java.nio.ByteBuffer + import org.apache.tinkerpop.gremlin.structure._ import org.apache.tinkerpop.gremlin.process.traversal.Path import java.util.stream.Collectors +import com.datastax.oss.driver.api.core.ConsistencyLevel + +import collection.JavaConverters._ + abstract class DseResponse[E] { def executionInfo(): E def rowCount(): Int def applied(): Boolean - def queriedHost(): Node = executionInfo().getCoordinator() - def speculativeExecutions(): Int = executionInfo().getSpeculativeExecutionCount - def pagingState(): ByteBuffer = executionInfo().getPagingState - def triedHosts(): List[Node] = executionInfo().getErrors.stream.map(_.getKey).collect(Collectors.toList[Node]).asScala.toList - def warnings(): List[String] = executionInfo().getWarnings.asScala.toList - def successFullExecutionIndex(): Int = executionInfo().getSuccessfulExecutionIndex - def schemaInAgreement(): Boolean = executionInfo().isSchemaInAgreement + def queriedHost(): Node + def speculativeExecutions(): Int + def pagingState(): ByteBuffer + def triedHosts(): List[Node] + def warnings(): List[String] + def successFullExecutionIndex(): Int + def schemaInAgreement(): Boolean + def exhausted(): Boolean + def getConsistencyLevel(): ConsistencyLevel } -class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttributes) extends DseResponse with LazyLogging { +class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttributes) extends DseResponse[GraphExecutionInfo] with LazyLogging { private lazy val allGraphNodes: Seq[GraphNode] = collection.JavaConverters.asScalaBuffer(graphResultSet.all()) - def graphExecutionInfo(): GraphExecutionInfo = graphResultSet.getExecutionInfo() - override def executionInfo(): ExecutionInfo = null + override def executionInfo(): GraphExecutionInfo = graphResultSet.getExecutionInfo() override def applied(): Boolean = false // graph doesn't support LWTs so always return false - //override def exhausted(): Boolean = isFullyFetched() + override def queriedHost(): Node = executionInfo().getCoordinator() + override def speculativeExecutions(): Int = executionInfo().getSpeculativeExecutionCount() + override def pagingState(): ByteBuffer = null + def triedHosts(): List[Node] = executionInfo().getErrors().asScala.map[Node](_.getKey).toList + def warnings(): List[String] = executionInfo().getWarnings().asScala.toList + override def successFullExecutionIndex(): Int = ??? + override def schemaInAgreement(): Boolean = ??? + override def exhausted(): Boolean = true + override def getConsistencyLevel(): ConsistencyLevel = graphResultSet.getExecutionInfo.getStatement.getConsistencyLevel /** * Get the number of all rows returned by the query. @@ -105,13 +119,21 @@ class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttri } def getDseAttributes: DseGraphAttributes = dseAttributes + } -class CqlResponse[T](cqlResultSet: ResultSet, dseAttributes: DseCqlAttributes[T]) extends DseResponse with LazyLogging { +class CqlResponse[T](cqlResultSet: ResultSet, dseAttributes: DseCqlAttributes[T]) extends DseResponse[ExecutionInfo] with LazyLogging { private lazy val allCqlRows: Seq[Row] = collection.JavaConverters.asScalaBuffer(cqlResultSet.all()) override def executionInfo(): ExecutionInfo = cqlResultSet.getExecutionInfo() override def applied(): Boolean = cqlResultSet.wasApplied() + override def pagingState(): ByteBuffer = executionInfo().getPagingState() + override def triedHosts(): List[Node] = executionInfo().getErrors().asScala.map[Node](_.getKey).toList + override def warnings(): List[String] = executionInfo().getWarnings().asScala.toList + override def successFullExecutionIndex(): Int = executionInfo().getSuccessfulExecutionIndex + override def schemaInAgreement(): Boolean = executionInfo().isSchemaInAgreement + override def getConsistencyLevel(): ConsistencyLevel = cqlResultSet.getExecutionInfo.getStatement.getConsistencyLevel + /** * Get the number of all rows returned by the query. diff --git a/src/test/scala/com/datastax/gatling/plugin/DseCqlStatementSpec.scala b/src/test/scala/com/datastax/gatling/plugin/DseCqlStatementSpec.scala index 2bc45da..0efc981 100644 --- a/src/test/scala/com/datastax/gatling/plugin/DseCqlStatementSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/DseCqlStatementSpec.scala @@ -6,13 +6,12 @@ import com.datastax.gatling.plugin.base.BaseSpec import com.datastax.gatling.plugin.exceptions.DseCqlStatementException import com.datastax.gatling.plugin.model._ import com.datastax.gatling.plugin.utils.CqlPreparedStatementUtil -import com.datastax.oss.driver.api.core.cql.{BoundStatement, ColumnDefinitions, PreparedStatement} +import com.datastax.oss.driver.api.core.cql.{BoundStatement, ColumnDefinitions, PreparedStatement, SimpleStatement} import com.datastax.oss.protocol.internal.ProtocolConstants.DataType import io.gatling.commons.validation._ import io.gatling.core.session.Session import io.gatling.core.session.el.ElCompiler import org.easymock.EasyMock._ -import org.scalatest.enablers.Definition import scala.collection.JavaConverters._ @@ -21,8 +20,6 @@ class DseCqlStatementSpec extends BaseSpec { val prepared = mock[PreparedStatement] val mockColDefinitions = mock[ColumnDefinitions] - val mockDefinitions = mock[Definition] - val mockDefinitionId = mock[Definition] val mockBoundStatement = mock[BoundStatement] val mockCqlTypes = mock[CqlPreparedStatementUtil] @@ -47,7 +44,7 @@ class DseCqlStatementSpec extends BaseSpec { it("should succeed with a passed SimpleStatement", CqlTest) { - val stmt = new SimpleStatement("select * from keyspace.table where id = 5") + val stmt = SimpleStatement.newInstance("select * from keyspace.table where id = 5") val result = DseCqlSimpleStatement(stmt).buildFromSession(validGatlingSession) result shouldBe a[Success[_]] @@ -78,7 +75,7 @@ class DseCqlStatementSpec extends BaseSpec { it("should fail if the expression is wrong and return the 1st error") { expecting { - prepared.getVariables.andStubReturn(mockColDefinitions) + prepared.getVariableDefinitions.andStubReturn(mockColDefinitions) } whenExecuting(prepared, mockCqlTypes, mockBoundStatement) { @@ -94,16 +91,16 @@ class DseCqlStatementSpec extends BaseSpec { describe("DseCqlBoundStatementWithParamList") { val validParamList = Seq("foo", "bar") - val paramsList = List[Integer](DataType.VARCHAR, DataType.INT) + val paramsList = List[Int](DataType.VARCHAR, DataType.INT) it("correctly bind values to a prepared statement") { expecting { prepared.bind().andReturn(mockBoundStatement) mockCqlTypes.getParamsList(prepared).andReturn(paramsList) - mockCqlTypes.bindParamByOrder(validGatlingSession, mockBoundStatement, DataType.TEXT, "foo", 0) + mockCqlTypes.bindParamByOrder(validGatlingSession, mockBoundStatement, DataType.VARCHAR, "foo", 0) .andReturn(mockBoundStatement) - mockCqlTypes.bindParamByOrder(validGatlingSession, mockBoundStatement, DataType.Name.INT, "bar", 1) + mockCqlTypes.bindParamByOrder(validGatlingSession, mockBoundStatement, DataType.INT, "bar", 1) .andReturn(mockBoundStatement) } @@ -123,7 +120,7 @@ class DseCqlStatementSpec extends BaseSpec { expecting { prepared.bind().andReturn(mockBoundStatement) mockCqlTypes.getParamsMap(prepared).andReturn(Map(fooKey -> DataType.INT)) - mockCqlTypes.bindParamByName(validGatlingSession, mockBoundStatement, DataType.Name.INT, "foo") + mockCqlTypes.bindParamByName(validGatlingSession, mockBoundStatement, DataType.INT, "foo") .andReturn(mockBoundStatement) } @@ -143,7 +140,7 @@ class DseCqlStatementSpec extends BaseSpec { expecting { prepared.bind().andReturn(mockBoundStatement) mockCqlTypes.getParamsMap(prepared).andReturn(Map(fooKey -> DataType.INT)) - mockCqlTypes.bindParamByName(sessionWithStatement, mockBoundStatement, DataType.Name.INT, "foo") + mockCqlTypes.bindParamByName(sessionWithStatement, mockBoundStatement, DataType.INT, "foo") .andReturn(mockBoundStatement) } whenExecuting(prepared, mockCqlTypes, mockBoundStatement) { @@ -173,11 +170,11 @@ class DseCqlStatementSpec extends BaseSpec { it("correctly bind values to a prepared statement") { expecting { - mockBoundStatement.getOutgoingPayload.andReturn(Map("test" -> ByteBuffer.wrap(Array(12.toByte))).asJava) - mockBoundStatement.getOutgoingPayload.andReturn(Map("test" -> ByteBuffer.wrap(Array(12.toByte))).asJava) + mockBoundStatement.getCustomPayload.andReturn(Map("test" -> ByteBuffer.wrap(Array(12.toByte))).asJava) + mockBoundStatement.getCustomPayload.andReturn(Map("test" -> ByteBuffer.wrap(Array(12.toByte))).asJava) prepared.bind().andReturn(mockBoundStatement) - mockCqlTypes.getParamsMap(prepared).andReturn(Map(fooKey -> DataType.Name.INT)) - mockCqlTypes.bindParamByName(validGatlingSession, mockBoundStatement, DataType.Name.INT, "foo") + mockCqlTypes.getParamsMap(prepared).andReturn(Map(fooKey -> DataType.INT)) + mockCqlTypes.bindParamByName(validGatlingSession, mockBoundStatement, DataType.INT, "foo") .andReturn(mockBoundStatement) } @@ -191,7 +188,7 @@ class DseCqlStatementSpec extends BaseSpec { describe("DseCqlCustomPayloadStatement") { - val stmt = new SimpleStatement("select * from keyspace.table where id = 5") + val stmt = SimpleStatement.newInstance("select * from keyspace.table where id = 5") it("should succeed with a passed SimpleStatement", CqlTest) { diff --git a/src/test/scala/com/datastax/gatling/plugin/DseGraphStatementSpec.scala b/src/test/scala/com/datastax/gatling/plugin/DseGraphStatementSpec.scala index 69c6bd1..1f7ceb0 100644 --- a/src/test/scala/com/datastax/gatling/plugin/DseGraphStatementSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/DseGraphStatementSpec.scala @@ -1,8 +1,7 @@ package com.datastax.gatling.plugin -import com.datastax.driver.dse.DseSession -import com.datastax.driver.dse.graph.SimpleGraphStatement -import com.datastax.dse.graph.api.DseGraph +import com.datastax.dse.driver.api.core.DseSession +import com.datastax.dse.driver.api.core.graph.{DseGraph, FluentGraphStatement, ScriptGraphStatement} import com.datastax.gatling.plugin.base.BaseSpec import com.datastax.gatling.plugin.model.{GraphBoundStatement, GraphFluentStatement, GraphStringStatement} import io.gatling.commons.validation.{Failure, Success} @@ -42,8 +41,8 @@ class DseGraphStatementSpec extends BaseSpec { describe("FluentStatement") { - val g = DseGraph.traversal(mockDseSession) - val gStatement = DseGraph.statementFromTraversal(g.V().limit(5)) + val g = DseGraph.g + val gStatement = FluentGraphStatement.newInstance(g.V().limit(5)) val target = GraphFluentStatement(gStatement) it("should correctly return StringStatement for a valid expression") { @@ -54,8 +53,8 @@ class DseGraphStatementSpec extends BaseSpec { describe("GraphBoundStatement") { - val graphStatement = new SimpleGraphStatement("g.addV(label, vertexLabel).property('type', myType)") - val target = GraphBoundStatement(graphStatement, Map("test" -> "type")) + val target = GraphBoundStatement(ScriptGraphStatement.newInstance( + "g.addV(label, vertexLabel).property('type', myType)"), Map("test" -> "type")) it("should suceeed with a valid session") { val result = target.buildFromSession(validGatlingSession) diff --git a/src/test/scala/com/datastax/gatling/plugin/base/BaseCassandraServerSpec.scala b/src/test/scala/com/datastax/gatling/plugin/base/BaseCassandraServerSpec.scala index aee98db..f696720 100644 --- a/src/test/scala/com/datastax/gatling/plugin/base/BaseCassandraServerSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/base/BaseCassandraServerSpec.scala @@ -2,7 +2,7 @@ package com.datastax.gatling.plugin.base import java.nio.file.Files -import com.datastax.driver.dse.DseSession +import com.datastax.dse.driver.api.core.DseSession import org.cassandraunit.utils.EmbeddedCassandraServerHelper /** diff --git a/src/test/scala/com/datastax/gatling/plugin/base/GatlingDseSession.scala b/src/test/scala/com/datastax/gatling/plugin/base/GatlingDseSession.scala index 8af4d84..880eb24 100644 --- a/src/test/scala/com/datastax/gatling/plugin/base/GatlingDseSession.scala +++ b/src/test/scala/com/datastax/gatling/plugin/base/GatlingDseSession.scala @@ -1,12 +1,12 @@ package com.datastax.gatling.plugin.base -import com.datastax.driver.dse.{DseCluster, DseSession} +import java.net.InetSocketAddress + +import com.datastax.dse.driver.api.core.DseSession import org.cassandraunit.utils.EmbeddedCassandraServerHelper trait GatlingDseSession { - private var dseCluster: DseCluster = _ - private var session: DseSession = _ /** @@ -29,15 +29,14 @@ trait GatlingDseSession { cPort = EmbeddedCassandraServerHelper.getNativeTransportPort } - dseCluster = + session = try { - DseCluster.builder().addContactPoint(cassandraHost).withPort(cPort).build() + DseSession.builder().addContactPoint(new InetSocketAddress(cassandraHost, cPort)).build() } catch { - case _: Exception => DseCluster.builder().addContactPoint(cassandraHost).withPort(cPort).build() + case _: Exception => DseSession.builder().addContactPoint(new InetSocketAddress(cassandraHost, cPort)).build() } - session = dseCluster.connect() session } diff --git a/src/test/scala/com/datastax/gatling/plugin/model/CqlStatementBuildersSpec.scala b/src/test/scala/com/datastax/gatling/plugin/model/CqlStatementBuildersSpec.scala index de40a8f..7fef245 100644 --- a/src/test/scala/com/datastax/gatling/plugin/model/CqlStatementBuildersSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/model/CqlStatementBuildersSpec.scala @@ -1,10 +1,11 @@ package com.datastax.gatling.plugin.model -import com.datastax.driver.core.ConsistencyLevel.{EACH_QUORUM, THREE} -import com.datastax.driver.core._ -import com.datastax.driver.core.policies.FallthroughRetryPolicy +import java.nio.ByteBuffer + import com.datastax.gatling.plugin.DsePredef._ -import com.datastax.gatling.plugin.checks.{CqlChecks, DseCqlCheck, GenericCheck, GenericChecks} +import com.datastax.gatling.plugin.checks.{CqlChecks, CqlGenericChecks, DseCqlCheck, GenericCheck} +import com.datastax.oss.driver.api.core.cql.{Row, SimpleStatement} +import com.datastax.oss.protocol.internal.ProtocolConstants.ConsistencyLevel import io.gatling.core.Predef._ import io.gatling.core.session.{ExpressionSuccessWrapper, Session} import org.scalatest.easymock.EasyMockSugar @@ -15,7 +16,7 @@ class CqlStatementBuildersSpec extends FlatSpec with Matchers with EasyMockSugar it should "build statements from a CQL String" in { - val statementAttributes: DseCqlAttributes = cql("the-tag") + val statementAttributes: DseCqlAttributes[SimpleStatement] = cql("the-tag") .executeCql("SELECT foo FROM bar.baz LIMIT 1") .build() .dseAttributes @@ -23,22 +24,21 @@ class CqlStatementBuildersSpec extends FlatSpec with Matchers with EasyMockSugar .buildFromSession(Session("the-tag", 42)) .get.asInstanceOf[SimpleStatement] statementAttributes.cqlStatements should contain only "SELECT foo FROM bar.baz LIMIT 1" - statement.getQueryString() should be("SELECT foo FROM bar.baz LIMIT 1") + statement.getQuery() should be("SELECT foo FROM bar.baz LIMIT 1") } it should "forward all attributs to DseCqlAttributes" in { - val pagingState = mock[PagingState] - val genericCheck = GenericCheck(GenericChecks.exhausted.is(true)) + val pagingState = mock[ByteBuffer] + val genericCheck = GenericCheck(CqlGenericChecks.exhausted.is(true)) val cqlCheck = DseCqlCheck(CqlChecks.oneRow.is(mock[Row].expressionSuccess)) - val statementAttributes: DseCqlAttributes = cql("the-session-tag") + val statementAttributes: DseCqlAttributes[SimpleStatement] = cql("the-session-tag") .executeCql("FOO") - .withConsistencyLevel(EACH_QUORUM) + .withConsistencyLevel(ConsistencyLevel.EACH_QUORUM) .withUserOrRole("User or role") .withDefaultTimestamp(-76) .withIdempotency() .withReadTimeout(99) - .withSerialConsistencyLevel(THREE) - .withRetryPolicy(FallthroughRetryPolicy.INSTANCE) + .withSerialConsistencyLevel(ConsistencyLevel.THREE) .withFetchSize(3) .withTracingEnabled() .withPagingState(pagingState) @@ -47,7 +47,7 @@ class CqlStatementBuildersSpec extends FlatSpec with Matchers with EasyMockSugar .build() .dseAttributes statementAttributes.tag should be("the-session-tag") - statementAttributes.cl should be(Some(EACH_QUORUM)) + statementAttributes.cl should be(Some(ConsistencyLevel.EACH_QUORUM)) statementAttributes.cqlChecks should contain only cqlCheck statementAttributes.genericChecks should contain only genericCheck statementAttributes.userOrRole should be(Some("User or role")) @@ -55,23 +55,22 @@ class CqlStatementBuildersSpec extends FlatSpec with Matchers with EasyMockSugar statementAttributes.idempotent should be(Some(true)) statementAttributes.defaultTimestamp should be(Some(-76)) statementAttributes.enableTrace should be(Some(true)) - statementAttributes.serialCl should be(Some(THREE)) + statementAttributes.serialCl should be(Some(ConsistencyLevel.THREE)) statementAttributes.fetchSize should be(Some(3)) - statementAttributes.retryPolicy should be(Some(FallthroughRetryPolicy.INSTANCE)) statementAttributes.pagingState should be(Some(pagingState)) statementAttributes.cqlStatements should contain only "FOO" } it should "build statements from a SimpleStatement" in { - val statementAttributes: DseCqlAttributes = cql("the-tag") - .executeStatement(new SimpleStatement("Some CQL")) + val statementAttributes: DseCqlAttributes[SimpleStatement] = cql("the-tag") + .executeStatement(SimpleStatement.newInstance("Some CQL")) .build() .dseAttributes val statement: SimpleStatement = statementAttributes.statement .buildFromSession(Session("the-tag", 42)) .get.asInstanceOf[SimpleStatement] statementAttributes.cqlStatements should contain only "Some CQL" - statement.getQueryString() should be("Some CQL") + statement.getQuery() should be("Some CQL") } // it should "build statements from a PreparedStatement" in { diff --git a/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala b/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala index b6f7608..b6f76e4 100644 --- a/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala @@ -8,9 +8,6 @@ import akka.testkit.TestKitBase import ch.qos.logback.classic.{Level, Logger} import ch.qos.logback.classic.spi.ILoggingEvent import ch.qos.logback.core.read.ListAppender -import com.datastax.driver.core._ -import com.datastax.driver.core.policies.FallthroughRetryPolicy -import com.datastax.driver.dse.DseSession import com.datastax.dse.driver.api.core.DseSession import com.datastax.gatling.plugin.base.BaseSpec import com.datastax.gatling.plugin.metrics.NoopMetricsLogger @@ -20,7 +17,6 @@ import com.datastax.gatling.plugin.model.{DseCqlAttributes, DseCqlStatement} import com.datastax.oss.driver.api.core.cql.{ResultSet, SimpleStatement, Statement} import com.datastax.oss.protocol.internal.ProtocolConstants.ConsistencyLevel import com.google.common.util.concurrent.{Futures, ListenableFuture} -import io.gatling.commons.validation.SuccessWrapper import io.gatling.core.action.Exit import io.gatling.core.config.GatlingConfiguration import io.gatling.core.session.Session @@ -33,12 +29,12 @@ class CqlRequestActionSpec extends BaseSpec with TestKitBase { implicit lazy val system:ActorSystem = ActorSystem() val gatlingTestConfig: GatlingConfiguration = GatlingConfiguration.loadForTest() val dseSession: DseSession = mock[DseSession] - val dseCqlStatement: DseCqlStatement = mock[DseCqlStatement] + val dseCqlStatement: DseCqlStatement[SimpleStatement] = mock[DseCqlStatement[SimpleStatement]] val pagingState: ByteBuffer = mock[ByteBuffer] val statsEngine: StatsEngine = mock[StatsEngine] val gatlingSession = Session("scenario", 1) - def getTarget(dseAttributes: DseCqlAttributes): CqlRequestAction = { + def getTarget(dseAttributes: DseCqlAttributes[SimpleStatement]): CqlRequestAction = { new CqlRequestAction( "sample-dse-request", new Exit(system.actorOf(Props[DseRequestActor]), statsEngine), diff --git a/src/test/scala/com/datastax/gatling/plugin/request/GraphRequestActionSpec.scala b/src/test/scala/com/datastax/gatling/plugin/request/GraphRequestActionSpec.scala index 2c61336..d5d6764 100644 --- a/src/test/scala/com/datastax/gatling/plugin/request/GraphRequestActionSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/request/GraphRequestActionSpec.scala @@ -1,17 +1,19 @@ package com.datastax.gatling.plugin.request +import java.nio.ByteBuffer import java.util.concurrent.{Executor, TimeUnit} import akka.actor.{ActorSystem, Props} import akka.testkit.TestKitBase -import com.datastax.driver.core._ -import com.datastax.driver.dse.DseSession -import com.datastax.driver.dse.graph.{GraphResultSet, RegularGraphStatement, SimpleGraphStatement} +import com.datastax.dse.driver.api.core.DseSession +import com.datastax.dse.driver.api.core.graph.{GraphResultSet, GraphStatement, ScriptGraphStatement} import com.datastax.gatling.plugin.base.BaseSpec import com.datastax.gatling.plugin.metrics.NoopMetricsLogger import com.datastax.gatling.plugin.utils.GatlingTimingSource import com.datastax.gatling.plugin.DseProtocol -import com.datastax.gatling.plugin.model.{DseGraphStatement, DseGraphAttributes} +import com.datastax.gatling.plugin.model.{DseGraphAttributes, DseGraphStatement, GraphFluentStatementFromScalaLambda, GraphStringStatement} +import com.datastax.oss.driver.api.core.cql.ResultSet +import com.datastax.oss.protocol.internal.ProtocolConstants.ConsistencyLevel import com.google.common.util.concurrent.{Futures, ListenableFuture} import io.gatling.commons.validation.SuccessWrapper import io.gatling.core.action.Exit @@ -25,12 +27,12 @@ class GraphRequestActionSpec extends BaseSpec with TestKitBase { implicit lazy val system = ActorSystem() val gatlingTestConfig = GatlingConfiguration.loadForTest() val dseSession = mock[DseSession] - val dseGraphStatement = mock[DseGraphStatement] - val pagingState = mock[PagingState] + val dseGraphStatement = mock[GraphStatement[GraphStringStatement]] + val pagingState = mock[ByteBuffer] val statsEngine: StatsEngine = mock[StatsEngine] val gatlingSession = Session("scenario", 1) - def getTarget(dseAttributes: DseGraphAttributes): GraphRequestAction = { + def getTarget(dseAttributes: DseGraphAttributes[ScriptGraphStatement]): GraphRequestAction = { new GraphRequestAction( "sample-dse-request", new Exit(system.actorOf(Props[DseRequestActor]), statsEngine), @@ -64,7 +66,7 @@ class GraphRequestActionSpec extends BaseSpec with TestKitBase { } describe("Graph") { - val statementCapture = EasyMock.newCapture[RegularGraphStatement] + val statementCapture = EasyMock.newCapture[GraphStatement[GraphStringStatement]] it("should enable all the Graph Attributes in DseAttributes") { val graphAttributes = DseGraphAttributes("test", dseGraphStatement, cl = Some(ConsistencyLevel.ANY), @@ -82,7 +84,7 @@ class GraphRequestActionSpec extends BaseSpec with TestKitBase { ) expecting { - dseGraphStatement.buildFromSession(gatlingSession).andReturn(new SimpleGraphStatement("g.V()").success) + dseGraphStatement.buildFromSession(gatlingSession).andReturn(new GraphStringStatement("g.V()").success) dseSession.executeGraphAsync(capture(statementCapture)) andReturn Futures.immediateFuture(mock[GraphResultSet]) } @@ -91,7 +93,7 @@ class GraphRequestActionSpec extends BaseSpec with TestKitBase { } val capturedStatement = statementCapture.getValue - capturedStatement shouldBe a[SimpleGraphStatement] + capturedStatement shouldBe a[GraphStringStatement] capturedStatement.getConsistencyLevel shouldBe ConsistencyLevel.ANY capturedStatement.getDefaultTimestamp shouldBe 1498167845000L capturedStatement.getReadTimeoutMillis shouldBe 12 diff --git a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/BatchStatementSimulation.scala b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/BatchStatementSimulation.scala index e4a7bb9..e356a43 100644 --- a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/BatchStatementSimulation.scala +++ b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/BatchStatementSimulation.scala @@ -1,8 +1,8 @@ package com.datastax.gatling.plugin.simulations.cql -import com.datastax.driver.core.ResultSet -import com.datastax.gatling.plugin.DsePredef._ +import com.datastax.gatling.plugin.CqlPredef._ import com.datastax.gatling.plugin.base.BaseCqlSimulation +import com.datastax.oss.driver.api.core.cql.ResultSet import io.gatling.core.Predef._ import scala.concurrent.duration.DurationInt @@ -17,12 +17,12 @@ class BatchStatementSimulation extends BaseCqlSimulation { val cqlConfig = cql.session(session) //Initialize Gatling DSL with your session - val addressType = session.getCluster.getMetadata.getKeyspace(testKeyspace).getUserType("fullname") + val addressType = session.getMetadata.getKeyspace(testKeyspace).get().getUserDefinedType("fullname") val simpleId = 1 val preparedId = 2 val namedId = 3 - val insertFullName = addressType.newValue() + val insertFullName = addressType.get().newValue() .setString("firstname", "John") .setString("lastname", "Smith") @@ -44,6 +44,7 @@ class BatchStatementSimulation extends BaseCqlSimulation { .exec(insertPreparedCql .check(exhausted is true) .check(rowCount is 0) // "normal" INSERTs don't return anything + .build() ) setUp( diff --git a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/BoundCqlTypesSimulation.scala b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/BoundCqlTypesSimulation.scala index 89dcf8a..2a43322 100644 --- a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/BoundCqlTypesSimulation.scala +++ b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/BoundCqlTypesSimulation.scala @@ -3,10 +3,11 @@ package com.datastax.gatling.plugin.simulations.cql import java.nio.ByteBuffer import java.sql.Timestamp -import com.datastax.driver.core.utils.UUIDs -import com.datastax.driver.core.{DataType, ResultSet} -import com.datastax.gatling.plugin.DsePredef._ +import com.datastax.gatling.plugin.CqlPredef._ import com.datastax.gatling.plugin.base.BaseCqlSimulation +import com.datastax.oss.driver.api.core.`type`.{DataType, DataTypes, TupleType} +import com.datastax.oss.driver.api.core.cql.ResultSet +import com.datastax.oss.driver.api.core.uuid.Uuids import io.gatling.core.Predef._ import scala.concurrent.duration.DurationInt @@ -20,16 +21,16 @@ class BoundCqlTypesSimulation extends BaseCqlSimulation { createTable val cqlConfig = cql.session(session) - val udtType = session.getCluster.getMetadata.getKeyspace(testKeyspace).getUserType("fullname") + val udtType = session.getMetadata.getKeyspace(testKeyspace).get().getUserDefinedType("fullname") - val insertFullName = udtType.newValue() + val insertFullName = udtType.get().newValue() .setString("firstname", "John") .setString("lastname", "Smith") - val tupleType = session.getCluster.getMetadata.newTupleType(DataType.text(), DataType.text()) + val tupleType = DataTypes.tupleOf(DataTypes.TEXT, DataTypes.TEXT) val insertTuple = tupleType.newValue("one", "two") - val uuid = UUIDs.random() + val uuid = Uuids.random() val preparedStatementInsert = s"""INSERT INTO $testKeyspace.$table_name ( @@ -58,7 +59,7 @@ class BoundCqlTypesSimulation extends BaseCqlSimulation { val preparedFeed = Iterator.continually( Map( "uuid_type" -> uuid, - "timeuuid_type" -> UUIDs.timeBased(), + "timeuuid_type" -> Uuids.timeBased(), "int_type" -> 1, "text_type" -> "text", "float_type" -> 4.50, @@ -117,6 +118,7 @@ class BoundCqlTypesSimulation extends BaseCqlSimulation { .exec(insertPreparedCql .check(exhausted is true) .check(rowCount is 0) // "normal" INSERTs don't return anything + .build() ) .pause(100.millis) @@ -127,6 +129,7 @@ class BoundCqlTypesSimulation extends BaseCqlSimulation { .check(columnValue("name") not "") .check(columnValue("null_type") not "test") .check(columnValue("boolean_type") is true) + .build() ) .pause(100.millis) @@ -134,6 +137,7 @@ class BoundCqlTypesSimulation extends BaseCqlSimulation { .exec(insertCounterPreparedCql .check(exhausted is true) .check(rowCount is 0) // "normal" INSERTs don't return anything + .build() ) .pause(100.millis) @@ -141,6 +145,7 @@ class BoundCqlTypesSimulation extends BaseCqlSimulation { .withParams(List("uuid_type")) .check(rowCount is 1) .check(columnValue("counter_type") is 2) + .build() ) .pause(100.millis) diff --git a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/NamedStatementSimulation.scala b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/NamedStatementSimulation.scala index cf88192..4dd6c06 100644 --- a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/NamedStatementSimulation.scala +++ b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/NamedStatementSimulation.scala @@ -1,6 +1,6 @@ package com.datastax.gatling.plugin.simulations.cql -import com.datastax.gatling.plugin.DsePredef._ +import com.datastax.gatling.plugin.CqlPredef._ import com.datastax.gatling.plugin.base.BaseCqlSimulation import io.gatling.core.Predef._ @@ -44,12 +44,14 @@ class NamedStatementSimulation extends BaseCqlSimulation { .exec(insertCql .check(exhausted is true) .check(rowCount is 0) // "normal" INSERTs don't return anything + .build() ) .pause(1.seconds) .exec(selectCql .check(rowCount is 1) .check(columnValue("str") is insertStr) + .build() ) diff --git a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/PreparedStatementSimulation.scala b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/PreparedStatementSimulation.scala index f634abd..18677e1 100644 --- a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/PreparedStatementSimulation.scala +++ b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/PreparedStatementSimulation.scala @@ -1,6 +1,6 @@ package com.datastax.gatling.plugin.simulations.cql -import com.datastax.gatling.plugin.DsePredef._ +import com.datastax.gatling.plugin.CqlPredef._ import com.datastax.gatling.plugin.base.BaseCqlSimulation import io.gatling.core.Predef._ @@ -51,20 +51,19 @@ class PreparedStatementSimulation extends BaseCqlSimulation { val scnPassed = scenario("ABCPreparedStatement") .feed(feeder) .exec(insertCql - .check(exhausted is true) - .check(rowCount is 0) // "normal" INSERTs don't return anything - ) + .check(rowCount is 0) + .build()) .pause(1.seconds) .exec(selectCql .check(rowCount is 1) - .check(columnValue("name") is insertName) + .check(columnValue("name") is insertName).build() ) .pause(1.seconds) .exec(selectCqlSessionParam .check(rowCount is 1) - .check(columnValue("name") is insertName) + .check(columnValue("name") is insertName).build() ) diff --git a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/SimpleStatementSimulation.scala b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/SimpleStatementSimulation.scala index a314aad..1947f76 100644 --- a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/SimpleStatementSimulation.scala +++ b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/SimpleStatementSimulation.scala @@ -1,6 +1,6 @@ package com.datastax.gatling.plugin.simulations.cql -import com.datastax.gatling.plugin.DsePredef._ +import com.datastax.gatling.plugin.CqlPredef._ import com.datastax.gatling.plugin.base.BaseCqlSimulation import io.gatling.core.Predef._ diff --git a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/UdtStatementSimulation.scala b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/UdtStatementSimulation.scala index 1406973..e8ebc93 100644 --- a/src/test/scala/com/datastax/gatling/plugin/simulations/cql/UdtStatementSimulation.scala +++ b/src/test/scala/com/datastax/gatling/plugin/simulations/cql/UdtStatementSimulation.scala @@ -1,8 +1,8 @@ package com.datastax.gatling.plugin.simulations.cql -import com.datastax.driver.core.ResultSet -import com.datastax.gatling.plugin.DsePredef._ +import com.datastax.gatling.plugin.CqlPredef._ import com.datastax.gatling.plugin.base.BaseCqlSimulation +import com.datastax.oss.driver.api.core.cql.ResultSet import io.gatling.core.Predef._ import scala.concurrent.duration.DurationInt @@ -17,12 +17,12 @@ class UdtStatementSimulation extends BaseCqlSimulation { val cqlConfig = cql.session(session) //Initialize Gatling DSL with your session - val addressType = session.getCluster.getMetadata.getKeyspace(testKeyspace).getUserType("fullname") + val addressType = session.getMetadata.getKeyspace(testKeyspace).get.getUserDefinedType("fullname") val simpleId = 1 val preparedId = 2 val namedId = 3 - val insertFullName = addressType.newValue() + val insertFullName = addressType.get().newValue() .setString("firstname", "John") .setString("lastname", "Smith") @@ -92,6 +92,7 @@ class UdtStatementSimulation extends BaseCqlSimulation { .withParams(List("id", "fullname")) .check(exhausted is true) .check(rowCount is 0) // "normal" INSERTs don't return anything + .build() ) .pause(100.millis) @@ -99,6 +100,7 @@ class UdtStatementSimulation extends BaseCqlSimulation { .withParams(List("id")) .check(rowCount is 1) .check(columnValue("name").find(0) not "") + .build() ) .pause(100.millis) @@ -106,12 +108,14 @@ class UdtStatementSimulation extends BaseCqlSimulation { .exec(insertNamedCql .check(exhausted is true) .check(rowCount is 0) // "normal" INSERTs don't return anything + .build() ) .pause(100.millis) .exec(selectNamedCql .check(rowCount is 1) .check(columnValue("name").find(0) not "") + .build() ) setUp( diff --git a/src/test/scala/com/datastax/gatling/plugin/simulations/graph/GraphStatementSimulation.scala b/src/test/scala/com/datastax/gatling/plugin/simulations/graph/GraphStatementSimulation.scala index 8f2fce2..c1dbe3d 100644 --- a/src/test/scala/com/datastax/gatling/plugin/simulations/graph/GraphStatementSimulation.scala +++ b/src/test/scala/com/datastax/gatling/plugin/simulations/graph/GraphStatementSimulation.scala @@ -1,13 +1,14 @@ package com.datastax.gatling.plugin.simulations.graph -import com.datastax.driver.core.ConsistencyLevel -import com.datastax.driver.dse.graph.{GraphStatement, SimpleGraphStatement} +import com.datastax.dse.driver.api.core.graph.{GraphSession, GraphStatement} import com.datastax.dse.graph.api.DseGraph -import com.datastax.gatling.plugin.DsePredef._ +import com.datastax.gatling.plugin.GraphPredef._ import com.datastax.gatling.plugin.base.BaseGraphSimulation +import com.datastax.gatling.plugin.model.GraphStringStatement import io.gatling.core.Predef._ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal import org.scalatest.Ignore +import com.datastax.oss.protocol.internal.ProtocolConstants._ import scala.concurrent.duration.DurationInt @@ -16,13 +17,13 @@ class GraphStatementSimulation extends BaseGraphSimulation { val table_name = "test_table" - session.getCluster.getConfiguration.getGraphOptions.setGraphName("demo") + session.getConfiguration.getGraphOptions.setGraphName("demo") val graphConfig = graph.session(session) //Initialize Gatling DSL with your session val r = scala.util.Random - val graphStatement = new SimpleGraphStatement("g.addV(label, vertexLabel).property('type', myType)") + val graphStatement = new GraphStringStatement("g.addV(label, vertexLabel).property('type', myType)") def getInt: String = { "test_" + r.nextInt(100).toString @@ -36,9 +37,9 @@ class GraphStatementSimulation extends BaseGraphSimulation { val queryGraph = graph("Graph Query") .executeGraph("g.V().limit(5)") - val g = DseGraph.traversal(session) + val g = DseGraph.traversal((GraphSession) session) val t: GraphTraversal[_,_] = g.V().limit(5) - val st: GraphStatement = DseGraph.statementFromTraversal(t) + val st: GraphStatement[String] = DseGraph.statementFromTraversal(t) val queryGraphNative = graph("Graph Fluent") .executeGraphFluent(st) diff --git a/src/test/scala/com/datastax/gatling/plugin/utils/CqlPreparedStatementUtilSpec.scala b/src/test/scala/com/datastax/gatling/plugin/utils/CqlPreparedStatementUtilSpec.scala index d373c2c..e6dc32e 100644 --- a/src/test/scala/com/datastax/gatling/plugin/utils/CqlPreparedStatementUtilSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/utils/CqlPreparedStatementUtilSpec.scala @@ -3,12 +3,15 @@ package com.datastax.gatling.plugin.utils import java.math.BigInteger import java.net.InetAddress import java.nio.ByteBuffer +import java.time.LocalDate -import com.datastax.driver.core.utils.UUIDs -import com.datastax.driver.core.{DataType, _} -import com.datastax.driver.dse.geometry._ +import com.datastax.dse.driver.api.core.data.geometry.{LineString, Point, Polygon} import com.datastax.gatling.plugin.base.BaseCassandraServerSpec import com.datastax.gatling.plugin.exceptions.CqlTypeException +import com.datastax.oss.driver.api.core.cql.BoundStatement +import com.datastax.oss.driver.api.core.data.{TupleValue, UdtValue} +import com.datastax.oss.driver.api.core.uuid.Uuids +import com.datastax.oss.protocol.internal.ProtocolConstants.DataType import com.github.nscala_time.time.Imports.DateTime import io.gatling.core.session.Session @@ -44,7 +47,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { "inetStr" -> "127.0.0.1", "inet" -> InetAddress.getByName("127.0.0.1"), - "localDate" -> LocalDate.fromMillisSinceEpoch(1483299340813L), + "localDate" -> LocalDate.ofEpochDay(1483299340813L), "stringDate" -> "2016-10-05", "set" -> Set(1), @@ -71,9 +74,9 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { "isoDateString" -> "2008-03-01T13:00:00Z", "dateString" -> "2016-10-05", - "uuid" -> UUIDs.random(), + "uuid" -> Uuids.random(), "uuidString" -> "252a3806-b8be-42d3-929d-4cbb380a433e", - "timeUuid" -> UUIDs.timeBased(), + "timeUuid" -> Uuids.timeBased(), "byte" -> 12.toByte, "short" -> 12.toShort, @@ -88,9 +91,10 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { "null_type" -> null, - "point_type" -> new Point(1.0, 1.0), - "linestring_type" -> new LineString(new Point(1.0, 1.0), new Point(2.0, 2.0)), - "polygon_type" -> new Polygon(new Point(1.0, 1.0), new Point(2.0, 2.0), new Point(3.0, 3.0), new Point(4.0, 4.0)) + "point_type" -> Point.fromCoordinates(1.0, 1.0), + "linestring_type" -> LineString.fromPoints(Point.fromCoordinates(1.0, 1.0), Point.fromCoordinates(2.0, 2.0)), + "polygon_type" -> Polygon.fromPoints(Point.fromCoordinates(1.0, 1.0), Point.fromCoordinates(2.0, 2.0), + Point.fromCoordinates(3.0, 3.0), Point.fromCoordinates(4.0, 4.0)) ) val defaultGatlingSession: Session = gatlingSession.setAll(defaultSessionVars) @@ -108,7 +112,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val preparedStatement = dseSession.prepare(s"SELECT * FROM $keyspace.$table where id = ?") val paramList = CqlPreparedStatementUtil.getParamsList(preparedStatement) - paramList should contain(DataType.Name.INT) + paramList should contain(DataType.INT) } } @@ -120,7 +124,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val preparedStatement = dseSession.prepare(s"SELECT * FROM $keyspace.$table where id = :id") val paramsMap = CqlPreparedStatementUtil.getParamsMap(preparedStatement) - paramsMap("id") shouldBe DataType.Name.INT + paramsMap("id") shouldBe DataType.INT } } @@ -387,28 +391,28 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { describe("asDate") { it("should accept a date string") { - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "stringDate") shouldBe a[LocalDate] - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "stringDate").getDay.equals(5) + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "stringDate") shouldBe a[LocalDate] + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "stringDate").getDayOfMonth.equals(5) } it("should accept a long") { - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "long") shouldBe a[LocalDate] - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "long").getDay.equals(1) + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "long") shouldBe a[LocalDate] + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "long").getDayOfMonth.equals(1) } it("should accept an int") { - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "int") shouldBe a[LocalDate] - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "int").getDay.equals(13) + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "int") shouldBe a[LocalDate] + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "int").getDayOfMonth.equals(13) } it("should accept an native localDate") { - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "localDate") shouldBe a[LocalDate] - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "localDate").getDay.equals(1) + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "localDate") shouldBe a[LocalDate] + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "localDate").getDayOfMonth.equals(1) } it("should not accept a float and produce a CqlTypeException") { intercept[CqlTypeException] { - CqlPreparedStatementUtil.asDate(defaultGatlingSession, "float") shouldBe a[LocalDate] + CqlPreparedStatementUtil.asLocalDate(defaultGatlingSession, "float") shouldBe a[LocalDate] } } @@ -520,19 +524,19 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { describe("asTime") { it("should accept a Long") { - CqlPreparedStatementUtil.asTime(defaultGatlingSession, "long") shouldBe a[java.lang.Long] + CqlPreparedStatementUtil.asLocalTime(defaultGatlingSession, "long") shouldBe a[java.lang.Long] } describe("should accept a String") { it("should accept a String time w/o nanoseconds") { - val validHour = CqlPreparedStatementUtil.asTime(defaultGatlingSession, "hourTime") + val validHour = CqlPreparedStatementUtil.asLocalTime(defaultGatlingSession, "hourTime") validHour shouldBe a[java.lang.Long] validHour shouldBe 3661000000000L } it("should accept a String time w/ nanoseconds") { - val validNano = CqlPreparedStatementUtil.asTime(defaultGatlingSession, "nanoTime") + val validNano = CqlPreparedStatementUtil.asLocalTime(defaultGatlingSession, "nanoTime") validNano shouldBe a[java.lang.Long] validNano shouldBe 3661343000000L } @@ -541,7 +545,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val newSessionVars = Map("invalidHour" -> "43:04:32") val newSession: Session = gatlingSession.setAll(newSessionVars) intercept[CqlTypeException] { - CqlPreparedStatementUtil.asTime(newSession, "invalidHour") shouldBe a[java.lang.Long] + CqlPreparedStatementUtil.asLocalTime(newSession, "invalidHour") shouldBe a[java.lang.Long] } } @@ -549,7 +553,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val newSessionVars = Map("invalidMin" -> "01:78:32") val newSession: Session = gatlingSession.setAll(newSessionVars) intercept[CqlTypeException] { - CqlPreparedStatementUtil.asTime(newSession, "invalidMin") shouldBe a[java.lang.Long] + CqlPreparedStatementUtil.asLocalTime(newSession, "invalidMin") shouldBe a[java.lang.Long] } } @@ -557,7 +561,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val newSessionVars = Map("invalidSec" -> "01:01:78") val newSession: Session = gatlingSession.setAll(newSessionVars) intercept[CqlTypeException] { - CqlPreparedStatementUtil.asTime(newSession, "invalidSec") shouldBe a[Long] + CqlPreparedStatementUtil.asLocalTime(newSession, "invalidSec") shouldBe a[Long] } } @@ -565,7 +569,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val newSessionVars = Map("invalidNano" -> "01:01:01.11111111111") val newSession: Session = gatlingSession.setAll(newSessionVars) intercept[CqlTypeException] { - CqlPreparedStatementUtil.asTime(newSession, "invalidNano") shouldBe a[Long] + CqlPreparedStatementUtil.asLocalTime(newSession, "invalidNano") shouldBe a[Long] } } @@ -573,7 +577,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { it("should not accept a float and produce a CqlTypeException") { intercept[CqlTypeException] { - CqlPreparedStatementUtil.asTime(defaultGatlingSession, "float") shouldBe a[Long] + CqlPreparedStatementUtil.asLocalTime(defaultGatlingSession, "float") shouldBe a[Long] } } } @@ -707,32 +711,32 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { describe("asTimestamp") { it("should accept an epoch long") { - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "epoch") shouldBe a[java.util.Date] - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "epoch") shouldBe + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "epoch") shouldBe a[java.util.Date] + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "epoch") shouldBe new java.util.Date(defaultSessionVars("epoch").asInstanceOf[Long]) } it("should accept a java Date") { - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "javaDate") shouldBe a[java.util.Date] - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "javaDate") shouldBe + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "javaDate") shouldBe a[java.util.Date] + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "javaDate") shouldBe defaultSessionVars("javaDate").asInstanceOf[java.util.Date] } it("should accept a date string") { - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "dateString") shouldBe a[java.util.Date] - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "dateString") shouldBe + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "dateString") shouldBe a[java.util.Date] + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "dateString") shouldBe DateTime.parse(defaultSessionVars("dateString").asInstanceOf[String]).toDate } it("should accept a isoDateString string") { - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "isoDateString") shouldBe a[java.util.Date] - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "isoDateString") shouldBe + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "isoDateString") shouldBe a[java.util.Date] + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "isoDateString") shouldBe DateTime.parse(defaultSessionVars("isoDateString").asInstanceOf[String]).toDate } it("should not accept a float and produce a CqlTypeException") { intercept[CqlTypeException] { - CqlPreparedStatementUtil.asTimestamp(defaultGatlingSession, "float") shouldBe a[java.util.Date] + CqlPreparedStatementUtil.asInstant(defaultGatlingSession, "float") shouldBe a[java.util.Date] } } @@ -781,12 +785,12 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val udtSession: Session = gatlingSession.setAll(newSessionVars) it("should accept a UDTValue") { - CqlPreparedStatementUtil.asUdt(udtSession, "fullname") shouldBe a[UDTValue] + CqlPreparedStatementUtil.asUdt(udtSession, "fullname") shouldBe a[UdtValue] } it("should not accept a float and produce a CqlTypeException") { intercept[CqlTypeException] { - CqlPreparedStatementUtil.asUdt(udtSession, "invalid") shouldBe a[UDTValue] + CqlPreparedStatementUtil.asUdt(udtSession, "invalid") shouldBe a[UdtValue] } } @@ -797,7 +801,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val table = "tuple_test" createTable(keyspace, table, "id int, tuple_type tuple, PRIMARY KEY (id)") - val tupleType = dseSession.getCluster.getMetadata.newTupleType(DataType.varchar(), DataType.varchar()) + val tupleType = dseSession.getMetadata.newTupleType(DataType.VARCHAR, DataType.VARCHAR) val insertTuple = tupleType.newValue("test", "test2") val newSessionVars = Map("tuple_type" -> insertTuple, "invalid" -> "string") val tupleSession: Session = gatlingSession.setAll(newSessionVars) @@ -871,145 +875,145 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val boundStatementKeys = dseSession.prepare(preparedStatementInsert).bind() it("should bind with a UUID") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.UUID, "uuid", 0) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.UUID, "uuid", 0) result shouldBe a[BoundStatement] result.isSet(0) shouldBe true } it("should bind with a timeUuid") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.TIMEUUID, "timeUuid", 1) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.TIMEUUID, "timeUuid", 1) result shouldBe a[BoundStatement] result.isSet(1) shouldBe true } it("should bind with a int") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.INT, "int", 2) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.INT, "int", 2) result shouldBe a[BoundStatement] result.isSet(2) shouldBe true } it("should bind with a text") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.TEXT, "string", 3) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.VARCHAR, "string", 3) result shouldBe a[BoundStatement] result.isSet(3) shouldBe true } it("should bind with a varchar") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.VARCHAR, "string", 4) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.VARCHAR, "string", 4) result shouldBe a[BoundStatement] result.isSet(4) shouldBe true } it("should bind with a ascii") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.ASCII, "string", 5) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.ASCII, "string", 5) result shouldBe a[BoundStatement] result.isSet(5) shouldBe true } it("should bind with a float") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.FLOAT, "float", 6) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.FLOAT, "float", 6) result shouldBe a[BoundStatement] result.isSet(6) shouldBe true } it("should bind with a double") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.DOUBLE, "double", 7) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.DOUBLE, "double", 7) result shouldBe a[BoundStatement] result.isSet(7) shouldBe true } it("should bind with a decimal") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.DECIMAL, "double", 8) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.DECIMAL, "double", 8) result shouldBe a[BoundStatement] result.isSet(8) shouldBe true } it("should bind with a boolean") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.BOOLEAN, "boolean", 9) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.BOOLEAN, "boolean", 9) result shouldBe a[BoundStatement] result.isSet(9) shouldBe true } it("should bind with a inetAddress") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.INET, "inetStr", 10) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.INET, "inetStr", 10) result shouldBe a[BoundStatement] result.isSet(10) shouldBe true } it("should bind with a timestamp") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.TIMESTAMP, "epoch", 11) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.TIMESTAMP, "epoch", 11) result shouldBe a[BoundStatement] result.isSet(11) shouldBe true } it("should bind with a bigInt") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.BIGINT, "bigInteger", 12) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.BIGINT, "bigInteger", 12) result shouldBe a[BoundStatement] result.isSet(12) shouldBe true } it("should bind with a blob_type") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.BLOB, "byteArray", 13) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.BLOB, "byteArray", 13) result shouldBe a[BoundStatement] result.isSet(13) shouldBe true } it("should bind with a varint") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.VARINT, "int", 14) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.VARINT, "int", 14) result shouldBe a[BoundStatement] result.isSet(14) shouldBe true } it("should bind with a list") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.LIST, "list", 15) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.LIST, "list", 15) result shouldBe a[BoundStatement] result.isSet(15) shouldBe true } it("should bind with a set") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.SET, "set", 16) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.SET, "set", 16) result shouldBe a[BoundStatement] result.isSet(16) shouldBe true } it("should bind with a map") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.MAP, "map", 17) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.MAP, "map", 17) result shouldBe a[BoundStatement] result.isSet(17) shouldBe true } it("should bind with a date") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.DATE, "epoch", 18) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.DATE, "epoch", 18) result shouldBe a[BoundStatement] result.isSet(18) shouldBe true } it("should bind with a smallInt") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.SMALLINT, "int", 19) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.SMALLINT, "int", 19) result shouldBe a[BoundStatement] result.isSet(19) shouldBe true } it("should bind with a tinyint") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.TINYINT, "int", 20) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.TINYINT, "int", 20) result shouldBe a[BoundStatement] result.isSet(20) shouldBe true } it("should bind with a time") { - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.TIME, "epoch", 21) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.TIME, "epoch", 21) result shouldBe a[BoundStatement] result.isSet(21) shouldBe true } it("should bind with a tuple") { - val tupleType = dseSession.getCluster.getMetadata.newTupleType(DataType.varchar(), DataType.varchar()) + val tupleType = dseSession.getMetadata.newTupleType(DataType.VARCHAR, DataType.VARCHAR) val insertTuple = tupleType.newValue("test", "test2") val newSessionVars = Map("tuple_type" -> insertTuple, "invalid" -> "string") val tupleSession: Session = gatlingSession.setAll(newSessionVars) - val result = CqlPreparedStatementUtil.bindParamByOrder(tupleSession, boundStatementKeys, DataType.Name.TUPLE, "tuple_type", 22) + val result = CqlPreparedStatementUtil.bindParamByOrder(tupleSession, boundStatementKeys, DataType.TUPLE, "tuple_type", 22) result shouldBe a[BoundStatement] result.isSet(22) shouldBe true @@ -1025,7 +1029,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val newSessionVars = Map("fullname2" -> insertFullName, "invalid" -> "string") val udtSession: Session = gatlingSession.setAll(newSessionVars) - val result = CqlPreparedStatementUtil.bindParamByOrder(udtSession, boundStatementKeys, DataType.Name.UDT, "fullname2", 23) + val result = CqlPreparedStatementUtil.bindParamByOrder(udtSession, boundStatementKeys, DataType.UDT, "fullname2", 23) result shouldBe a[BoundStatement] result.isSet(23) shouldBe true } @@ -1038,7 +1042,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val boundStatementCounter = dseSession.prepare(preparedStatementInsertCounter).bind() - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementCounter, DataType.Name.COUNTER, "int", 0) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementCounter, DataType.COUNTER, "int", 0) result shouldBe a[BoundStatement] result.isSet(0) shouldBe true } @@ -1047,7 +1051,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { boundStatementKeys.isSet("null_type") shouldBe false - val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.TINYINT, "null_type", 24) + val result = CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.TINYINT, "null_type", 24) result shouldBe a[BoundStatement] boundStatementKeys.isSet("null_type") shouldBe true @@ -1058,17 +1062,17 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val field = "none_type" - CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.TEXT, field, 25) shouldBe a[BoundStatement] + CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.VARCHAR, field, 25) shouldBe a[BoundStatement] boundStatementKeys.isSet(field) shouldBe false val newSessionVars = Map(field -> "test") val newSession: Session = gatlingSession.setAll(newSessionVars) - CqlPreparedStatementUtil.bindParamByOrder(newSession, boundStatementKeys, DataType.Name.TEXT, field, 25) shouldBe a[BoundStatement] + CqlPreparedStatementUtil.bindParamByOrder(newSession, boundStatementKeys, DataType.VARCHAR, field, 25) shouldBe a[BoundStatement] boundStatementKeys.isSet(field) shouldBe true boundStatementKeys.getString(field) shouldBe "test" - CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.Name.TEXT, field, 25) shouldBe a[BoundStatement] + CqlPreparedStatementUtil.bindParamByOrder(defaultGatlingSession, boundStatementKeys, DataType.VARCHAR, field, 25) shouldBe a[BoundStatement] boundStatementKeys.isSet(field) shouldBe false } @@ -1078,7 +1082,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val newSessionVars = Map("missing" -> "test") val newSession: Session = gatlingSession.setAll(newSessionVars) - CqlPreparedStatementUtil.bindParamByOrder(newSession, boundStatementKeys, DataType.Name.TEXT, field, 25) shouldBe a[BoundStatement] + CqlPreparedStatementUtil.bindParamByOrder(newSession, boundStatementKeys, DataType.VARCHAR, field, 25) shouldBe a[BoundStatement] boundStatementKeys.isSet(field) shouldBe false } } @@ -1147,7 +1151,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val defaultSessionVars = Map( "uuid_type" -> java.util.UUID.randomUUID(), - "timeuuid_type" -> UUIDs.timeBased(), + "timeuuid_type" -> Uuids.timeBased(), "int_type" -> 12, "text_type" -> "string", "varchar_type" -> "string", @@ -1177,84 +1181,84 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { it("should bind with a UUID") { val paramName = "uuid_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.UUID, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.UUID, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a timeUuid") { val paramName = "timeuuid_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.TIMEUUID, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.TIMEUUID, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a int") { val paramName = "int_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.INT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.INT, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a text") { val paramName = "text_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.TEXT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.VARCHAR, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a varchar") { val paramName = "varchar_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.VARCHAR, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.VARCHAR, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a ascii") { val paramName = "ascii_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.ASCII, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.ASCII, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a float") { val paramName = "float_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.FLOAT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.FLOAT, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a double") { val paramName = "double_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.DOUBLE, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.DOUBLE, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a decimal") { val paramName = "decimal_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.DECIMAL, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.DECIMAL, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a boolean") { val paramName = "boolean_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.BOOLEAN, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.BOOLEAN, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a inetAddress") { val paramName = "inet_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.INET, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.INET, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a timestamp") { val paramName = "timestamp_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.TIMESTAMP, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.TIMESTAMP, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true @@ -1262,82 +1266,82 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { it("should bind with a bigInt") { val paramName = "bigint_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.BIGINT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.BIGINT, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a blob_type") { val paramName = "blob_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.BLOB, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.BLOB, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a varint") { val paramName = "varint_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.VARINT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.VARINT, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a list") { val paramName = "list_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.LIST, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.LIST, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a set") { val paramName = "set_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.SET, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.SET, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a map") { val paramName = "map_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.MAP, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.MAP, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a date") { val paramName = "date_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.DATE, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.DATE, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a smallInt") { val paramName = "smallint_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.SMALLINT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.SMALLINT, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a tinyint") { val paramName = "tinyint_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.TINYINT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.TINYINT, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a time") { val paramName = "time_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.TIME, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.TIME, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } it("should bind with a tuple") { val paramName = "tuple_type" - val tupleType = dseSession.getCluster.getMetadata.newTupleType(DataType.varchar(), DataType.varchar()) + val tupleType = dseSession.getMetadata.newTupleType(DataType.VARCHAR, DataType.VARCHAR) val insertTuple = tupleType.newValue("test", "test2") val newSessionVars = Map("tuple_type" -> insertTuple, "invalid" -> "string") val tupleSession: Session = gatlingSession.setAll(newSessionVars) - val result = CqlPreparedStatementUtil.bindParamByName(tupleSession, boundStatementNames, DataType.Name.TUPLE, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(tupleSession, boundStatementNames, DataType.TUPLE, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } @@ -1345,14 +1349,14 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { it("should bind with a udt") { val paramName = "udt_type" - val addressType = dseSession.getCluster.getMetadata.getKeyspace(keyspace).getUserType("fullname2") - val insertFullName = addressType.newValue() + val addressType = dseSession.getMetadata.getKeyspace(keyspace).get.getUserDefinedType("fullname2") + val insertFullName = addressType.get().newValue() .setString("firstname", "John") .setString("lastname", "Smith") val newSessionVars = Map("udt_type" -> insertFullName, "invalid" -> "string") val udtSession: Session = gatlingSession.setAll(newSessionVars) - val result = CqlPreparedStatementUtil.bindParamByName(udtSession, boundStatementNames, DataType.Name.UDT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(udtSession, boundStatementNames, DataType.UDT, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true } @@ -1365,7 +1369,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val boundNamedStatementCounter = dseSession.prepare(preparedStatementInsertCounter).bind() - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundNamedStatementCounter, DataType.Name.COUNTER, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundNamedStatementCounter, DataType.COUNTER, paramName) result shouldBe a[BoundStatement] } @@ -1374,7 +1378,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val paramName = "null_type" boundStatementNames.isSet(paramName) shouldBe false - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.TINYINT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.TINYINT, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true @@ -1385,19 +1389,19 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val paramName = "none_type" - val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.TEXT, paramName) + val result = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.VARCHAR, paramName) result shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe false val newSessionVars = Map(paramName -> "test") val newSession: Session = gatlingSession.setAll(newSessionVars) - val result2 = CqlPreparedStatementUtil.bindParamByName(newSession, boundStatementNames, DataType.Name.TEXT, paramName) + val result2 = CqlPreparedStatementUtil.bindParamByName(newSession, boundStatementNames, DataType.VARCHAR, paramName) result2 shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe true boundStatementNames.getString(paramName) shouldBe "test" - val result3 = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.Name.TEXT, paramName) + val result3 = CqlPreparedStatementUtil.bindParamByName(typeSession, boundStatementNames, DataType.VARCHAR, paramName) result3 shouldBe a[BoundStatement] boundStatementNames.isSet(paramName) shouldBe false } @@ -1408,7 +1412,7 @@ class CqlPreparedStatementUtilSpec extends BaseCassandraServerSpec { val newSessionVars = Map("missing" -> "test") val newSession: Session = gatlingSession.setAll(newSessionVars) - val result = CqlPreparedStatementUtil.bindParamByName(newSession, boundStatementNames, DataType.Name.TEXT, field) + val result = CqlPreparedStatementUtil.bindParamByName(newSession, boundStatementNames, DataType.VARCHAR, field) result shouldBe a[BoundStatement] boundStatementNames.isSet(field) shouldBe false } From 105ed1d367272fa30ad265e7fef879394bf6c983 Mon Sep 17 00:00:00 2001 From: Arthur Landim Date: Tue, 16 Jul 2019 11:26:59 -0300 Subject: [PATCH 3/3] [wip] cql test refactoring --- .../gatling/plugin/response/DseResponse.scala | 2 +- .../gatling/plugin/utils/FutureUtils.scala | 7 +--- .../plugin/request/CqlRequestActionSpec.scala | 41 +++++++++++-------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala b/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala index 5fee93d..26b8343 100644 --- a/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala +++ b/src/main/scala/com/datastax/gatling/plugin/response/DseResponse.scala @@ -39,7 +39,7 @@ abstract class DseResponse[E] { } -class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttributes) extends DseResponse[GraphExecutionInfo] with LazyLogging { +class GraphResponse(graphResultSet: GraphResultSet, dseAttributes: DseGraphAttributes[ScriptGraphStatement]) extends DseResponse[GraphExecutionInfo] with LazyLogging { private lazy val allGraphNodes: Seq[GraphNode] = collection.JavaConverters.asScalaBuffer(graphResultSet.all()) override def executionInfo(): GraphExecutionInfo = graphResultSet.getExecutionInfo() diff --git a/src/main/scala/com/datastax/gatling/plugin/utils/FutureUtils.scala b/src/main/scala/com/datastax/gatling/plugin/utils/FutureUtils.scala index a79f12f..96ce008 100644 --- a/src/main/scala/com/datastax/gatling/plugin/utils/FutureUtils.scala +++ b/src/main/scala/com/datastax/gatling/plugin/utils/FutureUtils.scala @@ -7,13 +7,10 @@ package com.datastax.gatling.plugin.utils -import java.util.concurrent.{CompletableFuture, CompletionStage} - -import com.datastax.oss.driver.shaded.guava.common.util.concurrent.{FutureCallback, Futures} -import org.asynchttpclient.ListenableFuture +import java.util.concurrent.{CompletionStage} import scala.concurrent.java8.FuturesConvertersImpl._ -import scala.concurrent.{Future, Promise} +import scala.concurrent.{Future} object FutureUtils { /** diff --git a/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala b/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala index b6f76e4..c92ccc4 100644 --- a/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala +++ b/src/test/scala/com/datastax/gatling/plugin/request/CqlRequestActionSpec.scala @@ -1,7 +1,7 @@ package com.datastax.gatling.plugin.request import java.nio.ByteBuffer -import java.util.concurrent.{Executor, TimeUnit} +import java.util.concurrent.{CompletionStage, Executor, TimeUnit} import akka.actor.{ActorSystem, Props} import akka.testkit.TestKitBase @@ -14,9 +14,10 @@ import com.datastax.gatling.plugin.metrics.NoopMetricsLogger import com.datastax.gatling.plugin.utils.GatlingTimingSource import com.datastax.gatling.plugin.DseProtocol import com.datastax.gatling.plugin.model.{DseCqlAttributes, DseCqlStatement} -import com.datastax.oss.driver.api.core.cql.{ResultSet, SimpleStatement, Statement} +import com.datastax.oss.driver.api.core.cql.{AsyncResultSet, ResultSet, SimpleStatement, Statement} import com.datastax.oss.protocol.internal.ProtocolConstants.ConsistencyLevel import com.google.common.util.concurrent.{Futures, ListenableFuture} +import io.gatling.commons.validation.Validation import io.gatling.core.action.Exit import io.gatling.core.config.GatlingConfiguration import io.gatling.core.session.Session @@ -24,6 +25,7 @@ import io.gatling.core.stats.StatsEngine import org.easymock.EasyMock import org.easymock.EasyMock._ import org.slf4j.LoggerFactory +import scopt.Validation class CqlRequestActionSpec extends BaseSpec with TestKitBase { implicit lazy val system:ActorSystem = ActorSystem() @@ -47,7 +49,7 @@ class CqlRequestActionSpec extends BaseSpec with TestKitBase { GatlingTimingSource()) } - private def mockResultSetFuture(): ResultSetFuture = new ResultSetFuture { + private def mockResultSetFuture(): CompletionStage[AsyncResultSet] = new CompletionStage[AsyncResultSet] { val delegate: ListenableFuture[ResultSet] = Futures.immediateFuture(mock[ResultSet]) override def cancel(b: Boolean): Boolean = false override def getUninterruptibly: ResultSet = delegate.get() @@ -68,15 +70,14 @@ class CqlRequestActionSpec extends BaseSpec with TestKitBase { } describe("CQL") { - val statementCapture = EasyMock.newCapture[Statement] + val statementCapture = EasyMock.newCapture[SimpleStatement] it("should have default CQL attributes set if nothing passed") { val cqlAttributesWithDefaults = DseCqlAttributes( "test", dseCqlStatement) expecting { - dseCqlStatement.buildFromSession(gatlingSession).andReturn(new SimpleStatement("select * from test") - .success) + dseCqlStatement.buildFromSession(gatlingSession).andReturn(SimpleStatement.newInstance("select * from test")) dseSession.executeAsync(capture(statementCapture)) andReturn mockResultSetFuture() } @@ -84,17 +85,18 @@ class CqlRequestActionSpec extends BaseSpec with TestKitBase { getTarget(cqlAttributesWithDefaults).sendQuery(gatlingSession) } - val capturedStatement = statementCapture.getValue + val capturedStatement = statementCapture.getValue.asInstanceOf[SimpleStatement] capturedStatement shouldBe a[SimpleStatement] capturedStatement.getConsistencyLevel shouldBe null capturedStatement.getSerialConsistencyLevel shouldBe null - capturedStatement.getFetchSize shouldBe 0 - capturedStatement.getDefaultTimestamp shouldBe -9223372036854775808L - capturedStatement.getReadTimeoutMillis shouldBe -2147483648 - capturedStatement.getRetryPolicy shouldBe null + capturedStatement.getPageSize shouldBe 0 + capturedStatement.getQueryTimestamp shouldBe -9223372036854775808L + //TODO refactor + //capturedStatement.getReadTimeoutMillis shouldBe -2147483648 + //capturedStatement.getRetryPolicy shouldBe null capturedStatement.isIdempotent shouldBe null capturedStatement.isTracing shouldBe false - capturedStatement.getQueryString should be("select * from test") + capturedStatement.getQuery should be("select * from test") } it("should enable all the CQL Attributes in DseAttributes") { @@ -108,12 +110,19 @@ class CqlRequestActionSpec extends BaseSpec with TestKitBase { idempotent = Some(true), fetchSize = Some(50), serialCl = Some(ConsistencyLevel.LOCAL_SERIAL), - retryPolicy = Some(FallthroughRetryPolicy.INSTANCE), enableTrace = Some(true)) expecting { - dseCqlStatement.buildFromSession(gatlingSession).andReturn(new SimpleStatement("select * from test") - .success) + dseCqlStatement.buildFromSession(gatlingSession).andReturn(new Validation[SimpleStatement] { + override def map[A](f: SimpleStatement => A): Validation[A] = ??? + override def flatMap[A](f: SimpleStatement => Validation[A]): Validation[A] = ??? + override def mapError(f: String => String): Validation[SimpleStatement] = ??? + override def filter(p: SimpleStatement => Boolean): Validation[SimpleStatement] = ??? + override def onSuccess(f: SimpleStatement => Any): Unit = SimpleStatement.newInstance("select * from test").asInstanceOf[Statement] + override def onFailure(f: String => Any): Unit = ??? + override def recover[A >: SimpleStatement](v: => A): Validation[A] = ??? + override def get: SimpleStatement = ??? + }).success dseSession.executeAsync(capture(statementCapture)) andReturn mockResultSetFuture() } @@ -121,7 +130,7 @@ class CqlRequestActionSpec extends BaseSpec with TestKitBase { getTarget(cqlAttributes).sendQuery(gatlingSession) } - val capturedStatement = statementCapture.getValue + val capturedStatement = statementCapture.getValue.asInstanceOf[SimpleStatement] capturedStatement shouldBe a[SimpleStatement] capturedStatement.getConsistencyLevel shouldBe ConsistencyLevel.ANY capturedStatement.getDefaultTimestamp shouldBe 1498167845000L