Skip to content

Commit

Permalink
Fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
suarezgpablo committed Dec 16, 2024
1 parent 20ad0e3 commit 5d843f1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ public void csvCassandra(String tableName, String keyspace, String properties, S
}

/**
* Auxiliary method of csvCassandra that processes each row and returns
* Auxiliary method of csvCassandra that processes each row and returns
* its content in a string formatted as a CSV.
*/
private String rowProcessing(Row row, String[][] results, boolean[] numeric, int rowNumber, int columnNumber) {
StringBuilder stringRow = new StringBuilder("\"");
for (int i = 0; i < columnNumber; i++) {
String result = row.getString(i);
if (result == null) { //When there is no value stored in the db, skip the iteration
stringRow.append(",\"\"");
continue;
}
if (i==0) {
Expand Down Expand Up @@ -120,8 +119,8 @@ private String[][] sortMatrix(String[][] matrixResultSet, int columnNumber, List
matrixResultSet = sortMatrix(matrixResultSet, columnNumber + 1, cassandraRows, 0,
matrixResultSet.length - 1, numericArray);
return matrixResultSet;
}
//For the rest of columns it sorts them when the values of the first column are the same. This also applies
}
//For the rest of columns it sorts them when the values of the first column are the same. This also applies
//for the following of columns
else {
List<Integer> border = equalRanges(beggining, end, columnNumber - 1, matrixResultSet,
Expand Down Expand Up @@ -162,8 +161,8 @@ private void sortIteration (boolean numeric, String[][] matrixResultSet, List<St
String next = matrixResultSet[row2][numberColumn];
boolean sort = false;
if (numeric) {
long currentNumber = Long.parseLong(current);
long nextNumber = Long.parseLong(next);
Long currentNumber = Long.valueOf(current);
Long nextNumber = Long.valueOf(next);
if (currentNumber < nextNumber) {
sort = true;
}
Expand Down Expand Up @@ -264,7 +263,7 @@ public void convertToCsv(java.sql.ResultSet rs, String path) {

/**
* Returns the names of the tables of a keyspace
* @param tableProjection
* @param tableProjection
*/
public Map<String, List<String>> namesTablesColumnsKeyspace(String keyspace, CassandraConnection connection, Map<String, String> tableProjection) {
Map<String, List<String>> tableColumns = new HashMap<>();
Expand All @@ -289,7 +288,7 @@ public Map<String, List<String>> namesTablesColumnsKeyspace(String keyspace, Cas
List<String> columnNamesList = new ArrayList<>();
BoundStatement bsColumns = columnNamesPreparedStatement.bind(keyspace, tableName);
ResultSet resultColumnNames = connection.executeStatement(bsColumns);
Row rowColumnNames = resultColumnNames.one();
Row rowColumnNames = resultColumnNames.one();
while (rowColumnNames != null) {
String columnName = rowColumnNames.getString("column_name");
if (projectionStatementTable.matches(".*\\b" + columnName + "\\b.*")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.junit.Test;
import org.junit.rules.TestName;

import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.oss.driver.api.core.cql.PreparedStatement;

import giis.modevo.consistency.OracleCsv;
Expand All @@ -24,6 +27,9 @@
import giis.modevo.migration.script.execution.CassandraConnection;
import giis.modevo.model.ModelObjects;
import giis.visualassert.VisualAssert;
import in2test.consiste.XML.ReadXML;
import in2test.consiste.connection.ConnectionCassandra;
import in2test.consiste.structure.LogicalPhysicalTable;
import test4giis.modevo.TestUtils;

public class TestCheckConsistency {
Expand Down Expand Up @@ -132,14 +138,7 @@ public void testCustomV9RemovePK() throws IOException {
projectionAfterEvo.put("table1", "SELECT author.id AS idauthor, book.id AS idbook FROM author INNER JOIN authorbook ON author.id = authorbook.idauthor INNER JOIN book ON book.id = authorbook.idbook ORDER BY author.id DESC, book.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "custom", projectionBeforeEvo);
}
@Test
public void testMindsV3SplitColumn() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("comments", "SELECT id, parent_guid FROM comments;");
projectionAfterEvo.put("comments", "SELECT id,parent_guid, CASE WHEN parent_guid < 'F' THEN parent_guid ELSE NULL END AS parent_guid_c1, CASE WHEN parent_guid < 'P' THEN parent_guid ELSE NULL END AS parent_guid_c2, CASE WHEN parent_guid > 'P' THEN parent_guid ELSE NULL END AS parent_guid_c3 FROM comments ORDER BY id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "minds", projectionBeforeEvo);
}

@Test
public void testMindsV10NewTableMigrationFromOneTable() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Expand Down Expand Up @@ -253,6 +252,7 @@ private void testConsistency (String testName, Map<String, String> tableQueryCom
* Sets up the Cassandra by populating it with all the data required from the SQL database using the queries specified in tableProjection
*/
private void setUpCassandraDatabase(String testName, String keyspace, Map<String, String> tableProjection) {
resetDatabaseCassandraUnitTesting (testName);
OracleCsv oc = new OracleCsv();
Map<String, List<String>> tableColumnsMap = oc.namesTablesColumnsKeyspace(testName, connection, tableProjection); //Map of the names of tables and its columns
Map <String, PreparedStatement> preparedStatementsTable = new HashMap <>();
Expand All @@ -265,6 +265,19 @@ private void setUpCassandraDatabase(String testName, String keyspace, Map<String
}
migrateSqlToCassandra (preparedStatementsTable, keyspace, tableProjection); //Migrates data from the SQL database to each Cassandra table
}
/**
* Empties the database of data
*/
private void resetDatabaseCassandraUnitTesting(String keyspace) {
String cql = "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '"+keyspace+"';";
com.datastax.oss.driver.api.core.cql.ResultSet results = connection.executeStatement(cql);
for (com.datastax.oss.driver.api.core.cql.Row row : results) {
String nameTable = row.getString(0);
String delete = "";
delete = "TRUNCATE \""+keyspace+"\"."+nameTable+";";
connection.executeStatement(delete);
}
}

/**
* Builds a PreparedStatement to insert data to all columns of a Cassandra table
Expand Down
6 changes: 3 additions & 3 deletions modevo-script/dat/bmk/testMindsV3SplitColumn-script.cql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FOR $1,$2 = SELECT parent_guid, id FROM comments WHERE parent_guid>'f' ALLOW FILTERING
FOR $3,$4 = SELECT parent_guid, id FROM comments WHERE parent_guid>'p' ALLOW FILTERING
FOR $5,$6 = SELECT parent_guid, id FROM comments WHERE parent_guid<'p' ALLOW FILTERING
FOR $1,$2 = SELECT parent_guid, id FROM comments WHERE parent_guid>'F' ALLOW FILTERING
FOR $3,$4 = SELECT parent_guid, id FROM comments WHERE parent_guid>'P' ALLOW FILTERING
FOR $5,$6 = SELECT parent_guid, id FROM comments WHERE parent_guid<'P' ALLOW FILTERING
INSERT INTO comments(parent_guid_c1, id) VALUES ($1, $2);
INSERT INTO comments(parent_guid_c2, id) VALUES ($3, $4);
INSERT INTO comments(parent_guid_c3, id) VALUES ($5, $6);

0 comments on commit 5d843f1

Please sign in to comment.