maedhroz commented on code in PR #2190:
URL: https://github.com/apache/cassandra/pull/2190#discussion_r1126819910
##########
test/unit/org/apache/cassandra/cql3/PreparedStatementsTest.java:
##########
@@ -581,4 +653,126 @@ private void testPrepareWithBatchLWT(ProtocolVersion
version) throws Throwable
row(false, 1, 10, 20, null));
assertEquals(rs.getColumnDefinitions().size(), 5);
}
+
+ @Test
+ public void testPrepareWithAccordV4()
+ {
+ testPrepareWithAccord(ProtocolVersion.V4);
+ }
+
+ @Test
+ public void testPrepareWithAccordV5()
+ {
+ Assume.assumeTrue("Protocol v5 is CURRENT", ProtocolVersion.CURRENT !=
ProtocolVersion.V5);
+ testPrepareWithAccord(ProtocolVersion.V5);
+ }
+
+ @Test
+ public void testPrepareWithAccordCurrent()
+ {
+ testPrepareWithAccord(ProtocolVersion.CURRENT);
+ }
+
+ private void testPrepareWithAccord(ProtocolVersion version)
+ {
+ int maxAttempts = 3;
+ Session session = sessionNet(version);
+ session.execute("USE " + keyspace());
+ createTable("CREATE TABLE %s (pk int, v1 int, v2 int, PRIMARY KEY
(pk))");
+ updateTxnState();
+
+ PreparedStatement writeOnly = session.prepare(txn(
+ "INSERT INTO " + currentTable() + " (pk, v1, v2) VALUES (?, ?, ?)"
+ ));
+ PreparedStatement returnSelect = session.prepare(txn(
+ "SELECT * FROM " + currentTable() + " WHERE pk=?",
+ "UPDATE " + currentTable() + " SET v1 += 1, v2 += 2 WHERE pk = ?"
+ ));
+ PreparedStatement returnRef = session.prepare(txn(
+ "LET a = (SELECT * FROM " + currentTable() + " WHERE pk=?)",
+ "SELECT a.pk, a.v1, a.v2",
+ "UPDATE " + currentTable() + " SET v1 += 1, v2 += 2 WHERE pk = ?"
+ ));
+ // populate every row
+ int numPartitions = 5;
+ int[][] model = new int[numPartitions][];
+ for (int writePk = 0; writePk < numPartitions; writePk++)
+ {
+ model[writePk] = new int[] {0, 0};
+ assertRowsNet(version, session.execute(writeOnly.bind(writePk, 0,
0)));
+ }
+
+ for (int writePk = 0; writePk < numPartitions; writePk++)
+ {
+ for (int readPk = 0; readPk < numPartitions; readPk++)
+ {
+ int[] expected = model[readPk];
+ int[] mutated = model[writePk];
+ for (boolean select : Arrays.asList(true, false))
+ {
+ for (int retries = 0; retries < maxAttempts; retries++)
+ {
+ try
+ {
+ ResultSet rs = session.execute(select ?
returnSelect.bind(readPk, writePk)
+ :
returnRef.bind(readPk, writePk));
+ assertRowsNet(version, rs, row(readPk,
expected[0], expected[1]));
+ break;
+ }
+ catch (WriteTimeoutException e)
+ {
+ logger.warn("Write timeout seen", e);
+ if (retries >= maxAttempts - 1) throw e;
+ Uninterruptibles.sleepUninterruptibly(500,
TimeUnit.MILLISECONDS);
+ }
+ finally
+ {
+ // update to account for counter bumps
+ mutated[0]++;
+ mutated[1] = mutated[1] + 2;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static String txn(String... stmts)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("BEGIN TRANSACTION\n");
+ for (String stmt : stmts)
+ {
+ sb.append(" ").append(stmt);
+ if (!stmt.endsWith(";")) sb.append(';');
+ sb.append('\n');
+ }
+ sb.append("COMMIT TRANSACTION");
+ return sb.toString();
+ }
+
+ private static String batch(String... stmts)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("BEGIN BATCH\n");
+ for (String stmt : stmts)
+ {
+ sb.append(" ").append(stmt);
+ if (!stmt.endsWith(";")) sb.append(';');
+ sb.append('\n');
+ }
+ sb.append("APPLY BATCH");
+ return sb.toString();
+ }
+
+ private static List<String> columnNames(ResultSet rs)
+ {
+ return rs.getColumnDefinitions().asList().stream().map(d ->
d.getName()).collect(Collectors.toList());
+ }
+
+ private static void updateTxnState()
Review Comment:
nit: I guess we should throw in a TODO to remove this once transactional
metadata is in place? (The cache disabling bit could just be in a `@Before`
method...I think.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]