SbloodyS commented on code in PR #18192:
URL:
https://github.com/apache/dolphinscheduler/pull/18192#discussion_r3151964782
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-datax/src/test/java/org/apache/dolphinscheduler/plugin/task/datax/DataxTaskTest.java:
##########
@@ -273,6 +278,69 @@ private TaskExecutionContext
buildTestTaskExecutionContext() {
return taskExecutionContext;
}
+ @Test
+ public void testBuildDataxJobContentJsonWithBatchSize() throws Exception {
+ // set batchSize > 0 via reflection
+ Field dataXParametersField =
DataxTask.class.getDeclaredField("dataXParameters");
+ dataXParametersField.setAccessible(true);
+ DataxParameters params = (DataxParameters)
dataXParametersField.get(dataxTask);
+ params.setBatchSize(1024);
+ params.setDsType("MYSQL");
+ params.setDtType("MYSQL");
+
+ // set dataxTaskExecutionContext via reflection
+ DataxTaskExecutionContext ctx = new DataxTaskExecutionContext();
+ ctx.setSourcetype(DbType.MYSQL);
+ ctx.setTargetType(DbType.MYSQL);
+ ctx.setSourceConnectionParams(
+
"{\"user\":\"root\",\"password\":\"123456\",\"address\":\"jdbc:mysql://localhost:3306\"}");
+ ctx.setTargetConnectionParams(
+
"{\"user\":\"root\",\"password\":\"123456\",\"address\":\"jdbc:mysql://localhost:3306\"}");
+
+ Field ctxField =
DataxTask.class.getDeclaredField("dataxTaskExecutionContext");
+ ctxField.setAccessible(true);
+ ctxField.set(dataxTask, ctx);
+
+ BaseConnectionParam mockConnParam = mock(BaseConnectionParam.class);
+ when(mockConnParam.getUser()).thenReturn("root");
+ when(mockConnParam.getPassword()).thenReturn("123456");
+ when(mockConnParam.getCompatibleMode()).thenReturn(null);
+
+ try (
+ MockedStatic<DataSourceUtils> mockedDataSourceUtils =
mockStatic(DataSourceUtils.class);
+ MockedStatic<DataSourceClientProvider> mockedProvider =
mockStatic(DataSourceClientProvider.class)) {
+
+ mockedDataSourceUtils
+ .when(() ->
DataSourceUtils.buildConnectionParams(Mockito.any(DbType.class),
Mockito.anyString()))
+ .thenReturn(mockConnParam);
+ mockedDataSourceUtils.when(() ->
DataSourceUtils.getJdbcUrl(Mockito.any(DbType.class), Mockito.any()))
+ .thenReturn("jdbc:mysql://localhost:3306/test");
+
+ Connection connection = mock(Connection.class);
+ mockedProvider.when(() ->
DataSourceClientProvider.getAdHocConnection(Mockito.any(), Mockito.any()))
+ .thenReturn(connection);
+
+ PreparedStatement stmt = mock(PreparedStatement.class);
+ when(connection.prepareStatement(anyString())).thenReturn(stmt);
+ ResultSetMetaData md = mock(ResultSetMetaData.class);
+ when(md.getColumnCount()).thenReturn(1);
+ when(md.getColumnLabel(eq(1))).thenReturn("col1");
+ ResultSet resultSet = mock(ResultSet.class);
+ when(resultSet.getMetaData()).thenReturn(md);
+ when(stmt.executeQuery()).thenReturn(resultSet);
+
+ Method method =
DataxTask.class.getDeclaredMethod("buildDataxJobContentJson");
+ method.setAccessible(true);
+ @SuppressWarnings("unchecked")
Review Comment:
```suggestion
```
Don't use `SuppressWarnings` in any code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]