-
Notifications
You must be signed in to change notification settings - Fork 110
Initial CQL Session Replacement #1498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package org.evomaster.client.java.instrumentation; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Info related to CQL command execution | ||
| */ | ||
| public class ExecutedCqlCommand implements Serializable { | ||
|
|
||
| /** | ||
| * A constant to represent that execution time could not be obtained. | ||
| */ | ||
| public static final long FAILURE_EXECUTION_TIME = -1L; | ||
|
|
||
| /** | ||
| * The actual CQL string with the command that was executed | ||
| */ | ||
| private final String cqlCommand; | ||
|
|
||
| /** | ||
| * Whether the CQL command failed, for any reason | ||
| */ | ||
| private final boolean threwCqlException; | ||
|
|
||
| /** | ||
| * Execution time | ||
| */ | ||
| private final long executionTime; | ||
|
|
||
| public ExecutedCqlCommand(String cqlCommand, boolean threwCqlException, long executionTime) { | ||
| this.cqlCommand = cqlCommand; | ||
| this.threwCqlException = threwCqlException; | ||
| this.executionTime = executionTime; | ||
| } | ||
|
|
||
| public String getCqlCommand() { | ||
| return cqlCommand; | ||
| } | ||
|
|
||
| public boolean hasThrownCqlException() { | ||
| return threwCqlException; | ||
| } | ||
|
|
||
| public long getExecutionTime() { | ||
| return executionTime; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| ExecutedCqlCommand executedCqlCommand = (ExecutedCqlCommand) o; | ||
| return threwCqlException == executedCqlCommand.threwCqlException && Objects.equals(cqlCommand, executedCqlCommand.cqlCommand); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(cqlCommand, threwCqlException); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package org.evomaster.client.java.instrumentation.coverage.methodreplacement.thirdpartyclasses; | ||
|
|
||
| import org.evomaster.client.java.instrumentation.ExecutedCqlCommand; | ||
| import org.evomaster.client.java.instrumentation.coverage.methodreplacement.Replacement; | ||
| import org.evomaster.client.java.instrumentation.coverage.methodreplacement.ThirdPartyMethodReplacementClass; | ||
| import org.evomaster.client.java.instrumentation.coverage.methodreplacement.UsageFilter; | ||
| import org.evomaster.client.java.instrumentation.shared.ReplacementCategory; | ||
| import org.evomaster.client.java.instrumentation.shared.ReplacementType; | ||
| import org.evomaster.client.java.instrumentation.staticstate.ExecutionTracer; | ||
|
|
||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.lang.reflect.Method; | ||
|
|
||
| public class CqlSessionClassReplacement extends ThirdPartyMethodReplacementClass { | ||
| private static final CqlSessionClassReplacement singleton = new CqlSessionClassReplacement(); | ||
|
|
||
| @Override | ||
| protected String getNameOfThirdPartyTargetClass() { | ||
| return "com.datastax.oss.driver.api.core.CqlSession"; | ||
| } | ||
|
|
||
| @Replacement(replacingStatic = false, type = ReplacementType.TRACKER, id = "findSyncString", usageFilter = UsageFilter.ANY, category = ReplacementCategory.CASSANDRA, castTo = "com.datastax.oss.driver.api.core.cql.ResultSet") | ||
| public static Object execute(Object cqlSession, String query) { | ||
| return handleCqlExecute("findSyncString", cqlSession, query); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace these strings with private constants
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also check if replacingStatic is always false (most of the cases I've seen) then you can remove that parameter as false is the default. |
||
| } | ||
|
|
||
| private static Object handleCqlExecute(String id, Object cqlSession, String query) { | ||
| long start = System.currentTimeMillis(); | ||
| try { | ||
| Method executeMethod = retrieveExecuteMethod(id, cqlSession); | ||
| Object result = executeMethod.invoke(cqlSession, query); | ||
| long end = System.currentTimeMillis(); | ||
| long executionTime = end - start; | ||
| ExecutedCqlCommand info = new ExecutedCqlCommand(query, false, executionTime); | ||
| ExecutionTracer.addCqlInfo(info); | ||
| return result; | ||
| } catch (IllegalAccessException e) { | ||
| throw new RuntimeException(e); | ||
| } catch (InvocationTargetException e) { | ||
| throw (RuntimeException) e.getCause(); | ||
| } | ||
| } | ||
|
|
||
| private static Method retrieveExecuteMethod(String id, Object cqlSession){ | ||
| return getOriginal(singleton, id, cqlSession); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another student @aschenzle is modifying this at this moment. Please contact him to discuss this change because it might lead to integration conflicts
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the bom will work but we decided not to do that. This version will end up conflicting with my Amazon SDK version which is 4.1.107 (newer) so check my PR here and rebase your changes over it: https://github.com/aschenzle/EvoMaster/tree/pr/dynamodb-interception.