// Path: neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/data/PerformanceTestData.java
// public class PerformanceTestData {
// 
//     public static final String NEO_URL = "jdbc:neo4j:bolt://localhost:7687?user=neo4j,password=test";
// 
//     /**
//      * Get a new connection to the external database
//      * @return
//      * @throws SQLException
//      */
//     public static Connection getConnection() throws SQLException {
//         return DriverManager.getConnection(NEO_URL);
//     }
// 
//     /**
//      * Fill, if needed, the test random data.
//      * (:A)-[:X]->(:B)-[:Y]->(:C)
//      * @return true if the DB was empty and the load run
//      * @throws SQLException
//      */
//     public static boolean loadABCXYData() throws SQLException {
//         Connection conn = getConnection();
//         Statement stmt = conn.createStatement();
//         ResultSet rs = stmt.executeQuery("MATCH (n) RETURN n LIMIT 1");
//         boolean hasDataLoaded = rs.next();
//         rs.close();
//         if(hasDataLoaded){
//             Statement stmtCheck = conn.createStatement();
//             ResultSet checkRs = stmtCheck.executeQuery("MATCH (x:PerformanceTestData) RETURN x LIMIT 1");
//             boolean hasTestDataLoaded = checkRs.next();
//             if(!hasTestDataLoaded){
//                 throw new IllegalStateException("The database is loaded without test data. Make sure you are using the correct db at "+NEO_URL);
//             }
//             stmtCheck.close();
//         } else{
//             for (int i = 0; i < 100; i++) {
//                 stmt.executeQuery("CREATE (:A {prop:" + (int) (Math.random() * 100) + "})" + (Math.random() * 10 > 5 ?
//                         "-[:X]->(:B {prop:'" + (int) (Math.random() * 100) + "'})" :
//                         ""));
//             }
//             stmt.executeQuery("CREATE (:C)");
//             stmt.executeQuery("MATCH (b:B), (c:C) MERGE (c)<-[:Y]-(b)");
//             stmt.executeQuery("CREATE (x:PerformanceTestData {when: timestamp()})");
//             stmt.close();
//             conn.close();
//         }
// 
//         return !hasDataLoaded;
//     }
// }


import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.neo4j.jdbc.bolt.data.PerformanceTestData;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import java.io.IOException;
import java.sql.*;
/*
 * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it]
 * <p>
 * This file is part of the "LARUS Integration Framework for Neo4j".
 * <p>
 * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * <p>
 * Created on 14/03/16
 */
package org.neo4j.jdbc.bolt;



/**
 * @author AgileLARUS
 * @since 3.3
 * Created by the issue #141
 */
public class ExecutePT {

	@Test public void launchBenchmark() throws Exception {
// Path: neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/data/PerformanceTestData.java
// public class PerformanceTestData {
// 
//     public static final String NEO_URL = "jdbc:neo4j:bolt://localhost:7687?user=neo4j,password=test";
// 
//     /**
//      * Get a new connection to the external database
//      * @return
//      * @throws SQLException
//      */
//     public static Connection getConnection() throws SQLException {
//         return DriverManager.getConnection(NEO_URL);
//     }
// 
//     /**
//      * Fill, if needed, the test random data.
//      * (:A)-[:X]->(:B)-[:Y]->(:C)
//      * @return true if the DB was empty and the load run
//      * @throws SQLException
//      */
//     public static boolean loadABCXYData() throws SQLException {
//         Connection conn = getConnection();
//         Statement stmt = conn.createStatement();
//         ResultSet rs = stmt.executeQuery("MATCH (n) RETURN n LIMIT 1");
//         boolean hasDataLoaded = rs.next();
//         rs.close();
//         if(hasDataLoaded){
//             Statement stmtCheck = conn.createStatement();
//             ResultSet checkRs = stmtCheck.executeQuery("MATCH (x:PerformanceTestData) RETURN x LIMIT 1");
//             boolean hasTestDataLoaded = checkRs.next();
//             if(!hasTestDataLoaded){
//                 throw new IllegalStateException("The database is loaded without test data. Make sure you are using the correct db at "+NEO_URL);
//             }
//             stmtCheck.close();
//         } else{
//             for (int i = 0; i < 100; i++) {
//                 stmt.executeQuery("CREATE (:A {prop:" + (int) (Math.random() * 100) + "})" + (Math.random() * 10 > 5 ?
//                         "-[:X]->(:B {prop:'" + (int) (Math.random() * 100) + "'})" :
//                         ""));
//             }
//             stmt.executeQuery("CREATE (:C)");
//             stmt.executeQuery("MATCH (b:B), (c:C) MERGE (c)<-[:Y]-(b)");
//             stmt.executeQuery("CREATE (x:PerformanceTestData {when: timestamp()})");
//             stmt.close();
//             conn.close();
//         }
// 
//         return !hasDataLoaded;
//     }
// }


// Path: neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/ExecutePT.java
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.neo4j.jdbc.bolt.data.PerformanceTestData;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
import java.io.IOException;
import java.sql.*;

/*
 * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it]
 * <p>
 * This file is part of the "LARUS Integration Framework for Neo4j".
 * <p>
 * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * <p>
 * Created on 14/03/16
 */
package org.neo4j.jdbc.bolt;



/**
 * @author AgileLARUS
 * @since 3.3
 * Created by the issue #141
 */
public class ExecutePT {

	@Test public void launchBenchmark() throws Exception {
		PerformanceTestData.loadABCXYData();