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: Implemented Maxde


From: gnunet
Subject: [GNUnet-SVN] [taler-schemafuzz] branch master updated: Implemented Maxdepth as ending condition for main loop. added a test for MutationTree.
Date: Mon, 28 May 2018 14:22:55 +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 449b4e7  Implemented Maxdepth as ending condition for main loop. added 
a test for MutationTree.
449b4e7 is described below

commit 449b4e7b3c6797c98a5f766c409974d4ca62ea84
Author: Feideus <address@hidden>
AuthorDate: Mon May 28 14:22:50 2018 +0200

    Implemented Maxdepth as ending condition for main loop. added a test for 
MutationTree.
---
 TODO.txt                                           |   5 +-
 aLittleBitLessDumbEvaluator.sh                     |   6 -
 src/main/java/org/schemaspy/DBFuzzer.java          |   7 +-
 src/main/java/org/schemaspy/SchemaAnalyzer.java    |   5 +
 .../org/schemaspy/cli/CommandLineArguments.java    |  10 ++
 src/main/java/org/schemaspy/model/GenericTree.java |  17 +++
 .../java/org/schemaspy/model/GenericTreeTest.java  | 124 +++++++++++++++++++++
 7 files changed, 166 insertions(+), 8 deletions(-)

diff --git a/TODO.txt b/TODO.txt
index 9f602f1..4dcbc01 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -3,5 +3,8 @@ MANUAL FOR USE
 WEBSITE
 TEST CASES/ UNIT TESTING INTEGRATION TESTING
 VARCHAR CLASSIFIER (LATER)
- 
+ADD DEPTH TO COMMAND LINE OPTIONS AS ENDING CONDITION FOR MAIN LOOP
+ADD MULTI TABLE/ROW SUPPORT TO THE TREE
+MORE TYPES
+MORE DB TYPES  
 
diff --git a/aLittleBitLessDumbEvaluator.sh b/aLittleBitLessDumbEvaluator.sh
index 18cefb0..c27483d 100644
--- a/aLittleBitLessDumbEvaluator.sh
+++ b/aLittleBitLessDumbEvaluator.sh
@@ -7,12 +7,6 @@ RESULT=$( echo $RESULT | cut -d "-" -f 2 )
 RESULT=$( echo $RESULT | cut -d "(" -f1 )
 IFS=' | ' read -ra array <<< "$RESULT"
 
-echo $RESULT
-echo ${array[0]}
-echo ${array[1]}
-echo ${array[2]}
-echo ${array[3]}
-
 SCORE=0
 
 if [[ ${array[0]} = "t" && "${array[1]}" = "t" && "${array[2]}" = "t" && 
"${array[3]}" = "t" ]]
diff --git a/src/main/java/org/schemaspy/DBFuzzer.java 
b/src/main/java/org/schemaspy/DBFuzzer.java
index 150acee..cf62f06 100644
--- a/src/main/java/org/schemaspy/DBFuzzer.java
+++ b/src/main/java/org/schemaspy/DBFuzzer.java
@@ -77,6 +77,9 @@ public class DBFuzzer
     {
         boolean returnStatus = true;
         boolean resQuery;
+        int TreeDepth = 0;
+        int maxDepth = 
Integer.parseInt(analyzer.getCommandLineArguments().getMaxDepth());
+        System.out.println(maxDepth);
         int mark = 0;
         //adding CASCADE to all foreign key tableColumns.
         settingTemporaryCascade(false); // need to drop and recreate database
@@ -97,7 +100,7 @@ public class DBFuzzer
         * After injecting and retrieving the marking for the evaluator,
         * undoes necessary mutations from the tree to setup for next mutation
         */
-        while(mark != -2)
+        while(TreeDepth != maxDepth)
         {
           //Choosing next mutation
           currentMutation = chooseNextMutation();
@@ -160,6 +163,7 @@ public class DBFuzzer
                 e.printStackTrace();
                 returnStatus = false;
             }
+            TreeDepth = mutationTree.checkMaxDepth(mutationTree.getRoot());
       }
 
       System.out.println("success");
@@ -363,4 +367,5 @@ public class DBFuzzer
       return res;
     }
 
+    
 }
