From e206016ad846e85e8822fbb3b59f6a5db05e80ec Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 12 Apr 2017 13:03:54 +0900 Subject: [PATCH] test --- pom.xml | 4 +- .../overflow/crawler/sql/SQLCrawler.java | 46 +++------------- .../overflow/crawler/sql/TargetInfo.java | 53 ------------------- .../java/com/loafle/overflow/AppTest.java | 36 ++++++++++++- 4 files changed, 44 insertions(+), 95 deletions(-) delete mode 100644 src/main/java/com/loafle/overflow/crawler/sql/TargetInfo.java diff --git a/pom.xml b/pom.xml index 9ae4a3a..99628f8 100644 --- a/pom.xml +++ b/pom.xml @@ -11,10 +11,8 @@ com.loafle.overflow - crawler.sql - jar + crawler_sql 1.0.0-SNAPSHOT - com.loafle.overflow.crawler.sql diff --git a/src/main/java/com/loafle/overflow/crawler/sql/SQLCrawler.java b/src/main/java/com/loafle/overflow/crawler/sql/SQLCrawler.java index d1ffb33..422f9ed 100644 --- a/src/main/java/com/loafle/overflow/crawler/sql/SQLCrawler.java +++ b/src/main/java/com/loafle/overflow/crawler/sql/SQLCrawler.java @@ -15,55 +15,25 @@ public class SQLCrawler extends Crawler { public SQLCrawler() {} - @Override - protected Object getInternal(Map config) { - TargetInfo info = getTargetInfo(config.get("id").toString()); - return getMetrics(info); + public Object getInternal(Map config) { + return getMetrics(config); } - private TargetInfo getTargetInfo(String id) { - TargetInfo info = new TargetInfo(); -// //MySQL -// info.setUrl("jdbc:mysql://192.168.1.215:3306"); // ?useSSL=true&verifyServerCertificate=false -// info.setId("root"); -// info.setPw("qwe123"); -// info.setSSL(false); -// info.setQuery("show session status"); -// //MSSQL - info.setUrl("jdbc:sqlserver://192.168.1.103:1433;integratedSecurity=SSPI;encrypt=false;trustServerCertificate=true"); - info.setId("sa"); - info.setPw("qwer5795"); - info.setSSL(true); - info.setQuery("select * from master.dbo.sysprocesses"); -// //PGSQL -// info.setUrl("jdbc:postgresql://192.168.1.107:5432/postgres"); -// info.setId("postgres"); -// info.setPw("!@#$qwer1234"); -// info.setSSL(false); -// info.setQuery("select * from pg_stat_activity"); -// //Oracle -// info.setUrl("jdbc:oracle:thin:@192.168.1.30:1521/oracle.loafle.com"); -// info.setId("sys as sysdba"); -// info.setPw("qwer5795QWER"); -// info.setSSL(false); -// info.setQuery("select * from v$sysstat"); - - return info; - } - - private List> getMetrics(TargetInfo info) { + private List> getMetrics(Map config) { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { - - conn = DriverManager.getConnection(info.getUrl(),info.getId(), info.getPw()); + conn = DriverManager.getConnection( + (String)config.get("url"), + (String)config.get("user"), + (String)config.get("pw")); stmt = conn.createStatement(); - rs = stmt.executeQuery(info.getQuery()); + rs = stmt.executeQuery((String)config.get("query")); ResultSetMetaData md = rs.getMetaData(); int cnt = md.getColumnCount(); diff --git a/src/main/java/com/loafle/overflow/crawler/sql/TargetInfo.java b/src/main/java/com/loafle/overflow/crawler/sql/TargetInfo.java deleted file mode 100644 index f83aba6..0000000 --- a/src/main/java/com/loafle/overflow/crawler/sql/TargetInfo.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.loafle.overflow.crawler.sql; - -/** - * Created by insanity on 17. 4. 11. - */ -public class TargetInfo { - - private String url; - private String id; - private String pw; - private Boolean isSSL; - private String query; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getPw() { - return pw; - } - - public void setPw(String pw) { - this.pw = pw; - } - - public Boolean getSSL() { - return isSSL; - } - - public void setSSL(Boolean SSL) { - isSSL = SSL; - } - - public String getQuery() { - return query; - } - - public void setQuery(String query) { - this.query = query; - } -} diff --git a/src/test/java/com/loafle/overflow/AppTest.java b/src/test/java/com/loafle/overflow/AppTest.java index 1f448ab..dd52e30 100644 --- a/src/test/java/com/loafle/overflow/AppTest.java +++ b/src/test/java/com/loafle/overflow/AppTest.java @@ -1,17 +1,51 @@ package com.loafle.overflow; +import com.loafle.overflow.crawler.Crawler; import com.loafle.overflow.crawler.sql.SQLCrawler; import org.junit.Test; +import java.util.HashMap; import java.util.List; import java.util.Map; public class AppTest { +// //MySQL +// info.setUrl("jdbc:mysql://192.168.1.215:3306"); // ?useSSL=true&verifyServerCertificate=false +// info.setId("root"); +// info.setPw("qwe123"); +// info.setSSL(false); +// info.setQuery("show session status"); +// //MSSQL +// info.setUrl("jdbc:sqlserver://192.168.1.103:1433;"); //encrypt=false;trustServerCertificate=true" +// info.setId("sa"); +// info.setPw("qwer5795"); +// info.setSSL(true); +// info.setQuery("select * from master.dbo.sysprocesses"); +// //PGSQL +// info.setUrl("jdbc:postgresql://192.168.1.107:5432/postgres"); +// info.setId("postgres"); +// info.setPw("!@#$qwer1234"); +// info.setSSL(false); +// info.setQuery("select * from pg_stat_activity"); +// //Oracle +// info.setUrl("jdbc:oracle:thin:@192.168.1.30:1521/oracle.loafle.com"); +// info.setId("sys as sysdba"); +// info.setPw("qwer5795QWER"); +// info.setSSL(false); +// info.setQuery("select * from v$sysstat"); + @Test public void testSQL() { SQLCrawler sc = new SQLCrawler(); - List> result = (List>)sc.get("1111"); + Map config = new HashMap(); + config.put("url", "jdbc:mysql://192.168.1.215:3306"); + config.put("user", "root"); + config.put("pw", "qwe123"); + config.put("ssl", false); + config.put("query", "show session status"); + + List> result = (List>)sc.getInternal(config); for(Map m : result) { for (Map.Entry entry : m.entrySet()) {