Search in sources :

Example 1 with SqlPluginInfo

use of com.dtstack.taier.flink.plugininfo.SqlPluginInfo in project Taier by DTStack.

the class FlinkClientTest method testGrammarCheck.

/*@Test
    public void testGetJobStatus() throws Exception {
        String jobId = "40c01cd0c53928fff6a55e8d8b8b022c";
        String appId = "application_1594003499276_1278";
        String taskId = "taskId";
        JobIdentifier jobIdentifier = JobIdentifier.createInstance(jobId, appId, taskId);

        ApplicationReportPBImpl report = YarnMockUtil.mockApplicationReport(null);
        when(yarnClient.getApplicationReport(any())).thenReturn(report);
        when(flinkClientBuilder.getYarnClient()).thenReturn(yarnClient);

        RdosTaskStatus jobStatus = flinkClient.getJobStatus(jobIdentifier);
        Assert.assertNotNull(jobStatus);

        PowerMockito.mockStatic(PoolHttpClient.class);
        when(PoolHttpClient.get(any())).thenReturn("{\"state\":\"RUNNING\"}");

        ClusterClient clusterClient = YarnMockUtil.mockClusterClient();
        when(flinkClusterClientManager.getClusterClient(null)).thenReturn(clusterClient);
        jobIdentifier.setApplicationId(null);
        RdosTaskStatus jobStatus2 = flinkClient.getJobStatus(jobIdentifier);
        Assert.assertNotNull(jobStatus2);
    }*/
@Test
public void testGrammarCheck() throws Exception {
    MemberModifier.field(FlinkClient.class, "cacheFile").set(flinkClient, Maps.newConcurrentMap());
    String sqlPluginRootDir = temporaryFolder.newFolder("sqlPluginDir").getAbsolutePath();
    temporaryFolder.newFolder("sqlPluginDir", "sqlplugin");
    temporaryFolder.newFile("sqlPluginDir/sqlplugin/core-test.jar").getAbsolutePath();
    FlinkConfig flinkConfig = new FlinkConfig();
    flinkConfig.setFlinkPluginRoot(sqlPluginRootDir);
    SqlPluginInfo sqlPluginInfo = SqlPluginInfo.create(flinkConfig);
    MemberModifier.field(FlinkClient.class, "sqlPluginInfo").set(flinkClient, sqlPluginInfo);
    PowerMockito.mockStatic(PackagedProgram.class);
    PackagedProgram.Builder builder = PowerMockito.mock(PackagedProgram.Builder.class);
    when(PackagedProgram.newBuilder()).thenReturn(builder);
    PackagedProgram packagedProgram = PowerMockito.mock(PackagedProgram.class);
    when(builder.setJarFile(any(File.class))).thenReturn(builder);
    when(builder.setUserClassPaths(any(List.class))).thenReturn(builder);
    when(builder.setConfiguration(any(Configuration.class))).thenReturn(builder);
    when(builder.setArguments(any())).thenReturn(builder);
    when(builder.build()).thenReturn(packagedProgram);
    Configuration configuration = new Configuration();
    when(flinkClientBuilder.getFlinkConfiguration()).thenReturn(configuration);
    PowerMockito.mockStatic(PackagedProgramUtils.class);
    when(PackagedProgramUtils.createJobGraph(any(PackagedProgram.class), any(Configuration.class), any(int.class), any(boolean.class))).thenReturn(PowerMockito.mock(JobGraph.class));
    String absolutePath = temporaryFolder.newFile("core-flinksql.jar").getAbsolutePath();
    String sqlText = "CREATE TABLE MyTable ( id int, name varchar )  WITH (topicIsPattern = 'false', updateMode = 'append', bootstrapServers = 'dtstack01:9092', timezone = 'Asia/Shanghai', parallelism = '1', topic = 'grammar', type = 'kafka11', enableKeyPartitions = 'false', offsetReset = 'latest');  CREATE TABLE MyResult ( id INT, name VARCHAR )  WITH (type = 'console');  INSERT INTO MyResult SELECT a.id, a.name FROM MyTable a;";
    JobClient jobClient = YarnMockUtil.mockJobClient("perJob", sqlText, absolutePath);
    CheckResult checkResult = flinkClient.grammarCheck(jobClient);
    Assert.assertTrue(checkResult.isResult() == true);
}
Also used : PackagedProgram(org.apache.flink.client.program.PackagedProgram) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) SqlPluginInfo(com.dtstack.taier.flink.plugininfo.SqlPluginInfo) Configuration(org.apache.flink.configuration.Configuration) CheckResult(com.dtstack.taier.pluginapi.pojo.CheckResult) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File) JobClient(com.dtstack.taier.pluginapi.JobClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SqlPluginInfo (com.dtstack.taier.flink.plugininfo.SqlPluginInfo)1 JobClient (com.dtstack.taier.pluginapi.JobClient)1 CheckResult (com.dtstack.taier.pluginapi.pojo.CheckResult)1 File (java.io.File)1 List (java.util.List)1 PackagedProgram (org.apache.flink.client.program.PackagedProgram)1 Configuration (org.apache.flink.configuration.Configuration)1 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1