diff --git a/src/main/java/org/schemaspy/SchemaAnalyzer.java 
b/src/main/java/org/schemaspy/SchemaAnalyzer.java
index 66931ef..212301c 100644
--- a/src/main/java/org/schemaspy/SchemaAnalyzer.java
+++ b/src/main/java/org/schemaspy/SchemaAnalyzer.java
@@ -50,6 +50,8 @@ public class SchemaAnalyzer {
 
     private Database db;
 
+
+
     private final CommandLineArguments commandLineArguments;
 
     public SchemaAnalyzer(SqlService sqlService, DatabaseService 
databaseService, CommandLineArguments commandLineArguments) {
@@ -200,6 +202,9 @@ public class SchemaAnalyzer {
         }
     }
 
+    public CommandLineArguments getCommandLineArguments() {
+        return commandLineArguments;
+    }
 
     private Connection getConnection(Config config) throws IOException {
 
diff --git a/src/main/java/org/schemaspy/cli/CommandLineArguments.java 
b/src/main/java/org/schemaspy/cli/CommandLineArguments.java
index e3a4800..0cc3b69 100644
--- a/src/main/java/org/schemaspy/cli/CommandLineArguments.java
+++ b/src/main/java/org/schemaspy/cli/CommandLineArguments.java
@@ -116,6 +116,13 @@ public class CommandLineArguments {
     )
     private String query;
 
+    @Parameter(
+            names = {
+                    "-mx", "--maxDepth",
+            }
+    )
+    private String maxDepth;
+
     /* TODO Password handling is more complex, see Config class (prompt for 
password, fallback to Environment variable, multiple schemas, etc.)
     @Parameter(
             names = {
@@ -200,4 +207,7 @@ public class CommandLineArguments {
     public Integer getPort() {
         return port;
     }
+
+    public String getMaxDepth() { return maxDepth; }
+
 }
diff --git a/src/main/java/org/schemaspy/model/GenericTree.java 
b/src/main/java/org/schemaspy/model/GenericTree.java
index ea53bd1..e89feb0 100644
--- a/src/main/java/org/schemaspy/model/GenericTree.java
+++ b/src/main/java/org/schemaspy/model/GenericTree.java
@@ -103,4 +103,21 @@ public class GenericTree {
         }
         return res; // should never be null unless the algorithm is not 
looking for something precise
     }
+
+    public int checkMaxDepth(GenericTreeNode root)
+    {
+        int res = 0;
+
+        if(root.getChildren().isEmpty())
+            return root.getDepth();
+
+        for(GenericTreeNode child :root.getChildren())
+        {
+            int tmp = checkMaxDepth(child);
+            if(tmp > res)
+                res = tmp;
+        }
+
+        return res;
+    }
 }
diff --git a/src/test/java/org/schemaspy/model/GenericTreeTest.java 
b/src/test/java/org/schemaspy/model/GenericTreeTest.java
new file mode 100644
index 0000000..5d66b6f
--- /dev/null
+++ b/src/test/java/org/schemaspy/model/GenericTreeTest.java
@@ -0,0 +1,124 @@
+package org.schemaspy.model;
+
+import nl.jqno.equalsverifier.internal.exceptions.AssertionException;
+import org.junit.*;
+import org.junit.rules.ExternalResource;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.schemaspy.Config;
+import org.schemaspy.cli.CommandLineArguments;
+import org.schemaspy.service.DatabaseService;
+import org.schemaspy.service.SqlService;
+import org.schemaspy.util.CaseInsensitiveMap;
+import org.springframework.beans.factory.annotation.Autowired;
+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.junit4.SpringRunner;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Random;
+
+
address@hidden(SpringRunner.class)
address@hidden
+public class GenericTreeTest {
+
+    @Autowired
+    private SqlService sqlService;
+    @Autowired
+    private DatabaseService databaseService;
+    private Database database;
+    @Mock
+    private ProgressListener progressListener;
+    @MockBean
+    private CommandLineArguments arguments;
+    @MockBean
+    private CommandLineRunner commandLineRunner;
+
+    @Test
+    public void checkMaxDepthTest() throws Exception
+    {
+
+        String[] args = {
+                "-t", "pgsql",
+                "-db","sample_database2",
+                "-hostOptionalPort","127.0.0.1",
+                "-o", "target/integrationtesting/databaseServiceIT",
+                "-dp","postgresql-42.2.2.jar",
+                "-u", "feideus",
+                "-p", "feideus"
+        };
+
+        Config config = new Config(args);
+        DatabaseMetaData databaseMetaData = sqlService.connect(config);
+        String schema = sqlService.getConnection().getSchema();
+        String catalog = sqlService.getConnection().getCatalog();
+        Database database = new Database(
+                databaseMetaData,
+                "DatabaseServiceIT",
+                catalog,
+                schema,
+                null
+        );
+        databaseService.gatheringSchemaDetails(config, database, 
progressListener);
+
+
+        PreparedStatement stmt = sqlService.prepareStatement("SELECT * FROM 
test_table", database, null);
+        ResultSet rs = stmt.executeQuery();
+        QueryResponseParser parser = new QueryResponseParser();
+        QueryResponse response = 
parser.parse(rs,database.getTablesMap().get("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();
+
+        GenericTree tree = new GenericTree();
+
+        GenericTreeNode tmpMutation = new GenericTreeNode(row,1);
+        tmpMutation.setChosenChange(tmpMutation.getPotential_changes().get(0));
+        tmpMutation.setDepth(0);
+
+        GenericTreeNode tmpMutation2 = new GenericTreeNode(row2,2);
+        
tmpMutation2.setChosenChange(tmpMutation.getPotential_changes().get(0));
+        tmpMutation2.setDepth(1);
+
+        GenericTreeNode tmpMutation3 = new GenericTreeNode(row3,3);
+        
tmpMutation3.setChosenChange(tmpMutation.getPotential_changes().get(0));
+        tmpMutation3.setDepth(2);
+
+        GenericTreeNode tmpMutation4 = new GenericTreeNode(row4,4);
+        
tmpMutation4.setChosenChange(tmpMutation.getPotential_changes().get(0));
+        tmpMutation4.setDepth(1);
+
+        GenericTreeNode tmpMutation5 = new GenericTreeNode(row5,5);
+        
tmpMutation4.setChosenChange(tmpMutation.getPotential_changes().get(0));
+        tmpMutation4.setDepth(3);
+
+        GenericTreeNode tmpMutation6 = new GenericTreeNode(row6,6);
+        
tmpMutation6.setChosenChange(tmpMutation.getPotential_changes().get(0));
+        tmpMutation6.setDepth(4);
+
+
+        tmpMutation.addChild(tmpMutation2);
+        tmpMutation.addChild(tmpMutation4);
+        tmpMutation2.addChild(tmpMutation3);
+        tmpMutation3.addChild(tmpMutation4);
+        tmpMutation4.addChild(tmpMutation5);
+        tmpMutation5.addChild(tmpMutation6);
+
+        tree.setRoot(tmpMutation);
+
+        Assert.assertEquals(tree.checkMaxDepth(tree.getRoot()) , 4);
+
+    }
+
+}
+

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



reply via email to

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