diff options
author | Feideus <erwan.ulrich@gmail.com> | 2018-06-20 18:45:52 +0200 |
---|---|---|
committer | Feideus <erwan.ulrich@gmail.com> | 2018-06-20 18:45:52 +0200 |
commit | 79a2c8ad1620fa4ec2b4381338297f61810ef042 (patch) | |
tree | c93abe01590657abf5ed5b9fa36105fa631dd046 /src | |
parent | b14408b4a85380c900fc8f508d6903b27ebd2061 (diff) | |
download | schemafuzz-79a2c8ad1620fa4ec2b4381338297f61810ef042.tar.gz schemafuzz-79a2c8ad1620fa4ec2b4381338297f61810ef042.tar.bz2 schemafuzz-79a2c8ad1620fa4ec2b4381338297f61810ef042.zip |
Transfer makes two do's happen. pathFinding fixed. Still working.
Diffstat (limited to 'src')
4 files changed, 34 insertions, 31 deletions
diff --git a/src/main/java/org/schemaspy/DBFuzzer.java b/src/main/java/org/schemaspy/DBFuzzer.java index 1090e2c..7c306c8 100644 --- a/src/main/java/org/schemaspy/DBFuzzer.java +++ b/src/main/java/org/schemaspy/DBFuzzer.java @@ -143,7 +143,21 @@ public class DBFuzzer mutationTree.addToTree(currentMutation); } else - LOGGER.info("QueryError. This update affected 0 rows"); + { + LOGGER.info("QueryError. This update affected 0 rows."); + if(!currentMutation.getParent().compare(mutationTree.getLastMutation())) + { + try + { + currentMutation.getParent().undoToMutation(mutationTree.getLastMutation(),analyzer); + + } + catch(Exception e) + { + e.printStackTrace(); + } + } + } } } catch(Exception e) @@ -333,7 +347,7 @@ public class DBFuzzer } else { - Random changeOrDepthen = new Random(); // 1 is same row + Random changeOrDepthen = new Random(); // 1 inside tree, 2 is pick new random row if(changeOrDepthen.nextInt(2) == 1) { diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java b/src/main/java/org/schemaspy/model/GenericTreeNode.java index 9e02bc6..7bc0d17 100644 --- a/src/main/java/org/schemaspy/model/GenericTreeNode.java +++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java @@ -187,10 +187,9 @@ public class GenericTreeNode { public void setChosenChange(SingleChange sc) { this.chosenChange = sc; this.chosenChange.getAttachedToMutation().getPotential_changes().remove(chosenChange); - this.getPotential_changes().add(sc); this.chosenChange.setAttachedToMutation(this); - assert(sc.getAttachedToMutation().equals(this.getId())); + assert(sc.getAttachedToMutation().getId().equals(this.getId())); } /** @@ -350,7 +349,7 @@ public class GenericTreeNode { int nbUpdates = stmt.executeUpdate(theQuery); return nbUpdates; } catch (Exception e) { - System.out.println("Error ! : Mutation Canceled" + e); // temporerally putting aside the Unique constraint brought by the transfertToParent Mechanic + e.printStackTrace(); // TransfertToMutation Modifies the tree and provoques the happenning of 2 do's on one single mutation during undoToMutation. return 0; } } @@ -403,7 +402,9 @@ public class GenericTreeNode { theQuery = theQuery + (entry.getKey() + "='" + entry.getValue().toString() + "' AND "); else theQuery = theQuery + (entry.getKey() + " IS NULL AND "); - } else { + } + else + { if (entry.getValue() != null) theQuery = theQuery + (entry.getKey() + "=" + entry.getValue().toString() + " AND "); else @@ -413,9 +414,9 @@ public class GenericTreeNode { } else { if (undo) - theQuery = theQuery + (entry.getKey() + "='" + chosenChange.getNewValue().toString() + "' AND "); + theQuery = theQuery + (entry.getKey() + "='" + post_change_row.getContent().get(entry.getKey()) + "' AND "); else - theQuery = theQuery + (entry.getKey() + "='" + chosenChange.getOldValue().toString() + "' AND "); + theQuery = theQuery + (entry.getKey() + "='" + initial_state_row.getContent().get(entry.getKey()) + "' AND "); } } try { @@ -483,20 +484,19 @@ public class GenericTreeNode { public boolean undoToMutation(GenericTreeNode target, SchemaAnalyzer analyzer) { ArrayList<GenericTreeNode> goingUp = findPathToMutation(target).get(0); - goingUp.remove(this.getParent()); ArrayList<GenericTreeNode> goingDown = findPathToMutation(target).get(1); - if(goingUp.contains(parent)) + 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"); + 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"); + if (node.inject(analyzer.getSqlService(), analyzer.getDb(), false) > 0) + System.out.println("success doing :"+node.getId()); } @@ -560,7 +560,6 @@ public class GenericTreeNode { tmpThis = tmpThis.getParent(); tmpTarget = tmpTarget.getParent(); } - thisPath.add(tmpThis); // tmpThis and tmpTarget are equals, so add the commun ancestor Collections.reverse(targetPath); finalPath.add(thisPath); //way up diff --git a/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java b/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java index 8b06778..b24242b 100644 --- a/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java +++ b/src/test/java/org/schemaspy/model/GenericTreeNodeTest.java @@ -15,16 +15,12 @@ import org.junit.Test; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.TestContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.support.AbstractTestExecutionListener; import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.HashMap; import java.util.Random; @@ -78,7 +74,6 @@ public class GenericTreeNodeTest extends AbstractTestExecutionListener { } } - @Ignore @Test public void WeightPropagationTest() throws Exception { @@ -121,7 +116,6 @@ public class GenericTreeNodeTest extends AbstractTestExecutionListener { } - @Ignore @Test public void SingleChangeBasedOnWeightShouldNotReturnNull() throws Exception { @@ -147,7 +141,6 @@ public class GenericTreeNodeTest extends AbstractTestExecutionListener { Assert.assertNotNull(tmpMutation3.singleChangeBasedOnWeight()); } - @Ignore @Test public void singleChangeAttachedMutationShouldMatch() throws Exception// Not very Usefull { @@ -167,7 +160,6 @@ public class GenericTreeNodeTest extends AbstractTestExecutionListener { } - @Ignore @Test public void NoNullMutationPossibilitiesTest() throws Exception { @@ -183,7 +175,6 @@ public class GenericTreeNodeTest extends AbstractTestExecutionListener { } - @Ignore @Test public void injectAndUndoConsistencyTest() throws Exception { @@ -217,7 +208,6 @@ public class GenericTreeNodeTest extends AbstractTestExecutionListener { } - @Ignore @Test public void compareTest() throws Exception { @@ -228,7 +218,7 @@ public class GenericTreeNodeTest extends AbstractTestExecutionListener { QueryResponse response = parser.parse(rs,database.getTablesMap().get("actual_test_table")); Row row = response.getRows().get(0); - Row row2 = row.clone(); + Row row2 = row.myClone(); GenericTreeNode tmpMutation1 = new GenericTreeNode(response.getRows().get(0),1,sqlService); tmpMutation1.setChosenChange(tmpMutation1.getPotential_changes().get(0)); diff --git a/src/test/java/org/schemaspy/model/GenericTreeTest.java b/src/test/java/org/schemaspy/model/GenericTreeTest.java index 5a8e692..3057f20 100644 --- a/src/test/java/org/schemaspy/model/GenericTreeTest.java +++ b/src/test/java/org/schemaspy/model/GenericTreeTest.java @@ -75,11 +75,11 @@ public class GenericTreeTest { QueryResponse response = parser.parse(rs,database.getTablesMap().get("actual_test_table")); Row row = response.getRows().get(0); - Row row2 = row.clone(); - Row row3 = row.clone(); - Row row4 = row.clone(); - Row row5 = row.clone(); - Row row6 = row.clone(); + Row row2 = row.myClone(); + Row row3 = row.myClone(); + Row row4 = row.myClone(); + Row row5 = row.myClone(); + Row row6 = row.myClone(); GenericTree tree = new GenericTree(); |