|
16 | 16 |
|
17 | 17 | package io.cdap.plugin; |
18 | 18 |
|
| 19 | +import com.google.common.base.Strings; |
19 | 20 | import io.cdap.e2e.utils.PluginPropertyUtils; |
20 | 21 | import io.cdap.plugin.oracle.OracleSourceSchemaReader; |
21 | 22 | import org.junit.Assert; |
| 23 | +import org.slf4j.Logger; |
| 24 | +import org.slf4j.LoggerFactory; |
22 | 25 |
|
23 | 26 | import java.sql.Blob; |
24 | 27 | import java.sql.Clob; |
|
30 | 33 | import java.sql.Statement; |
31 | 34 | import java.sql.Timestamp; |
32 | 35 | import java.sql.Types; |
| 36 | +import java.time.Instant; |
33 | 37 | import java.util.Arrays; |
34 | 38 | import java.util.Date; |
35 | 39 | import java.util.GregorianCalendar; |
@@ -112,30 +116,51 @@ private static boolean compareResultSetData(ResultSet rsSource, ResultSet rsTarg |
112 | 116 | byte[] sourceArrayBlob = blobSource.getBytes(1, (int) blobSource.length()); |
113 | 117 | Blob blobTarget = rsTarget.getBlob(currentColumnCount); |
114 | 118 | byte[] targetArrayBlob = blobTarget.getBytes(1, (int) blobTarget.length()); |
115 | | - Assert.assertTrue(String.format("Different values found for column : %s", columnName), |
| 119 | + Assert.assertTrue(String.format("Different BLOB values found for column : %s", columnName), |
116 | 120 | Arrays.equals(sourceArrayBlob, targetArrayBlob)); |
117 | 121 | break; |
118 | 122 | case Types.CLOB: |
119 | 123 | Clob clobSource = rsSource.getClob(currentColumnCount); |
120 | 124 | String sourceClobString = clobSource.getSubString(1, (int) clobSource.length()); |
121 | 125 | Clob clobTarget = rsTarget.getClob(currentColumnCount); |
122 | 126 | String targetClobString = clobTarget.getSubString(1, (int) clobTarget.length()); |
123 | | - Assert.assertTrue(String.format("Different values found for column : %s", columnName), |
124 | | - sourceClobString.equals(targetClobString)); |
| 127 | + Assert.assertEquals(String.format("Different CLOB values found for column : %s", columnName), |
| 128 | + sourceClobString, targetClobString); |
125 | 129 | break; |
126 | 130 | case Types.TIMESTAMP: |
127 | 131 | GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("UTC")); |
128 | 132 | gc.setGregorianChange(new Date(Long.MIN_VALUE)); |
129 | 133 | Timestamp sourceTS = rsSource.getTimestamp(currentColumnCount, gc); |
130 | 134 | Timestamp targetTS = rsTarget.getTimestamp(currentColumnCount, gc); |
131 | | - Assert.assertTrue(String.format("Different values found for column : %s", columnName), |
132 | | - sourceTS.equals(targetTS)); |
| 135 | + Assert.assertEquals(String.format("Different TIMESTAMP values found for column : %s", columnName), |
| 136 | + sourceTS, targetTS); |
| 137 | + break; |
| 138 | + case OracleSourceSchemaReader.TIMESTAMP_TZ: |
| 139 | + // The timezone information in the field is lost during pipeline execution hence it is required to |
| 140 | + // convert both values into the system timezone and then compare. |
| 141 | + GregorianCalendar gregorianCalendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); |
| 142 | + gregorianCalendar.setGregorianChange(new Date(Long.MIN_VALUE)); |
| 143 | + Timestamp tsSource = rsSource.getTimestamp(currentColumnCount, gregorianCalendar); |
| 144 | + Timestamp tsTarget = rsTarget.getTimestamp(currentColumnCount, gregorianCalendar); |
| 145 | + if (tsSource == null && tsTarget == null) { |
| 146 | + break; |
| 147 | + } |
| 148 | + Assert.assertNotNull( |
| 149 | + String.format("Column : %s is null in source table and is not Null in target table.", columnName), |
| 150 | + tsSource); |
| 151 | + Assert.assertNotNull( |
| 152 | + String.format("Column : %s is null in target table and is not Null in source table.", columnName), |
| 153 | + tsTarget); |
| 154 | + Instant sourceInstant = tsSource.toInstant(); |
| 155 | + Instant targetInstant = tsTarget.toInstant(); |
| 156 | + Assert.assertEquals(String.format("Different TIMESTAMPTZ values found for column : %s", columnName), |
| 157 | + sourceInstant, targetInstant); |
133 | 158 | break; |
134 | 159 | default: |
135 | 160 | String sourceString = rsSource.getString(currentColumnCount); |
136 | 161 | String targetString = rsTarget.getString(currentColumnCount); |
137 | | - Assert.assertTrue(String.format("Different values found for column : %s", columnName), |
138 | | - String.valueOf(sourceString).equals(String.valueOf(targetString))); |
| 162 | + Assert.assertEquals(String.format("Different %s values found for column : %s", columnTypeName, columnName), |
| 163 | + String.valueOf(sourceString), String.valueOf(targetString)); |
139 | 164 | } |
140 | 165 | currentColumnCount++; |
141 | 166 | } |
@@ -217,6 +242,34 @@ public static void createTargetLongTable(String targetTable, String schema) thro |
217 | 242 | } |
218 | 243 | } |
219 | 244 |
|
| 245 | + public static void createTimestampSourceTable(String sourceTable, String schema) throws SQLException, |
| 246 | + ClassNotFoundException { |
| 247 | + try (Connection connect = getOracleConnection(); Statement statement = connect.createStatement()) { |
| 248 | + String timestampColumns = PluginPropertyUtils.pluginProp("timestampColumns"); |
| 249 | + String createSourceTableQuery = "CREATE TABLE " + schema + "." + sourceTable + " " + timestampColumns; |
| 250 | + statement.executeUpdate(createSourceTableQuery); |
| 251 | + |
| 252 | + int rowCount = 1; |
| 253 | + while (!Strings.isNullOrEmpty(PluginPropertyUtils.pluginProp("timestampValue" + rowCount))) { |
| 254 | + // Insert dummy data. |
| 255 | + String timestampValue = PluginPropertyUtils.pluginProp("timestampValue" + rowCount); |
| 256 | + String timestampColumnsList = PluginPropertyUtils.pluginProp("timestampColumnsList"); |
| 257 | + statement.executeUpdate("INSERT INTO " + schema + "." + sourceTable + " " + timestampColumnsList + " " + |
| 258 | + timestampValue); |
| 259 | + rowCount++; |
| 260 | + } |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + public static void createTimestampTargetTable(String targetTable, String schema) throws SQLException, |
| 265 | + ClassNotFoundException { |
| 266 | + try (Connection connect = getOracleConnection(); Statement statement = connect.createStatement()) { |
| 267 | + String timestampColumns = PluginPropertyUtils.pluginProp("timestampColumns"); |
| 268 | + String createTargetTableQuery = "CREATE TABLE " + schema + "." + targetTable + " " + timestampColumns; |
| 269 | + statement.executeUpdate(createTargetTableQuery); |
| 270 | + } |
| 271 | + } |
| 272 | + |
220 | 273 | public static void createSourceLongRawTable(String sourceTable, String schema) throws SQLException, |
221 | 274 | ClassNotFoundException { |
222 | 275 | try (Connection connect = getOracleConnection(); Statement statement = connect.createStatement()) { |
|
0 commit comments