[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-schemafuzz] branch master updated: db setup script,
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-schemafuzz] branch master updated: db setup script, bugg fixing and minor optimisation |
Date: |
Mon, 02 Jul 2018 11:26:06 +0200 |
This is an automated email from the git hooks/post-receive script.
erwan-ulrich pushed a commit to branch master
in repository schemafuzz.
The following commit(s) were added to refs/heads/master by this push:
new 22c22d3 db setup script, bugg fixing and minor optimisation
22c22d3 is described below
commit 22c22d3252bdc8008c5f931f4b452e5a3505342b
Author: Feideus <address@hidden>
AuthorDate: Mon Jul 2 11:26:00 2018 +0200
db setup script, bugg fixing and minor optimisation
---
sample_database/pagila-0.10.1/setup_test_table.sql | 15 ++++
src/main/java/org/schemaspy/DBFuzzer.java | 22 ++++--
src/main/java/org/schemaspy/model/GenericTree.java | 17 +++++
.../java/org/schemaspy/model/GenericTreeNode.java | 84 +++++++++++++++++-----
.../org/schemaspy/model/GenericTreeNodeTest.java | 8 ++-
5 files changed, 118 insertions(+), 28 deletions(-)
diff --git a/sample_database/pagila-0.10.1/setup_test_table.sql
b/sample_database/pagila-0.10.1/setup_test_table.sql
new file mode 100644
index 0000000..afcd341
--- /dev/null
+++ b/sample_database/pagila-0.10.1/setup_test_table.sql
@@ -0,0 +1,15 @@
+DROP TABLE actual_test_table;
+
+CREATE TABLE actual_test_table (
+ address_id integer DEFAULT nextval('address_address_id_seq'::regclass) NOT
NULL,
+ address character varying(50) NOT NULL,
+ address2 character varying(50),
+ district character varying(20) NOT NULL,
+ city_id smallint NOT NULL,
+ postal_code character varying(10),
+ phone character varying(20) NOT NULL
+ );
+
+INSERT INTO actual_test_table VALUES (0 ,23, 'Workhaven Lane'
,'Alberta' ,300,93360 ,14033335567);
+INSERT INTO actual_test_table VALUES (4 ,1411, 'Lillydale Drive' ,'QLD'
,576 ,88888,6172235589);
+INSERT INTO actual_test_table VALUES (5 ,1913, 'Hanoi Way' ,'Nagasaki'
,463 ,42420,28303384290);
diff --git a/src/main/java/org/schemaspy/DBFuzzer.java
b/src/main/java/org/schemaspy/DBFuzzer.java
index 00d9d6b..be192a5 100644
--- a/src/main/java/org/schemaspy/DBFuzzer.java
+++ b/src/main/java/org/schemaspy/DBFuzzer.java
@@ -9,6 +9,7 @@ import org.schemaspy.model.*;
import org.schemaspy.model.Table;
import org.schemaspy.model.GenericTree;
import org.schemaspy.model.GenericTreeNode;
+import org.schemaspy.service.DatabaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
@@ -37,7 +38,7 @@ public class DBFuzzer
{
if(rootMutation.getChosenChange() != null)
{
- nbUpdates =
rootMutation.inject(analyzer.getSqlService(),analyzer.getDb(),false);
+ nbUpdates =
rootMutation.inject(analyzer.getSqlService(),analyzer.getDb(),mutationTree,false);
if(nbUpdates > 0)
{
LOGGER.info("GenericTreeNode was sucessfull");
@@ -122,7 +123,7 @@ public class DBFuzzer
{
try
{
-
mutationTree.getLastMutation().undoToMutation(currentMutation.getParent(),analyzer);
+
mutationTree.getLastMutation().undoToMutation(currentMutation.getParent(),analyzer,mutationTree);
}
catch(Exception e)
@@ -135,7 +136,7 @@ public class DBFuzzer
{
if(currentMutation.getChosenChange() != null)
{
- int nbUpdates =
currentMutation.inject(analyzer.getSqlService(),analyzer.getDb(),false);
+ int nbUpdates =
currentMutation.inject(analyzer.getSqlService(),analyzer.getDb(),mutationTree,false);
if(nbUpdates > 0)
{
LOGGER.info("GenericTreeNode was sucessfull");
@@ -144,17 +145,20 @@ public class DBFuzzer
}
else if (nbUpdates == 0 || nbUpdates == -1)
{
- if(nbUpdates == 0)
+ if (nbUpdates == 0)
LOGGER.info("QueryError. This update affected 0
rows.");
else
+ {
LOGGER.info("GenericTreeNode was sucessfull");
+
currentMutation.updatePotentialChangeAfterInjection();
+ mutationTree.addToTree(currentMutation);
+ }
if(!currentMutation.getParent().compare(mutationTree.getLastMutation()))
{
try
{
-
currentMutation.getParent().undoToMutation(mutationTree.getLastMutation(),analyzer);
-
+
currentMutation.getParent().undoToMutation(mutationTree.getLastMutation(),analyzer,mutationTree);
}
catch(Exception e)
{
@@ -162,6 +166,10 @@ public class DBFuzzer
}
}
}
+ else
+ LOGGER.info("Injection returned unknown error code.");
+
+
}
}
catch(Exception e)
@@ -413,5 +421,5 @@ public class DBFuzzer
return mutationTree.getLastId()+1;
}
-
+
}
diff --git a/src/main/java/org/schemaspy/model/GenericTree.java
b/src/main/java/org/schemaspy/model/GenericTree.java
index c6f488d..cf5f9c0 100644
--- a/src/main/java/org/schemaspy/model/GenericTree.java
+++ b/src/main/java/org/schemaspy/model/GenericTree.java
@@ -1,6 +1,8 @@
package org.schemaspy.model;
+import java.util.ArrayList;
+
public class GenericTree {
private GenericTreeNode root;
@@ -121,4 +123,19 @@ public class GenericTree {
return res;
}
+
+ public ArrayList<GenericTreeNode> toArray() {
+ ArrayList<GenericTreeNode> result = new ArrayList<>();
+ toArrayHelp(root, result);
+ return result;
+ }
+
+ private void toArrayHelp(GenericTreeNode ref, ArrayList<GenericTreeNode>
result) {
+ if (ref == null) {
+ return;
+ }
+ result.add(ref);
+ for(GenericTreeNode gtn : ref.getChildren())
+ toArrayHelp(gtn, result);
+ }
}
diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java
b/src/main/java/org/schemaspy/model/GenericTreeNode.java
index e447165..97e333b 100644
--- a/src/main/java/org/schemaspy/model/GenericTreeNode.java
+++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java
@@ -238,17 +238,20 @@ public class GenericTreeNode {
case "serial":
case "bigserial":
Object tmp =
rootForThisMutation.getInitial_state_row().getContent().get(tableColumn.getName());
+ Random rand = new Random();
if (tmp != null && tmp.toString() != "") {
int tmp2;
if (typeName.equals("int2") || typeName.equals("serial")) {
tmp2 =
Integer.parseInt(rootForThisMutation.getInitial_state_row().getContent().get(tableColumn.getName()).toString());
oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(tmp2++)));
oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(32767)));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, rand.nextInt(32767)));
} else if (typeName.equals("int8") ||
typeName.equals("bigserial")) {
BigInteger bigInt = new
BigInteger(rootForThisMutation.getInitial_state_row().getContent().get(tableColumn.getName()).toString());
bigInt = bigInt.add(new BigInteger("1"));
oneChange.add(new SingleChange(tableColumn, this,
column_value, bigInt));
oneChange.add(new SingleChange(tableColumn, this,
column_value, new BigInteger("9223372036854775806")));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, nextRandomBigInteger(new BigInteger("9223372036854775806"))));
}
oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(0)));
break;
@@ -264,12 +267,15 @@ public class GenericTreeNode {
tmp = Arrays.toString(bytes);
}
- if (tmp != null && !tmp.toString().isEmpty()) {
+ if (tmp != null && !tmp.toString().isEmpty() &&
tmp.toString().length() >0)
+ {
String tmp2 = tmp.toString();
- char nextChar = (char) (tmp2.charAt(0) + 1);
- char prevChar = (char) (tmp2.charAt(0) - 1);
- oneChange.add(new SingleChange(tableColumn, this,
column_value, (Character.toString(nextChar) +
column_value.toString().substring(1))));
- oneChange.add(new SingleChange(tableColumn, this,
column_value, (Character.toString(prevChar) +
column_value.toString().substring(1))));
+ Random rand3 = new Random();
+ int tmpRand = rand3.nextInt(tmp2.length());
+ char nextChar = (char) (tmp2.charAt(tmpRand) + 1);
+ char prevChar = (char) (tmp2.charAt(tmpRand) - 1);
+ oneChange.add(new SingleChange(tableColumn, this,
column_value,
column_value.toString().substring(0,tmpRand)+nextChar+column_value.toString().substring(tmpRand+1)));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value,
column_value.toString().substring(0,tmpRand)+prevChar+column_value.toString().substring(tmpRand+1)));
}
break;
@@ -282,9 +288,10 @@ public class GenericTreeNode {
case "text":
tmp =
rootForThisMutation.getInitial_state_row().getContent().get(tableColumn.getName());
- if (tmp != null && tmp.toString() != "") {
- Random rand = new Random();
- int randNum = rand.nextInt(tmp.toString().length());
+ if (tmp != null && tmp.toString() != "")
+ {
+ Random rand2 = new Random();
+ int randNum = rand2.nextInt(tmp.toString().length());
char tmp3 = tmp.toString().charAt(randNum);
oneChange.add(new SingleChange(tableColumn, this,
column_value, tmp.toString().substring(0, randNum) +
(Character.toString(tmp3++)) + tmp.toString().substring(randNum + 1)));
@@ -332,7 +339,7 @@ public class GenericTreeNode {
return oneChange;
}
- public int inject(SqlService sqlService, Database db, boolean undo)
+ public int inject(SqlService sqlService, Database db,GenericTree
mutationTree, boolean undo)
{
boolean transfered = false;
String theQuery = "";
@@ -345,7 +352,7 @@ public class GenericTreeNode {
if (checkIfHasParentFk(db)) {
transfered = true;
System.out.println("TRANSFERT");
- transferMutationToParent(db, sqlService); //LAST UNCONSISTENCY
COMES FROM THE CASCADE ON CONSTRAINT.SOME OTHER MUTATIONS ARE AFECTED BY THE
CASCADE AND GET THEIR INITIAL STATE ROW UNCONSISTENT.
+ transferMutationToParent(db, sqlService);
}
theQuery = updateQueryBuilder(undo, db, sqlService);
@@ -353,8 +360,11 @@ public class GenericTreeNode {
{
Statement stmt = sqlService.getConnection().createStatement();
int nbUpdates = stmt.executeUpdate(theQuery);
+ if(nbUpdates > 0)
+ //handleCascadeUpdate(this,db,mutationTree);
if(transfered && nbUpdates > 0)
return -1;
+
return nbUpdates;
}
catch (Exception e)
@@ -379,9 +389,9 @@ public class GenericTreeNode {
System.out.println("problem");
}
- public int undo(SqlService sqlService, Database db) {
+ public int undo(SqlService sqlService, Database db,GenericTree
mutationTree) {
try {
- return this.inject(sqlService, db, true);
+ return this.inject(sqlService, db,mutationTree, true);
} catch (Exception e) {
e.printStackTrace();
return 0;
@@ -500,22 +510,19 @@ public class GenericTreeNode {
return false;
}
- public boolean undoToMutation(GenericTreeNode target, SchemaAnalyzer
analyzer) {
+ public boolean undoToMutation(GenericTreeNode target, SchemaAnalyzer
analyzer,GenericTree mutationTree) {
ArrayList<GenericTreeNode> goingUp = findPathToMutation(target).get(0);
ArrayList<GenericTreeNode> goingDown =
findPathToMutation(target).get(1);
- if(goingUp.contains(parent) && goingDown.isEmpty())
- goingUp.remove(parent);
-
try
{
for (GenericTreeNode node : goingUp) {
- if (node.undo(analyzer.getSqlService(), analyzer.getDb()) > 0)
+ if (node.undo(analyzer.getSqlService(),
analyzer.getDb(),mutationTree) > 0)
System.out.println("success undoing :" + node.getId());
}
for (GenericTreeNode node : goingDown) {
- if (node.inject(analyzer.getSqlService(), analyzer.getDb(),
false) > 0)
+ if (node.inject(analyzer.getSqlService(),
analyzer.getDb(),mutationTree, false) > 0)
System.out.println("success doing :" + node.getId());
}
@@ -858,4 +865,45 @@ public class GenericTreeNode {
initPostChangeRow();
}
+ public void handleCascadeUpdate(GenericTreeNode currentMutation, Database
db,GenericTree mutationTree)
+ {
+ SingleChange sgCurrMut = currentMutation.getChosenChange();
+ Map<String,Collection<ForeignKeyConstraint>> lesFk =
db.getLesForeignKeys();
+ List<TableColumn> cascadedColumns = new ArrayList<>();
+
+ for (Map.Entry<String,Collection<ForeignKeyConstraint>> fkCol:
lesFk.entrySet())
+ {
+ for(ForeignKeyConstraint fk : fkCol.getValue())
+ {
+ if
(fk.getParentColumns().contains(sgCurrMut.getParentTableColumn()))
+ {
+ cascadedColumns = fk.getChildColumns();
+ }
+ }
+ }
+
+ if(cascadedColumns.isEmpty())
+ return;
+
+ ArrayList<GenericTreeNode> treeAsArray = mutationTree.toArray();
+ treeAsArray.remove(this);
+ for(GenericTreeNode gtn : treeAsArray)
+ {
+ for(TableColumn tb : cascadedColumns)
+ {
+ Object objectToBeChanged =
gtn.getInitial_state_row().getContent().get(tb.getName());
+ if(objectToBeChanged != null &&
objectToBeChanged.toString().equals(sgCurrMut.getOldValue()))
+
gtn.getInitial_state_row().setValueOfColumn(tb.getName(),sgCurrMut.getNewValue());
+ }
+ }
+ }
+
+ public BigInteger nextRandomBigInteger(BigInteger n) {
+ Random rand = new Random();
+ BigInteger result = new BigInteger(n.bitLength(), rand);
+ while( result.compareTo(n) >= 0 ) {
+ result = new BigInteger(n.bitLength(), rand);
+ }
+ return result;
+ }
}
diff --git a/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java
b/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java
index 5a696bd..67c65bf 100644
--- a/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java
+++ b/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java
@@ -186,11 +186,13 @@ public class GenericTreeNodeTest extends
AbstractTestExecutionListener {
GenericTreeNode tmpMutation1 = new
GenericTreeNode(response.getRows().get(0),1,sqlService);
+ GenericTree mutationTree = new GenericTree();
+
tmpMutation1.setChosenChange(tmpMutation1.getPotential_changes().get(0));
tmpMutation1.initPostChangeRow();
+ mutationTree.setRoot(tmpMutation1);
-
- Assert.assertTrue(tmpMutation1.inject(sqlService,database,false) > 0
); //Test
+
Assert.assertTrue(tmpMutation1.inject(sqlService,database,mutationTree,false) >
0 ); //Test
rs = stmt.executeQuery();
response =
parser.parse(rs,database.getTablesMap().get("actual_test_table"));
@@ -199,7 +201,7 @@ public class GenericTreeNodeTest extends
AbstractTestExecutionListener {
System.out.println(tmpMutation1.getPost_change_row());
Assert.assertTrue(response.getRows().get(0).compare(tmpMutation1.getPost_change_row()));
- Assert.assertTrue(tmpMutation1.undo(sqlService,database) > 0); //Test
+ Assert.assertTrue(tmpMutation1.undo(sqlService,database,mutationTree)
> 0); //Test
rs = stmt.executeQuery();
response =
parser.parse(rs,database.getTablesMap().get("actual_test_table"));
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-schemafuzz] branch master updated: db setup script, bugg fixing and minor optimisation,
gnunet <=