11package tech .mlsql .it
22
3+ import net .csdn .modules .transport .DefaultHttpTransportService
4+ import org .apache .http .HttpEntity
5+ import org .apache .http .util .EntityUtils
36import tech .mlsql .common .utils .log .Logging
47import tech .mlsql .crawler .RestUtils
58import tech .mlsql .it .contiainer .ByzerCluster
@@ -8,6 +11,7 @@ import tech.mlsql.it.utils.DockerUtils.getCurProjectRootPath
811
912import java .io .File
1013import java .util .UUID
14+ import scala .collection .mutable
1115
1216/**
1317 * 23/02/2022 hellozepp(lisheng.zhanglin@163.com)
@@ -54,11 +58,27 @@ class ByzerScriptTestSuite extends LocalBaseTestSuite with Logging {
5458 })
5559 }
5660
57- def runScript (url : String , user : String , code : String ): (Int , String ) = {
61+ def runScript (url : String , user : String , code : String , callbackHeader : String = " " ): (Int , String ) = {
5862 val jobName = UUID .randomUUID().toString
63+ val params = mutable.Map (" sql" -> code, " owner" -> user,
64+ " jobName" -> jobName, " sessionPerUser" -> " true" , " sessionPerRequest" -> " true" )
65+ if (callbackHeader != " " ) params.put(" callbackHeader" , callbackHeader)
5966 logInfo(s " The test submits a script to the container through Rest, url: $url, sql: $code" )
60- val (status, result) = RestUtils .rest_request_string(url, " post" , Map (" sql" -> code, " owner" -> user,
61- " jobName" -> jobName, " sessionPerUser" -> " true" , " sessionPerRequest" -> " true" ),
67+ val (status, result) = RestUtils .rest_request_string(url, " post" , params.toMap,
68+ Map (" Content-Type" -> " application/x-www-form-urlencoded" ), Map (" socket-timeout" -> " 1800s" ,
69+ " connect-timeout" -> " 1800s" , " retry" -> " 1" )
70+ )
71+ logInfo(s " status: $status,result: $result" )
72+ (status, result)
73+ }
74+
75+ def runScriptWithHeader (url : String , user : String , code : String , callbackHeader : String = " " ): (Int , HttpEntity ) = {
76+ val jobName = UUID .randomUUID().toString
77+ val params = mutable.Map (" sql" -> code, " owner" -> user,
78+ " jobName" -> jobName, " sessionPerUser" -> " true" , " sessionPerRequest" -> " true" )
79+ if (callbackHeader != " " ) params.put(" callbackHeader" , callbackHeader)
80+ logInfo(s " The test submits a script to the container through Rest, url: $url, sql: $code" )
81+ val (status, result) = RestUtils .rest_request(url, " post" , params.toMap,
6282 Map (" Content-Type" -> " application/x-www-form-urlencoded" ), Map (" socket-timeout" -> " 1800s" ,
6383 " connect-timeout" -> " 1800s" , " retry" -> " 1" )
6484 )
@@ -82,7 +102,7 @@ class ByzerScriptTestSuite extends LocalBaseTestSuite with Logging {
82102 val cluster : ByzerCluster = setupCluster()
83103 val hadoopContainer = cluster.hadoopContainer
84104 val byzerLangContainer = cluster.byzerLangContainer
85- val javaContainer = cluster. byzerLangContainer.container
105+ val javaContainer = byzerLangContainer.container
86106 url = s " http:// ${javaContainer.getHost}: ${javaContainer.getMappedPort(9003 )}/run/script "
87107
88108 test(" javaContainer" ) {
@@ -101,6 +121,19 @@ class ByzerScriptTestSuite extends LocalBaseTestSuite with Logging {
101121 }
102122
103123 test(" Execute yarn sql file" ) {
124+ try {
125+ val (_, result) = runScriptWithHeader(url, user, " select 1 as a,'jack' as b as bbc;" ,
126+ """ {"Authorization":"Bearer acc"}""" )
127+ val _result = EntityUtils .toString(result, DefaultHttpTransportService .charset)
128+ println(" With callbackHeader result:" + _result)
129+ assert(_result === " [{\" a\" :1,\" b\" :\" jack\" }]" )
130+ } catch {
131+ case _ : Exception =>
132+ val res = " callbackHeader should be returned normally in the byzer callback!"
133+ logError(res)
134+ throw new RuntimeException (res)
135+ }
136+
104137 TestManager .testCases.foreach(testCase => {
105138 try {
106139 val (status, result) = runScript(url, user, testCase.sql)
@@ -110,7 +143,6 @@ class ByzerScriptTestSuite extends LocalBaseTestSuite with Logging {
110143 TestManager .acceptRest(testCase, 500 , null , e)
111144 }
112145 })
113-
114146 TestManager .report()
115147 }
116148
0 commit comments