gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-schemafuzz] branch master updated: Working on the tr


From: gnunet
Subject: [GNUnet-SVN] [taler-schemafuzz] branch master updated: Working on the transfer mechanic.(f*cks up the do-undo history)
Date: Fri, 22 Jun 2018 14:45:45 +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 000a38c  Working on the transfer mechanic.(f*cks up the do-undo 
history)
000a38c is described below

commit 000a38c930f1cd7c8ed55853aa475f2e04500991
Author: Feideus <address@hidden>
AuthorDate: Fri Jun 22 14:45:38 2018 +0200

    Working on the transfer mechanic.(f*cks up the do-undo history)
---
 src/main/java/org/schemaspy/DBFuzzer.java          |  12 ++-
 .../java/org/schemaspy/model/GenericTreeNode.java  | 118 ++++++++++++++-------
 .../java/org/schemaspy/model/SingleChange.java     |   7 +-
 .../org/schemaspy/model/GenericTreeNodeTest.java   |   2 +-
 4 files changed, 94 insertions(+), 45 deletions(-)

diff --git a/src/main/java/org/schemaspy/DBFuzzer.java 
b/src/main/java/org/schemaspy/DBFuzzer.java
index 7c306c8..00d9d6b 100644
--- a/src/main/java/org/schemaspy/DBFuzzer.java
+++ b/src/main/java/org/schemaspy/DBFuzzer.java
@@ -77,7 +77,6 @@ public class DBFuzzer
     public boolean fuzz (Config config)
     {
         boolean returnStatus = true;
-        int nbUpdates;
         int TreeDepth = 0;
         int maxDepth = 
Integer.parseInt(analyzer.getCommandLineArguments().getMaxDepth());
         int mark = 0;
@@ -136,15 +135,20 @@ public class DBFuzzer
             {
                 if(currentMutation.getChosenChange() != null)
                 {
-                    nbUpdates = 
currentMutation.inject(analyzer.getSqlService(),analyzer.getDb(),false);
+                    int nbUpdates = 
currentMutation.inject(analyzer.getSqlService(),analyzer.getDb(),false);
                     if(nbUpdates > 0)
                     {
                         LOGGER.info("GenericTreeNode was sucessfull");
+                        currentMutation.updatePotentialChangeAfterInjection();
                         mutationTree.addToTree(currentMutation);
                     }
-                    else
+                    else if (nbUpdates == 0 || nbUpdates == -1)
                     {
-                        LOGGER.info("QueryError. This update affected 0 
rows.");
+                        if(nbUpdates == 0)
+                            LOGGER.info("QueryError. This update affected 0 
rows.");
+                        else
+                            LOGGER.info("GenericTreeNode was sucessfull");
+
                         
if(!currentMutation.getParent().compare(mutationTree.getLastMutation()))
                         {
                             try
diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java 
b/src/main/java/org/schemaspy/model/GenericTreeNode.java
index 7bc0d17..09f00c1 100644
--- a/src/main/java/org/schemaspy/model/GenericTreeNode.java
+++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java
@@ -332,28 +332,44 @@ public class GenericTreeNode {
         return oneChange;
     }
 
-    public int inject(SqlService sqlService, Database db, boolean undo) {
-        String theQuery = "";
-        if (undo)
-            System.out.println("UNDOING");
-        else
-            System.out.println("INJECT");
-        if (checkIfHasParentFk(db)) {
-            System.out.println("TRANSFERT");
-            transferMutationToParent(db, sqlService);
-        }
+    public int inject(SqlService sqlService, Database db, boolean undo)
+    {
+            boolean transfered = false;
+            String theQuery = "";
+            if (undo)
+                System.out.println("UNDOING");
+            else
+                System.out.println("INJECT");
+            if (checkIfHasParentFk(db)) {
+                transfered = true;
+                System.out.println("TRANSFERT");
+                transferMutationToParent(db, sqlService);
+            }
+
+            theQuery = updateQueryBuilder(undo, db, sqlService);
+            try
+            {
+                Statement stmt = sqlService.getConnection().createStatement();
+                int nbUpdates = stmt.executeUpdate(theQuery);
+                if(transfered && nbUpdates > 0)
+                    return -1;
+                return nbUpdates;
+            }
+            catch (Exception e)
+            {
+                if(!e.getMessage().contains("unique constraint")) {
+                    e.printStackTrace(); // TransfertToMutation Modifies the 
tree and provoques the happenning of 2 do's on one single mutation during 
undoToMutation.
+                    return 0;
+                }
+                else {
+                    System.out.println("Value already in use");
+                    return 0;
+                }
+            }
 
-        theQuery = updateQueryBuilder(undo, db, sqlService);
-        try {
-            Statement stmt = sqlService.getConnection().createStatement();
-            int nbUpdates = stmt.executeUpdate(theQuery);
-            return nbUpdates;
-        } catch (Exception e) {
-            e.printStackTrace(); // TransfertToMutation Modifies the tree and 
provoques the happenning of 2 do's on one single mutation during undoToMutation.
-            return 0;
-        }
     }
 
+
     public void initPostChangeRow() {
         this.post_change_row = this.initial_state_row.myClone();
         
this.post_change_row.setValueOfColumn(chosenChange.getParentTableColumn().getName(),
 chosenChange.getNewValue());
@@ -489,15 +505,23 @@ public class GenericTreeNode {
         if(goingUp.contains(parent) && goingDown.isEmpty())
             goingUp.remove(parent);
 
-        for (GenericTreeNode node : goingUp) {
-            if (node.undo(analyzer.getSqlService(), analyzer.getDb()) > 0)
-                System.out.println("success undoing :"+node.getId());
-        }
+        try
+        {
+            for (GenericTreeNode node : goingUp) {
+                if (node.undo(analyzer.getSqlService(), analyzer.getDb()) > 0)
+                    System.out.println("success undoing :" + node.getId());
+            }
 
-        for (GenericTreeNode node : goingDown) {
-            if (node.inject(analyzer.getSqlService(), analyzer.getDb(), false) 
> 0)
-                System.out.println("success doing :"+node.getId());
+            for (GenericTreeNode node : goingDown) {
+                if (node.inject(analyzer.getSqlService(), analyzer.getDb(), 
false) > 0)
+                    System.out.println("success doing :" + node.getId());
 
+            }
+        }
+
+        catch(Exception e)
+        {
+            System.out.println(e.toString());
         }
 
         return true;
@@ -707,7 +731,7 @@ public class GenericTreeNode {
 
         semiQuery = "SELECT * FROM " + 
chosenChange.getParentTableColumn().getTable().getName();
 
-        setInitial_state_row(response.getRows().get(0),sqlService); // Crashes 
sometimes due to 0 row found. to be fixed.
+        setInitial_state_row(response.getRows().get(0),sqlService); // Crashes 
sometimes due to 0 row found. to be fixed. Update: doesnt SEEM to crash amymore.
 
         if (requireQuotes(chosenChange.getParentTableColumn()) == 1) {
             semiQuery = semiQuery + " WHERE " + 
chosenChange.getParentTableColumn().getName() + "= '" + 
chosenChange.getNewValue() + " '";
@@ -719,17 +743,7 @@ public class GenericTreeNode {
         response = fetchingDataFromDatabase(semiQuery, 
chosenChange.getParentTableColumn().getTable(), sqlService);
 
         if (!response.getRows().isEmpty()) {
-            String columnName = chosenChange.getParentTableColumn().getName();
-            String tableName = 
chosenChange.getParentTableColumn().getTable().getName();
-
-            semiQuery = "SELECT * FROM ( SELECT  1 AS " + columnName + " ) q1 
WHERE NOT EXISTS ( SELECT  1 FROM " + tableName + " WHERE   " + columnName + " 
= 1) " +
-                    "UNION ALL SELECT  * FROM    ( SELECT  " + columnName + " 
+ 1 FROM " + tableName + " t WHERE NOT EXISTS ( SELECT  1 FROM " + tableName + 
" ti WHERE ti." + columnName + " = t." + columnName + " + 1) " +
-                    "ORDER BY " + columnName + " LIMIT 1) q2 LIMIT 1";
-
-            response = fetchingDataFromDatabase(semiQuery, 
chosenChange.getParentTableColumn().getTable(), sqlService);
-
-            
chosenChange.setNewValue(response.getRows().get(0).getValueOfColumn(columnName));
-            initPostChangeRow();
+            handleAlreadySetValue(sqlService);
         }
     }
 
@@ -758,7 +772,7 @@ public class GenericTreeNode {
             {
                 String semiQuery = "SELECT * FROM " + 
sg.getParentTableColumn().getTable().getName();
                 if (requireQuotes(sg.getParentTableColumn()) == 1)
-                    semiQuery = semiQuery + " WHERE " + 
sg.getParentTableColumn().getName() + "= '" + sg.getNewValue() + " '";
+                    semiQuery = semiQuery + " WHERE " + 
sg.getParentTableColumn().getName() + "=' " + sg.getNewValue() + " '";
                 else
                     semiQuery = semiQuery + " WHERE " + 
sg.getParentTableColumn().getName() + "=" + sg.getNewValue();
 
@@ -816,4 +830,30 @@ public class GenericTreeNode {
         return false;
     }
 
+    public void updatePotentialChangeAfterInjection()
+    {
+        for(SingleChange sg : potential_changes)
+        {
+            
if(sg.getOldValue().equals(initial_state_row.getValueOfColumn(sg.getParentTableColumn().getName())))
+            {
+                
sg.setOldValue(post_change_row.getValueOfColumn(sg.getParentTableColumn().getName()));
+            }
+        }
+    }
+
+    public void handleAlreadySetValue(SqlService sqlService)
+    {
+        String columnName = chosenChange.getParentTableColumn().getName();
+        String tableName = 
chosenChange.getParentTableColumn().getTable().getName();
+
+        String semiQuery = "SELECT * FROM ( SELECT  1 AS " + columnName + " ) 
q1 WHERE NOT EXISTS ( SELECT  1 FROM " + tableName + " WHERE   " + columnName + 
" = 1) " +
+                "UNION ALL SELECT  * FROM    ( SELECT  " + columnName + " + 1 
FROM " + tableName + " t WHERE NOT EXISTS ( SELECT  1 FROM " + tableName + " ti 
WHERE ti." + columnName + " = t." + columnName + " + 1) " +
+                "ORDER BY " + columnName + " LIMIT 1) q2 LIMIT 1";
+
+        QueryResponse response = fetchingDataFromDatabase(semiQuery, 
chosenChange.getParentTableColumn().getTable(), sqlService);
+
+        
chosenChange.setNewValue(response.getRows().get(0).getValueOfColumn(columnName));
+        initPostChangeRow();
+    }
+
 }
diff --git a/src/main/java/org/schemaspy/model/SingleChange.java 
b/src/main/java/org/schemaspy/model/SingleChange.java
index a628713..fefb651 100644
--- a/src/main/java/org/schemaspy/model/SingleChange.java
+++ b/src/main/java/org/schemaspy/model/SingleChange.java
@@ -18,7 +18,12 @@ public class SingleChange
                this.newValue = newValue;
        }
 
-  public boolean respectsConstraints()
+
+    public void setOldValue(Object oldValue) {
+        this.oldValue = oldValue;
+    }
+
+    public boolean respectsConstraints()
   {
     switch (parentTableColumn.getTypeName())
     {
diff --git a/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java 
b/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java
index b24242b..5a696bd 100644
--- a/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java
+++ b/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java
@@ -179,7 +179,7 @@ public class GenericTreeNodeTest extends 
AbstractTestExecutionListener {
     public void injectAndUndoConsistencyTest() throws Exception
     {
 
-        PreparedStatement stmt = sqlService.prepareStatement("SELECT * FROM 
actual_test_table WHERE address_id=1", database, null);
+        PreparedStatement stmt = sqlService.prepareStatement("SELECT * FROM 
actual_test_table WHERE address_id=0", database, null);
         ResultSet rs = stmt.executeQuery();
         QueryResponseParser parser = new QueryResponseParser();
         QueryResponse response = 
parser.parse(rs,database.getTablesMap().get("actual_test_table"));

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]