Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.edwmigration.dumper.application.dumper.connector.teradata.AbstractTeradataConnector.DEF_LOG_TABLE;
import static com.google.edwmigration.dumper.application.dumper.connector.teradata.AbstractTeradataConnector.DEF_SQL_TABLE;
import static com.google.edwmigration.dumper.application.dumper.test.DumperTestUtils.assertQueryEquals;
import static java.nio.file.FileSystems.newFileSystem;
import static java.time.ZoneOffset.UTC;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.edwmigration.dumper.application.dumper.ConnectorArguments;
import com.google.edwmigration.dumper.application.dumper.connector.AbstractConnectorExecutionTest;
import com.google.edwmigration.dumper.application.dumper.handle.Handle;
import com.google.edwmigration.dumper.application.dumper.handle.JdbcHandle;
import com.google.edwmigration.dumper.application.dumper.io.FileSystemOutputHandleFactory;
import com.google.edwmigration.dumper.application.dumper.io.OutputHandleFactory;
import com.google.edwmigration.dumper.application.dumper.task.*;
import com.google.edwmigration.dumper.application.dumper.test.DummyTaskRunContextFactory;
import com.google.edwmigration.dumper.application.dumper.test.DumperTestUtils;
import com.google.edwmigration.dumper.plugin.lib.dumper.spi.TeradataLogsDumpFormat;
import java.io.File;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.time.Clock;
import java.time.Instant;
import java.util.ArrayList;
Expand All @@ -53,6 +56,8 @@
@RunWith(JUnit4.class)
public class TeradataLogsConnectorTest extends AbstractConnectorExecutionTest {

final TaskRunContextOps mockOptions = mock(TaskRunContextOps.class);

private final TeradataLogsConnector connector = new TeradataLogsConnector();

@Test
Expand Down Expand Up @@ -223,34 +228,27 @@ public void addTasksTo_commonConnectorTest_success() throws Exception {

@Test
public void addTasksTo_executeQuery_success() throws Exception {
String name = getClass().getSimpleName();
File dbFile = DumperTestUtils.newJdbcFile(name);
File zipFile = DumperTestUtils.newZipFile(name);
File dbFile = DumperTestUtils.newJdbcFile(getClass().getSimpleName());
File zipFile = DumperTestUtils.newZipFile(getClass().getSimpleName());

dbFile.delete();
zipFile.delete();

URI outputUri = URI.create("jar:" + zipFile.toURI());

ImmutableList<String> scripts =
ImmutableList.of(
"attach ':memory:' as dbc",
String.format(
"create table %s (UserName varchar, errorcode int, StartTime int)", DEF_LOG_TABLE),
String.format("create table %s (QueryID int)", DEF_SQL_TABLE));
// This isn't great because all the column-validity queries fail.
try (JdbcHandle handle = DumperTestUtils.newJdbcHandle(dbFile);
FileSystem fileSystem =
FileSystems.newFileSystem(outputUri, ImmutableMap.of("create", "true"))) {
OutputHandleFactory sinkFactory = new FileSystemOutputHandleFactory(fileSystem, "/");
handle.getJdbcTemplate().execute("attach ':memory:' as dbc");
handle
.getJdbcTemplate()
.execute(
"create table "
+ TeradataLogsConnector.DEF_LOG_TABLE
+ " (UserName varchar, errorcode int, StartTime int)");
handle
.getJdbcTemplate()
.execute("create table " + TeradataLogsConnector.DEF_SQL_TABLE + " (QueryID int)");

FileSystem fileSystem = newFileSystem(outputUri, ImmutableMap.of("create", "true"))) {
scripts.forEach(handle.getJdbcTemplate()::execute);
ConnectorArguments arguments =
new ConnectorArguments("--connector", connector.getName(), "--query-log-days", "1");
TaskRunContext runContext = DummyTaskRunContextFactory.create(sinkFactory, handle, arguments);
ConnectorArguments.create(
ImmutableList.of("--connector", "teradata-logs", "--query-log-days", "1"));
TaskRunContext runContext = testContext(fileSystem, handle, mockOptions, arguments);
List<Task<?>> tasks = new ArrayList<>();
connector.addTasksTo(tasks, arguments);
for (Task<?> task : tasks) {
Expand Down Expand Up @@ -452,4 +450,13 @@ public void values_success() {
Teradata14LogsConnector.EXPRESSIONS_LOG_TBL.toArray(
new String[Teradata14LogsConnector.EXPRESSIONS_LOG_TBL.size()]));
}

static TaskRunContext testContext(
FileSystem fileSystem,
Handle handle,
TaskRunContextOps options,
ConnectorArguments arguments) {
OutputHandleFactory sinkFactory = new FileSystemOutputHandleFactory(fileSystem, "/");
return new TaskRunContext(sinkFactory, handle, 10, options, arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.google.edwmigration.dumper.application.dumper.task;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

import com.google.edwmigration.dumper.application.dumper.ConnectorArguments;
import com.google.edwmigration.dumper.application.dumper.test.DummyTaskRunContextFactory;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -29,12 +29,13 @@
@RunWith(JUnit4.class)
public class DumpMetadataTaskTest extends AbstractTaskTest {

final TaskRunContext mockContext = mock(TaskRunContext.class);

@Test
public void testTask() throws Exception {
MemoryByteSink sink = new MemoryByteSink();
ConnectorArguments arguments = new ConnectorArguments("--connector", "bigquery-logs");
new DumpMetadataTask(arguments, "test-format")
.doRun(DummyTaskRunContextFactory.create(HANDLE), sink, HANDLE);
new DumpMetadataTask(arguments, "test-format").doRun(mockContext, sink, HANDLE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.google.edwmigration.dumper.application.dumper.task;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

import com.google.edwmigration.dumper.application.dumper.test.DummyTaskRunContextFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -27,10 +27,12 @@
@RunWith(JUnit4.class)
public class FormatTaskTest extends AbstractTaskTest {

final TaskRunContext mockContext = mock(TaskRunContext.class);

@Test
public void testTask() throws Exception {
MemoryByteSink sink = new MemoryByteSink();
new FormatTask("test-format").doRun(DummyTaskRunContextFactory.create(HANDLE), sink, HANDLE);
new FormatTask("test-format").doRun(mockContext, sink, HANDLE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;

import com.google.edwmigration.dumper.application.dumper.handle.JdbcHandle;
import com.google.edwmigration.dumper.application.dumper.io.OutputHandle.WriteMode;
import com.google.edwmigration.dumper.application.dumper.task.AbstractTask.TaskOptions;
import com.google.edwmigration.dumper.application.dumper.test.DummyTaskRunContextFactory;
import com.google.edwmigration.dumper.application.dumper.test.DumperTestUtils;
import java.io.File;
import java.sql.ResultSet;
Expand All @@ -40,7 +40,6 @@
@RunWith(JUnit4.class)
public class JdbcSelectTaskTest extends AbstractTaskTest {

@SuppressWarnings("UnusedVariable")
private static final Logger logger = LoggerFactory.getLogger(JdbcSelectTaskTest.class);

private static final String NAME = JdbcSelectTaskTest.class.getSimpleName();
Expand All @@ -53,6 +52,8 @@ private enum Header {
Baz
}

final TaskRunContext mockContext = mock(TaskRunContext.class);

@BeforeClass
public static void setUpClass() throws Exception {
Class.forName("org.sqlite.JDBC");
Expand All @@ -68,8 +69,7 @@ public static void setUpClass() throws Exception {
public void testResultSetHeader() throws Exception {
MemoryByteSink sink = new MemoryByteSink();
try (JdbcHandle handle = DumperTestUtils.newJdbcHandle(FILE)) {
new JdbcSelectTask("(memory)", QUERY)
.doRun(DummyTaskRunContextFactory.create(handle), sink, handle);
new JdbcSelectTask("(memory)", QUERY).doRun(mockContext, sink, handle);
}
String actualOutput = sink.openStream().toString();
assertEquals("a,b,c\n1,2,3\n", actualOutput);
Expand All @@ -81,7 +81,7 @@ public void testClassHeader() throws Exception {
try (JdbcHandle handle = DumperTestUtils.newJdbcHandle(FILE)) {
new JdbcSelectTask("(memory)", QUERY)
.withHeaderClass(Header.class)
.doRun(DummyTaskRunContextFactory.create(handle), sink, handle);
.doRun(mockContext, sink, handle);
}
String actualOutput = sink.openStream().toString();
assertEquals("Foo,Bar,Baz\n1,2,3\n", actualOutput);
Expand All @@ -102,7 +102,7 @@ protected CSVFormat newCsvFormat(ResultSet rs) throws SQLException {
return format;
}
}.withHeaderClass(Header.class);
task.doRun(DummyTaskRunContextFactory.create(handle), sink, handle);
task.doRun(mockContext, sink, handle);
}
String actualOutput = sink.openStream().toString();
assertEquals("Foo,Bar,Baz\n,14,3\n", actualOutput);
Expand Down Expand Up @@ -130,7 +130,6 @@ public void append_success() throws Exception {
String secondSql = "select null, 15, b FROM foo";

MemoryByteSink sink = new MemoryByteSink();
final MutableObject<CSVFormat> formatHolder = new MutableObject<>();
try (JdbcHandle handle = DumperTestUtils.newJdbcHandle(FILE)) {
AbstractTask<Summary> first =
new JdbcSelectTask("(memory)", firstSql).withHeaderClass(Header.class);
Expand All @@ -141,8 +140,8 @@ public void append_success() throws Exception {
TaskCategory.REQUIRED,
TaskOptions.DEFAULT.withWriteMode(WriteMode.APPEND_EXISTING))
.withHeaderClass(Header.class);
first.doRun(DummyTaskRunContextFactory.create(handle), sink, handle);
second.doRun(DummyTaskRunContextFactory.create(handle), sink, handle);
first.doRun(mockContext, sink, handle);
second.doRun(mockContext, sink, handle);
}
String actualOutput = sink.openStream().toString();
assertEquals("Foo,Bar,Baz\n,14,3\n,15,2\n", actualOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.google.edwmigration.dumper.application.dumper.task;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

import com.google.edwmigration.dumper.application.dumper.test.DummyTaskRunContextFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -30,7 +30,8 @@ public class VersionTaskTest extends AbstractTaskTest {
@Test
public void testTask() throws Exception {
MemoryByteSink sink = new MemoryByteSink();
new VersionTask().doRun(DummyTaskRunContextFactory.create(HANDLE), sink, HANDLE);
TaskRunContext mockContext = mock(TaskRunContext.class);
new VersionTask().doRun(mockContext, sink, HANDLE);
}

@Test
Expand Down

This file was deleted.

Loading