|
18 | 18 |
|
19 | 19 | import static com.google.common.collect.ImmutableList.toImmutableList; |
20 | 20 | import static com.google.common.collect.Iterables.getOnlyElement; |
| 21 | +import static com.google.edwmigration.dumper.application.dumper.connector.teradata.AbstractTeradataConnector.DEF_LOG_TABLE; |
| 22 | +import static com.google.edwmigration.dumper.application.dumper.connector.teradata.AbstractTeradataConnector.DEF_SQL_TABLE; |
21 | 23 | import static com.google.edwmigration.dumper.application.dumper.test.DumperTestUtils.assertQueryEquals; |
| 24 | +import static java.nio.file.FileSystems.newFileSystem; |
22 | 25 | import static java.time.ZoneOffset.UTC; |
23 | 26 | import static org.junit.Assert.assertEquals; |
24 | 27 | import static org.junit.Assert.assertTrue; |
|
28 | 31 | import com.google.common.collect.ImmutableMap; |
29 | 32 | import com.google.edwmigration.dumper.application.dumper.ConnectorArguments; |
30 | 33 | import com.google.edwmigration.dumper.application.dumper.connector.AbstractConnectorExecutionTest; |
| 34 | +import com.google.edwmigration.dumper.application.dumper.handle.Handle; |
31 | 35 | import com.google.edwmigration.dumper.application.dumper.handle.JdbcHandle; |
32 | 36 | import com.google.edwmigration.dumper.application.dumper.io.FileSystemOutputHandleFactory; |
33 | 37 | import com.google.edwmigration.dumper.application.dumper.io.OutputHandleFactory; |
|
37 | 41 | import java.io.File; |
38 | 42 | import java.net.URI; |
39 | 43 | import java.nio.file.FileSystem; |
40 | | -import java.nio.file.FileSystems; |
41 | 44 | import java.time.Clock; |
42 | 45 | import java.time.Instant; |
43 | 46 | import java.util.ArrayList; |
|
53 | 56 | @RunWith(JUnit4.class) |
54 | 57 | public class TeradataLogsConnectorTest extends AbstractConnectorExecutionTest { |
55 | 58 |
|
56 | | - final TaskRunContext mockContext = mock(TaskRunContext.class); |
| 59 | + final TaskRunContextOps mockOptions = mock(TaskRunContextOps.class); |
| 60 | + |
57 | 61 | private final TeradataLogsConnector connector = new TeradataLogsConnector(); |
58 | 62 |
|
59 | 63 | @Test |
@@ -224,37 +228,30 @@ public void addTasksTo_commonConnectorTest_success() throws Exception { |
224 | 228 |
|
225 | 229 | @Test |
226 | 230 | public void addTasksTo_executeQuery_success() throws Exception { |
227 | | - String name = getClass().getSimpleName(); |
228 | | - File dbFile = DumperTestUtils.newJdbcFile(name); |
229 | | - File zipFile = DumperTestUtils.newZipFile(name); |
| 231 | + File dbFile = DumperTestUtils.newJdbcFile(getClass().getSimpleName()); |
| 232 | + File zipFile = DumperTestUtils.newZipFile(getClass().getSimpleName()); |
230 | 233 |
|
231 | 234 | dbFile.delete(); |
232 | 235 | zipFile.delete(); |
233 | 236 |
|
234 | 237 | URI outputUri = URI.create("jar:" + zipFile.toURI()); |
235 | | - |
| 238 | + ImmutableList<String> scripts = |
| 239 | + ImmutableList.of( |
| 240 | + "attach ':memory:' as dbc", |
| 241 | + String.format( |
| 242 | + "create table %s (UserName varchar, errorcode int, StartTime int)", DEF_LOG_TABLE), |
| 243 | + String.format("create table %s (QueryID int)", DEF_SQL_TABLE)); |
236 | 244 | // This isn't great because all the column-validity queries fail. |
237 | 245 | try (JdbcHandle handle = DumperTestUtils.newJdbcHandle(dbFile); |
238 | | - FileSystem fileSystem = |
239 | | - FileSystems.newFileSystem(outputUri, ImmutableMap.of("create", "true"))) { |
240 | | - OutputHandleFactory sinkFactory = new FileSystemOutputHandleFactory(fileSystem, "/"); |
241 | | - handle.getJdbcTemplate().execute("attach ':memory:' as dbc"); |
242 | | - handle |
243 | | - .getJdbcTemplate() |
244 | | - .execute( |
245 | | - "create table " |
246 | | - + TeradataLogsConnector.DEF_LOG_TABLE |
247 | | - + " (UserName varchar, errorcode int, StartTime int)"); |
248 | | - handle |
249 | | - .getJdbcTemplate() |
250 | | - .execute("create table " + TeradataLogsConnector.DEF_SQL_TABLE + " (QueryID int)"); |
251 | | - |
| 246 | + FileSystem fileSystem = newFileSystem(outputUri, ImmutableMap.of("create", "true"))) { |
| 247 | + scripts.forEach(handle.getJdbcTemplate()::execute); |
252 | 248 | ConnectorArguments arguments = |
253 | | - new ConnectorArguments("--connector", connector.getName(), "--query-log-days", "1"); |
| 249 | + new ConnectorArguments("--connector", "teradata-logs", "--query-log-days", "1"); |
| 250 | + TaskRunContext runContext = testContext(fileSystem, handle, mockOptions, arguments); |
254 | 251 | List<Task<?>> tasks = new ArrayList<>(); |
255 | 252 | connector.addTasksTo(tasks, arguments); |
256 | 253 | for (Task<?> task : tasks) { |
257 | | - task.run(mockContext); |
| 254 | + task.run(runContext); |
258 | 255 | } |
259 | 256 | } |
260 | 257 | } |
@@ -452,4 +449,13 @@ public void values_success() { |
452 | 449 | Teradata14LogsConnector.EXPRESSIONS_LOG_TBL.toArray( |
453 | 450 | new String[Teradata14LogsConnector.EXPRESSIONS_LOG_TBL.size()])); |
454 | 451 | } |
| 452 | + |
| 453 | + static TaskRunContext testContext( |
| 454 | + FileSystem fileSystem, |
| 455 | + Handle handle, |
| 456 | + TaskRunContextOps options, |
| 457 | + ConnectorArguments arguments) { |
| 458 | + OutputHandleFactory sinkFactory = new FileSystemOutputHandleFactory(fileSystem, "/"); |
| 459 | + return new TaskRunContext(sinkFactory, handle, 10, options, arguments); |
| 460 | + } |
455 | 461 | } |
0 commit comments