Skip to content

Commit 761d3c0

Browse files
author
Jakub Raczek
authored
Merge pull request #33 from ObjectivityLtd/KeyComparator
Key comparator
2 parents 11189cb + 1d9eba5 commit 761d3c0

69 files changed

Lines changed: 2525 additions & 123 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ If you set JAVA_HOME variable:
1818
```
1919
java -jar DBTestCompare-1.0-SNAPSHOT-jar-with-dependencies.jar
2020
```
21-
21+
or to add automatically all drivers from the directory to the classspath (jdbc_drivers/*)
22+
Windows
23+
```
24+
java -cp "DBTestCompare-1.0-SNAPSHOT-jar-with-dependencies.jar;jdbc_drivers/*" uk.co.objectivity.test.db.RunTests
25+
```
26+
Linux
27+
```
28+
java -cp "DBTestCompare-1.0-SNAPSHOT-jar-with-dependencies.jar:jdbc_drivers/*" uk.co.objectivity.test.db.RunTests
29+
```
2230
or e.g.
2331
```
2432
"C:\Program Files\Java\jdk1.8.0_92\bin\java" -jar DBTestCompare-1.0-SNAPSHOT-jar-with-dependencies.jar
@@ -30,6 +38,7 @@ Application provides following features:
3038
- Supports **all Continuous Integration tools** thanks to TestNG Java unit test framework
3139
- Possibility to compare data between **two different database engines** even for huge data sets
3240
without "Out of memory problem" thanks to incremental solution, more details [here](https://github.com/ObjectivityLtd/DBTestCompare/wiki/Fetch)
41+
- Possibility to compare query to **expected data defined in csv file** and generate **Excel test raport**, more details [here](https://github.com/ObjectivityLtd/DBTestCompare/wiki/KEY)
3342
- Possibility to compare data in **one database engine in the fastest way** using MINUS/EXCEPT Sql operator, more details [here](https://github.com/ObjectivityLtd/DBTestCompare/wiki/Minus)
3443
- **No need to compile program** in order to add new tests - thanks to Test Adapter DataDriven mechanism from TestNG
3544
- Possibility to **execute test in parallel** by setting Threads parameter in connection file.

azure-pipelines.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ steps:
7474
targetPath: './target/test-output'
7575
artifact: 'DBTestCompare$(dBTestCompareVersion).TestResults.$(Build.BuildNumber)'
7676
publishLocation: 'pipeline'
77+
78+
- task: PublishPipelineArtifact@1
79+
inputs:
80+
targetPath: './target/test-definitions'
81+
artifact: 'DBTestCompare$(dBTestCompareVersion).TestDefinitionsResults.$(Build.BuildNumber)'
82+
publishLocation: 'pipeline'
7783

7884
- task: PublishPipelineArtifact@1
7985
inputs:
-2.25 MB
Binary file not shown.
2.3 MB
Binary file not shown.

pom.xml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>uk.co.objectivity.test.db</groupId>
@@ -14,6 +14,9 @@
1414
<log4j.version>2.13.1</log4j.version>
1515
<log4jcore.version>2.13.2</log4jcore.version>
1616
<c3p0.version>0.9.5.5</c3p0.version>
17+
<poi.version>4.1.1</poi.version>
18+
<commons.version>3.9</commons.version>
19+
<sirocco.version>1.0</sirocco.version>
1720
</properties>
1821

1922
<build>
@@ -36,7 +39,7 @@
3639
<manifestEntries>
3740
<!-- TODO all drivers from directory -->
3841
<Class-Path>jdbc_drivers/mssql-jdbc-8.2.0.jre8.jar jdbc_drivers/mssql-jdbc-8.2.0.jre11.jar jdbc_drivers/mssql-jdbc-8.2.0.jre13.jar jdbc_drivers/tdgssconfig-4.jar
39-
jdbc_drivers/terajdbc-4.jar jdbc_drivers/mysql-connector-java-8.0.19.jar
42+
jdbc_drivers/terajdbc-4.jar jdbc_drivers/mysql-connector-java-8.0.23.jar
4043
jdbc_drivers/postgresql-42.2.11.jar jdbc_drivers/mariadb-java-client-2.6.0.jar jdbc_drivers/snowflake-jdbc-3.9.2.jar</Class-Path>
4144
</manifestEntries>
4245
</archive>
@@ -72,7 +75,7 @@
7275
<dependency>
7376
<groupId>org.ow2.sirocco</groupId>
7477
<artifactId>sirocco-text-table-formatter</artifactId>
75-
<version>1.0</version>
78+
<version>${sirocco.version}</version>
7679
</dependency>
7780

7881
<!-- used to create JDBC Connection Pool -->
@@ -91,7 +94,19 @@
9194
<artifactId>log4j-core</artifactId>
9295
<version>${log4jcore.version}</version>
9396
</dependency>
94-
</dependencies>
9597

98+
<!-- used to generate Excel file -->
99+
<dependency>
100+
<groupId>org.apache.poi</groupId>
101+
<artifactId>poi</artifactId>
102+
<version>${poi.version}</version>
103+
</dependency>
104+
105+
<dependency>
106+
<groupId>org.apache.commons</groupId>
107+
<artifactId>commons-lang3</artifactId>
108+
<version>${commons.version}</version>
109+
</dependency>
110+
</dependencies>
96111
</project>
97112

src/main/java/uk/co/objectivity/test/db/DBTestCompare.java

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import uk.co.objectivity.test.db.beans.TestParams;
4545
import uk.co.objectivity.test.db.beans.TestResults;
4646
import uk.co.objectivity.test.db.beans.xml.Compare;
47+
import uk.co.objectivity.test.db.beans.xml.Condition;
4748
import uk.co.objectivity.test.db.utils.Printer;
4849
import uk.co.objectivity.test.db.utils.SavedTimes;
4950
import uk.co.objectivity.test.db.utils.TCMessages;
@@ -82,50 +83,56 @@ public void testSQLResults() {
8283
}
8384
compare = testParams.getCmpSqlResultsTest().getCompare();
8485
testResults = compare.getCompareMode().getComparator().compare(testParams);
86+
if(!testResults.getOutput().isEmpty())
87+
logInfo2All(testResults.getOutput() + "\r\n", tcMsgs);
8588
logInfo2All("Executed query: \r\n" + testResults.getExecutedQuery(), tcMsgs);
8689

8790
// assertions
8891
if (compare.getCompareMode() == CompareMode.NMB_OF_RESULTS) {
89-
List<uk.co.objectivity.test.db.beans.xml.Assert> assertList = compare.getAssertions();
92+
List<Condition> assertList = compare.getAssertions();
9093
if (assertList != null) {
91-
logInfo2All("Rows count:" + testResults.getNmbOfRows(),tcMsgs);
94+
logInfo2All("Rows count:" + testResults.getNmbOfRows(), tcMsgs);
9295
TestResults effFinalTR = testResults;
93-
assertList.forEach(a -> logInfo2All(a.getAssertType().name() + " " + a.getValue(), tcMsgs));
94-
assertList.forEach(a -> a.getAssertType().assertByType(effFinalTR.getNmbOfRows(), a.getValue()));
96+
assertList.forEach(a -> logInfo2All(a.getConditionType().name() + " " + a.getValue(), tcMsgs));
97+
assertList.forEach(a -> a.getConditionType().assertByType(effFinalTR.getNmbOfRows(), a.getValue()));
9598
int p = getIndexByName(testParams.getTestName());
96-
if(p >= 0){
99+
if (p >= 0) {
97100
savedTimesList.get(p).setTestResult("Passed");
98101
}
99102

100103
}
101-
} else if(compare.getCompareMode() == CompareMode.FETCH || compare.getCompareMode() == CompareMode.FILE) {
102-
Assert.assertEquals(testResults.getNmbOfRows(), Integer.valueOf(0),
103-
"Among " + testResults.getNmbOfComparedRows() +
104-
" compared rows, some differences in SQL queries results found - ");
104+
} else if (compare.getCompareMode() == CompareMode.FETCH || compare.getCompareMode() == CompareMode.FILE
105+
|| compare.getCompareMode() == CompareMode.KEY) {
106+
Assert.assertEquals(testResults.getNmbOfRows(), Integer.valueOf(0),
107+
"Among " + testResults.getNmbOfComparedRows()
108+
+ " compared rows, some differences in SQL queries results found - ");
105109
} else {
106-
Assert.assertEquals(testResults.getNmbOfRows(), Integer.valueOf(0),
107-
"Differences in SQL queries found - ");
108-
}
110+
Assert.assertEquals(testResults.getNmbOfRows(), Integer.valueOf(0),
111+
"Differences in SQL queries found - ");
112+
}
109113

110-
if(compare.getCompareMode() == CompareMode.FETCH || compare.getCompareMode() == CompareMode.FILE){
111-
logInfo2All("TEST PASSED, Compared rows:" + testResults.getNmbOfComparedRows(),tcMsgs);
114+
if (compare.getCompareMode() == CompareMode.FETCH || compare.getCompareMode() == CompareMode.FILE
115+
|| compare.getCompareMode() == CompareMode.KEY) {
116+
logInfo2All("TEST PASSED, Compared rows:" + testResults.getNmbOfComparedRows(), tcMsgs);
112117
} else {
113118
logInfo2All("TEST PASSED", tcMsgs);
114119
}
115120

116121
} catch (AssertionError ae) {
117122
String resultsTextTable = null;
118-
if (compare != null && testResults != null && compare.getCompareMode() != CompareMode.NMB_OF_RESULTS &&
119-
compare.getDiffTableSize() > 0) {
123+
if (compare != null && testResults != null && compare.getCompareMode() != CompareMode.NMB_OF_RESULTS
124+
&& compare.getDiffTableSize() > 0) {
120125
resultsTextTable = Printer.getTextTable(testResults);
121126
log.info(resultsTextTable);
122127
}
123128
logFailed2All(ae, tcMsgs, resultsTextTable);
124129
throw ae;
125130
} catch (Exception e) {
126131
logFailed2All(e, tcMsgs, null);
127-
// it would be better to skip tests which configuration is wrong, and fail only those which really fails
128-
// (AssertionError) but fail is more "visible". Maybe user should choose (configuration) if skip or fail
132+
// it would be better to skip tests which configuration is wrong, and fail only
133+
// those which really fails
134+
// (AssertionError) but fail is more "visible". Maybe user should choose
135+
// (configuration) if skip or fail
129136
// on misconfiguration or i.e. DB problems
130137
// throw new SkipException(e.getMessage());
131138
throw new TestException(e);
@@ -136,11 +143,9 @@ public void testSQLResults() {
136143

137144
}
138145

139-
public int getIndexByName(String testName)
140-
{
141-
for(SavedTimes _item : savedTimesList)
142-
{
143-
if(_item.getTestName().equals(testName))
146+
public int getIndexByName(String testName) {
147+
for (SavedTimes _item : savedTimesList) {
148+
if (_item.getTestName().equals(testName))
144149
return savedTimesList.indexOf(_item);
145150
}
146151
return -1;
@@ -159,8 +164,9 @@ private void logFailed2All(Throwable throwable, TCMessages tcMsgs, String additi
159164
}
160165

161166
/**
162-
* For TestNG HTML reports purposes. Without this method it does not display test name provided by getTestName()
163-
* ITest interface). For i.e. Intellij IDEA uses name provided by getTestName() .
167+
* For TestNG HTML reports purposes. Without this method it does not display
168+
* test name provided by getTestName() ITest interface). For i.e. Intellij IDEA
169+
* uses name provided by getTestName() .
164170
*
165171
* @param result - test results
166172
*/
@@ -178,51 +184,52 @@ public void setResultTestName(ITestResult result) {
178184
log.error(ex);
179185
}
180186
}
181-
@AfterSuite
182-
public void displaySavedTimesStatistics(){
187+
188+
@AfterSuite(enabled = false)
189+
public void displaySavedTimesStatistics() {
183190
savedTimesList.sort(Comparator.comparing(SavedTimes::getDuration).reversed());
184-
Map<String, List<SavedTimes>> savedTimesListGrouped =
185-
savedTimesList.stream().collect(Collectors.groupingBy(w -> w.getTestName()));
191+
Map<String, List<SavedTimes>> savedTimesListGrouped = savedTimesList.stream()
192+
.collect(Collectors.groupingBy(w -> w.getTestName()));
186193

187194
CellStyle cs = new CellStyle(CellStyle.HorizontalAlign.left, CellStyle.AbbreviationStyle.crop,
188195
CellStyle.NullStyle.emptyString);
189-
Table t = new Table(5, BorderStyle.DESIGN_TUBES, ShownBorders
190-
.SURROUND_HEADER_AND_COLUMNS, false, "");
196+
Table t = new Table(5, BorderStyle.DESIGN_TUBES, ShownBorders.SURROUND_HEADER_AND_COLUMNS, false, "");
191197
t.addCell("Test Name", cs);
192198
t.addCell("Measure Type", cs);
193199
t.addCell("Duration min:s:ms", cs);
194200
t.addCell("Compared rows", cs);
195201
t.addCell("Status", cs);
196-
int i=0;
197202
savedTimesListGrouped.forEach((String key, List<SavedTimes> value) -> {
198203
value.forEach((SavedTimes v) -> {
199-
t.addCell(v.getTestName().trim(), cs)
200-
;
204+
t.addCell(v.getTestName().trim(), cs);
201205
t.addCell(v.getMeasureType().trim(), cs);
202-
t.addCell(v.getFormattedDuration().replace("min:s:ms", "").trim(), cs)
203-
;
206+
t.addCell(v.getFormattedDuration().replace("min:s:ms", "").trim(), cs);
204207
t.addCell(v.getNumberOfComparedRows(), cs);
205208
t.addCell(v.getTestResult().trim(), cs);
206209
});
207210
});
208-
String stringTable = "Statistics of queries execution group by test name(" + savedTimesListGrouped.size() + " rows):\r\n" + t.render();
211+
String stringTable = "Statistics of queries execution group by test name(" + savedTimesListGrouped.size()
212+
+ " rows):\r\n" + t.render();
209213
Printer.addReporterLog(stringTable);
210214

211-
log.log(Level.OFF, "##teamcity[message '"+stringTable+"']");
215+
log.log(Level.OFF, "##teamcity[message '" + stringTable + "']");
212216
log.info(stringTable);
213217

214-
Table ts = new Table(3, BorderStyle.DESIGN_TUBES, ShownBorders
215-
.SURROUND_HEADER_AND_COLUMNS, false, "");
218+
Table ts = new Table(3, BorderStyle.DESIGN_TUBES, ShownBorders.SURROUND_HEADER_AND_COLUMNS, false, "");
216219
ts.addCell("Test Name", cs);
217220
ts.addCell("Measure Type", cs);
218221
ts.addCell("Duration min:s:ms", cs);
219-
savedTimesList.forEach(s -> {ts.addCell(s.getTestName().trim(), cs)
220-
;ts.addCell(s.getMeasureType().trim(), cs);ts.addCell(s.getFormattedDuration().replace("min:s:ms","").trim(), cs);});
222+
savedTimesList.forEach(s -> {
223+
ts.addCell(s.getTestName().trim(), cs);
224+
ts.addCell(s.getMeasureType().trim(), cs);
225+
ts.addCell(s.getFormattedDuration().replace("min:s:ms", "").trim(), cs);
226+
});
221227

222-
stringTable = "Statistics of queries execution sorted by time execution (" + savedTimesList.size() + " rows):\r\n" + ts.render();
228+
stringTable = "Statistics of queries execution sorted by time execution (" + savedTimesList.size()
229+
+ " rows):\r\n" + ts.render();
223230
Printer.addReporterLog(stringTable);
224231

225-
log.log(Level.OFF, "##teamcity[message '"+stringTable+"']");
232+
log.log(Level.OFF, "##teamcity[message '" + stringTable + "']");
226233
log.info(stringTable);
227234

228235
}

src/main/java/uk/co/objectivity/test/db/RunTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public static void main(String[] args) {
7070
}
7171

7272
static CmpSqlResultsConfig readConfigAndInit() {
73-
log.debug("Scanning tests directory: " + TEST_DIR + "...");
73+
log.debug("Working Directory = " + System.getProperty("user.dir"));
74+
log.debug("Scanning tests directory: \"" + TEST_DIR + "\" ...");
7475
File testsDirFile = new File(TEST_DIR);
7576
if (!testsDirFile.exists()) {
7677
log.error("Tests directory does not exists! Please create directory: " + testsDirFile.getAbsolutePath());

0 commit comments

Comments
 (0)