You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by am...@apache.org on 2016/02/02 14:21:20 UTC
[2/7] lens git commit: LENS-920 : Fix issues in producing and
consuming json for all api
http://git-wip-us.apache.org/repos/asf/lens/blob/d559ef2e/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java
index ef8c1aa..d9b7679 100644
--- a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java
+++ b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java
@@ -33,10 +33,7 @@ import java.util.*;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import javax.ws.rs.core.*;
import org.apache.lens.api.APIResult;
import org.apache.lens.api.LensConf;
@@ -77,16 +74,11 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
-import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
-import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.test.TestProperties;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
+import org.testng.annotations.*;
import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Optional;
@@ -130,7 +122,7 @@ public class TestQueryService extends LensJerseyTest {
super.setUp();
queryService = LensServices.get().getService(QueryExecutionService.NAME);
metricsSvc = LensServices.get().getService(MetricsService.NAME);
- Map<String, String> sessionconf = new HashMap<String, String>();
+ Map<String, String> sessionconf = new HashMap<>();
sessionconf.put("test.session.key", "svalue");
lensSessionId = queryService.openSession("foo@localhost", "bar", sessionconf); // @localhost should be removed
// automatically
@@ -167,17 +159,6 @@ public class TestQueryService extends LensJerseyTest {
return new QueryServiceTestApp();
}
- /*
- * (non-Javadoc)
- *
- * @see org.glassfish.jersey.test.JerseyTest#configureClient(org.glassfish.jersey.client.ClientConfig)
- */
- @Override
- protected void configureClient(ClientConfig config) {
- config.register(MultiPartFeature.class);
- config.register(LensJAXBContextResolver.class);
- }
-
/** The test table. */
public static final String TEST_TABLE = "TEST_TABLE";
@@ -188,7 +169,7 @@ public class TestQueryService extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
*/
private void createTable(String tblName) throws InterruptedException {
- LensServerTestUtil.createTable(tblName, target(), lensSessionId);
+ LensServerTestUtil.createTable(tblName, target(), lensSessionId, defaultMT);
}
/**
@@ -199,7 +180,7 @@ public class TestQueryService extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
*/
private void loadData(String tblName, final String testDataFile) throws InterruptedException {
- LensServerTestUtil.loadDataFromClasspath(tblName, testDataFile, target(), lensSessionId);
+ LensServerTestUtil.loadDataFromClasspath(tblName, testDataFile, target(), lensSessionId, defaultMT);
}
/**
@@ -209,19 +190,17 @@ public class TestQueryService extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
*/
private void dropTable(String tblName) throws InterruptedException {
- LensServerTestUtil.dropTable(tblName, target(), lensSessionId);
+ LensServerTestUtil.dropTable(tblName, target(), lensSessionId, defaultMT);
}
- // test get a random query, should return 400
-
/**
- * Test get random query.
+ * Test get random query. should return 400
*/
- @Test
- public void testGetRandomQuery() {
+ @Test(dataProvider = "mediaTypeData")
+ public void testGetRandomQuery(MediaType mt) {
final WebTarget target = target().path("queryapi/queries");
- Response rs = target.path("random").queryParam("sessionid", lensSessionId).request().get();
+ Response rs = target.path("random").queryParam("sessionid", lensSessionId).request(mt).get();
assertEquals(rs.getStatus(), 400);
}
@@ -229,7 +208,7 @@ public class TestQueryService extends LensJerseyTest {
public void testLoadingMultipleDrivers() {
Collection<LensDriver> drivers = queryService.getDrivers();
assertEquals(drivers.size(), 4);
- Set<String> driverNames = new HashSet<String>(drivers.size());
+ Set<String> driverNames = new HashSet<>(drivers.size());
for (LensDriver driver : drivers) {
assertEquals(driver.getConf().get("lens.driver.test.drivername"), driver.getFullyQualifiedName());
driverNames.add(driver.getFullyQualifiedName());
@@ -242,19 +221,17 @@ public class TestQueryService extends LensJerseyTest {
*
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testRewriteFailureInExecute() throws InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testRewriteFailureInExecute(MediaType mt) throws InterruptedException {
final WebTarget target = target().path("queryapi/queries");
LensConf conf = new LensConf();
final FormDataMultiPart mp = new FormDataMultiPart();
- mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt));
mp.bodyPart(
new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from non_exist_table"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
- mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- final Response response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
+ mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, mt));
+ final Response response = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
assertEquals(response.getStatus(), BAD_REQUEST.getStatusCode());
}
@@ -263,10 +240,10 @@ public class TestQueryService extends LensJerseyTest {
*
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testLaunchFail() throws InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testLaunchFail(MediaType mt) throws InterruptedException {
LensQuery lensQuery = executeAndWaitForQueryToFinish(target(), lensSessionId, "select fail from non_exist",
- Optional.<LensConf>absent(), Optional.of(Status.FAILED));
+ Optional.<LensConf>absent(), Optional.of(Status.FAILED), mt);
assertTrue(lensQuery.getSubmissionTime() > 0);
assertEquals(lensQuery.getLaunchTime(), 0);
assertEquals(lensQuery.getDriverStartTime(), 0);
@@ -282,8 +259,8 @@ public class TestQueryService extends LensJerseyTest {
*
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testQueriesAPI() throws InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testQueriesAPI(MediaType mt) throws InterruptedException {
// test post execute op
final WebTarget target = target().path("queryapi/queries");
@@ -292,7 +269,7 @@ public class TestQueryService extends LensJerseyTest {
long finishedQueries = metricsSvc.getFinishedQueries();
QueryHandle handle = executeAndGetHandle(target(), Optional.of(lensSessionId), Optional.of("select ID from "
- + TEST_TABLE), Optional.<LensConf>absent());
+ + TEST_TABLE), Optional.<LensConf>absent(), mt);
// Get all queries
// XML
@@ -300,7 +277,7 @@ public class TestQueryService extends LensJerseyTest {
.get(new GenericType<List<QueryHandle>>() {});
assertTrue(allQueriesXML.size() >= 1);
- List<QueryHandle> allQueries = target.queryParam("sessionid", lensSessionId).request()
+ List<QueryHandle> allQueries = target.queryParam("sessionid", lensSessionId).request(mt)
.get(new GenericType<List<QueryHandle>>() {});
assertTrue(allQueries.size() >= 1);
assertTrue(allQueries.contains(handle));
@@ -309,17 +286,17 @@ public class TestQueryService extends LensJerseyTest {
.request(MediaType.APPLICATION_XML).get(String.class);
log.debug("query XML:{}", queryXML);
- Response response = target.path(handle.toString() + "001").queryParam("sessionid", lensSessionId).request().get();
+ Response response = target.path(handle.toString() + "001").queryParam("sessionid", lensSessionId).request(mt).get();
assertEquals(response.getStatus(), 404);
- LensQuery ctx = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request()
+ LensQuery ctx = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request(mt)
.get(LensQuery.class);
// wait till the query finishes
QueryStatus stat = ctx.getStatus();
while (!stat.finished()) {
Thread.sleep(1000);
- ctx = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request().get(LensQuery.class);
+ ctx = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request(mt).get(LensQuery.class);
stat = ctx.getStatus();
/*
Commented due to same issue as: https://issues.apache.org/jira/browse/LENS-683
@@ -343,10 +320,10 @@ public class TestQueryService extends LensJerseyTest {
LensConf conf = new LensConf();
conf.addProperty("my.property", "myvalue");
confpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
confpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- APIResult updateConf = target.path(handle.toString()).request()
+ mt));
+ APIResult updateConf = target.path(handle.toString()).request(mt)
.put(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class);
assertEquals(updateConf.getStatus(), APIResult.Status.FAILED);
}
@@ -358,19 +335,19 @@ public class TestQueryService extends LensJerseyTest {
*
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testExplainQuery() throws InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testExplainQuery(MediaType mt) throws InterruptedException {
final WebTarget target = target().path("queryapi/queries");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from " + TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final QueryPlan plan = target.request()
+ final QueryPlan plan = target.request(mt)
.post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryPlan>>() {}).getData();
assertEquals(plan.getTablesQueried().size(), 1);
@@ -382,14 +359,14 @@ public class TestQueryService extends LensJerseyTest {
final FormDataMultiPart mp2 = new FormDataMultiPart();
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(),
"select ID from " + TEST_TABLE));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain_and_prepare"));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final QueryPlan plan2 = ptarget.request().post(Entity.entity(mp2, MediaType.MULTIPART_FORM_DATA_TYPE),
+ final QueryPlan plan2 = ptarget.request(mt).post(Entity.entity(mp2, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryPlan>>() {}).getData();
assertEquals(plan2.getTablesQueried().size(), 1);
assertTrue(plan2.getTablesQueried().get(0).endsWith(TEST_TABLE.toLowerCase()));
@@ -404,20 +381,20 @@ public class TestQueryService extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws UnsupportedEncodingException
*/
- @Test
- public void testExplainFailure() throws InterruptedException, UnsupportedEncodingException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testExplainFailure(MediaType mt) throws InterruptedException, UnsupportedEncodingException {
final WebTarget target = target().path("queryapi/queries");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select NO_ID from "
+ TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final Response responseExplain = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
+ final Response responseExplain = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
assertEquals(responseExplain.getStatus(), BAD_REQUEST.getStatusCode());
@@ -426,14 +403,14 @@ public class TestQueryService extends LensJerseyTest {
final FormDataMultiPart mp2 = new FormDataMultiPart();
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select NO_ID from "
+ TEST_TABLE));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain_and_prepare"));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final Response responseExplainAndPrepare = target.request().post(
+ final Response responseExplainAndPrepare = ptarget.request(mt).post(
Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
assertEquals(responseExplainAndPrepare.getStatus(), BAD_REQUEST.getStatusCode());
@@ -445,19 +422,18 @@ public class TestQueryService extends LensJerseyTest {
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testHiveSemanticFailure() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testHiveSemanticFailure(MediaType mt) throws InterruptedException, IOException {
final WebTarget target = target().path("queryapi/queries");
-
final FormDataMultiPart mp = new FormDataMultiPart();
- mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), " select ID from NOT_EXISTS"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- Response response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
+ Response response = target.request(mt).post(Entity.entity(mp, MediaType
+ .MULTIPART_FORM_DATA_TYPE));
LensAPIResult result = response.readEntity(LensAPIResult.class);
List<LensErrorTO> childErrors = result.getLensErrorTO().getChildErrors();
boolean hiveSemanticErrorExists = false;
@@ -482,31 +458,31 @@ public class TestQueryService extends LensJerseyTest {
*
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testPrepareQuery() throws InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testPrepareQuery(MediaType mt) throws InterruptedException {
final WebTarget target = target().path("queryapi/preparedqueries");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from " + TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "prepare"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("queryName").build(), "testQuery1"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final QueryPrepareHandle pHandle = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
+ final QueryPrepareHandle pHandle = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryPrepareHandle>>() {}).getData();
// Get all prepared queries
- List<QueryPrepareHandle> allQueries = (List<QueryPrepareHandle>) target.queryParam("sessionid", lensSessionId)
- .queryParam("queryName", "testQuery1").request().get(new GenericType<List<QueryPrepareHandle>>() {
+ List<QueryPrepareHandle> allQueries = target.queryParam("sessionid", lensSessionId)
+ .queryParam("queryName", "testQuery1").request(mt).get(new GenericType<List<QueryPrepareHandle>>() {
});
assertTrue(allQueries.size() >= 1);
assertTrue(allQueries.contains(pHandle));
- LensPreparedQuery ctx = target.path(pHandle.toString()).queryParam("sessionid", lensSessionId).request()
+ LensPreparedQuery ctx = target.path(pHandle.toString()).queryParam("sessionid", lensSessionId).request(mt)
.get(LensPreparedQuery.class);
assertTrue(ctx.getUserQuery().equalsIgnoreCase("select ID from " + TEST_TABLE));
assertTrue(ctx.getDriverQuery().equalsIgnoreCase("select ID from " + TEST_TABLE));
@@ -519,39 +495,40 @@ public class TestQueryService extends LensJerseyTest {
LensConf conf = new LensConf();
conf.addProperty("my.property", "myvalue");
confpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
confpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- APIResult updateConf = target.path(pHandle.toString()).request()
+ mt));
+ APIResult updateConf = target.path(pHandle.toString()).request(mt)
.put(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class);
assertEquals(updateConf.getStatus(), APIResult.Status.SUCCEEDED);
- ctx = target.path(pHandle.toString()).queryParam("sessionid", lensSessionId).request().get(LensPreparedQuery.class);
+ ctx = target.path(pHandle.toString()).queryParam("sessionid", lensSessionId).request(mt).get(LensPreparedQuery
+ .class);
assertEquals(ctx.getConf().getProperties().get("my.property"), "myvalue");
- QueryHandle handle1 = target.path(pHandle.toString()).request()
+ QueryHandle handle1 = target.path(pHandle.toString()).request(mt)
.post(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), QueryHandle.class);
// Override query name
confpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("queryName").build(), "testQueryName2"));
// do post once again
- QueryHandle handle2 = target.path(pHandle.toString()).request()
+ QueryHandle handle2 = target.path(pHandle.toString()).request(mt)
.post(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), QueryHandle.class);
assertNotEquals(handle1, handle2);
- LensQuery ctx1 = waitForQueryToFinish(target(), lensSessionId, handle1, Status.SUCCESSFUL);
+ LensQuery ctx1 = waitForQueryToFinish(target(), lensSessionId, handle1, Status.SUCCESSFUL, mt);
assertEquals(ctx1.getQueryName().toLowerCase(), "testquery1");
- LensQuery ctx2 = waitForQueryToFinish(target(), lensSessionId, handle2, Status.SUCCESSFUL);
+ LensQuery ctx2 = waitForQueryToFinish(target(), lensSessionId, handle2, Status.SUCCESSFUL, mt);
assertEquals(ctx2.getQueryName().toLowerCase(), "testqueryname2");
// destroy prepared
- APIResult result = target.path(pHandle.toString()).queryParam("sessionid", lensSessionId).request()
+ APIResult result = target.path(pHandle.toString()).queryParam("sessionid", lensSessionId).request(mt)
.delete(APIResult.class);
assertEquals(result.getStatus(), APIResult.Status.SUCCEEDED);
// Post on destroyed query
- Response response = target.path(pHandle.toString()).request()
+ Response response = target.path(pHandle.toString()).request(mt)
.post(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), Response.class);
assertEquals(response.getStatus(), 404);
}
@@ -561,19 +538,19 @@ public class TestQueryService extends LensJerseyTest {
*
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testExplainAndPrepareQuery() throws InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testExplainAndPrepareQuery(MediaType mt) throws InterruptedException {
final WebTarget target = target().path("queryapi/preparedqueries");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from " + TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain_and_prepare"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final QueryPlan plan = target.request()
+ final QueryPlan plan = target.request(mt)
.post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryPlan>>() {}).getData();
@@ -582,7 +559,7 @@ public class TestQueryService extends LensJerseyTest {
assertNotNull(plan.getPrepareHandle());
LensPreparedQuery ctx = target.path(plan.getPrepareHandle().toString()).queryParam("sessionid", lensSessionId)
- .request().get(LensPreparedQuery.class);
+ .request(mt).get(LensPreparedQuery.class);
assertTrue(ctx.getUserQuery().equalsIgnoreCase("select ID from " + TEST_TABLE));
assertTrue(ctx.getDriverQuery().equalsIgnoreCase("select ID from " + TEST_TABLE));
//both drivers hive/hive1 and hive/hive2 are capable of handling the query as they point to the same hive server
@@ -594,35 +571,35 @@ public class TestQueryService extends LensJerseyTest {
LensConf conf = new LensConf();
conf.addProperty("my.property", "myvalue");
confpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
confpart.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- APIResult updateConf = target.path(plan.getPrepareHandle().toString()).request()
+ mt));
+ APIResult updateConf = target.path(plan.getPrepareHandle().toString()).request(mt)
.put(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class);
assertEquals(updateConf.getStatus(), APIResult.Status.SUCCEEDED);
- ctx = target.path(plan.getPrepareHandle().toString()).queryParam("sessionid", lensSessionId).request()
+ ctx = target.path(plan.getPrepareHandle().toString()).queryParam("sessionid", lensSessionId).request(mt)
.get(LensPreparedQuery.class);
assertEquals(ctx.getConf().getProperties().get("my.property"), "myvalue");
- QueryHandle handle1 = target.path(plan.getPrepareHandle().toString()).request()
+ QueryHandle handle1 = target.path(plan.getPrepareHandle().toString()).request(mt)
.post(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), QueryHandle.class);
// do post once again
- QueryHandle handle2 = target.path(plan.getPrepareHandle().toString()).request()
+ QueryHandle handle2 = target.path(plan.getPrepareHandle().toString()).request(mt)
.post(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), QueryHandle.class);
assertNotEquals(handle1, handle2);
- waitForQueryToFinish(target(), lensSessionId, handle1, Status.SUCCESSFUL);
- waitForQueryToFinish(target(), lensSessionId, handle2, Status.SUCCESSFUL);
+ waitForQueryToFinish(target(), lensSessionId, handle1, Status.SUCCESSFUL, mt);
+ waitForQueryToFinish(target(), lensSessionId, handle2, Status.SUCCESSFUL, mt);
// destroy prepared
- APIResult result = target.path(plan.getPrepareHandle().toString()).queryParam("sessionid", lensSessionId).request()
- .delete(APIResult.class);
+ APIResult result = target.path(plan.getPrepareHandle().toString()).queryParam("sessionid", lensSessionId)
+ .request(mt).delete(APIResult.class);
assertEquals(result.getStatus(), APIResult.Status.SUCCEEDED);
// Post on destroyed query
- Response response = target.path(plan.getPrepareHandle().toString()).request()
+ Response response = target.path(plan.getPrepareHandle().toString()).request(mt)
.post(Entity.entity(confpart, MediaType.MULTIPART_FORM_DATA_TYPE), Response.class);
assertEquals(response.getStatus(), 404);
@@ -637,8 +614,8 @@ public class TestQueryService extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Test
- public void testExecuteAsync() throws InterruptedException, IOException, LensException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testExecuteAsync(MediaType mt) throws InterruptedException, IOException, LensException {
// test post execute op
final WebTarget target = target().path("queryapi/queries");
@@ -647,19 +624,19 @@ public class TestQueryService extends LensJerseyTest {
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from "
+ TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
- final QueryHandle handle = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
+ mt));
+ final QueryHandle handle = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandle>>() {}).getData();
assertNotNull(handle);
// Get query
- LensQuery lensQuery = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request()
+ LensQuery lensQuery = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request(mt)
.get(LensQuery.class);
assertTrue(lensQuery.getStatus().getStatus().equals(Status.QUEUED)
|| lensQuery.getStatus().getStatus().equals(Status.LAUNCHED)
@@ -669,7 +646,8 @@ public class TestQueryService extends LensJerseyTest {
// wait till the query finishes
QueryStatus stat = lensQuery.getStatus();
while (!stat.finished()) {
- lensQuery = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request().get(LensQuery.class);
+ lensQuery = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request(mt).get(LensQuery
+ .class);
stat = lensQuery.getStatus();
/* Commented and jira ticket raised for correction: https://issues.apache.org/jira/browse/LENS-683
switch (stat.getStatus()) {
@@ -694,17 +672,18 @@ public class TestQueryService extends LensJerseyTest {
assertEquals(ctx.getPhase1RewrittenQuery(), ctx.getUserQuery()); //Since there is no rewriter in this test
assertEquals(lensQuery.getStatus().getStatus(), QueryStatus.Status.SUCCESSFUL);
- validatePersistedResult(handle, target(), lensSessionId, new String[][]{{"ID", "INT"}, {"IDSTR", "STRING"}}, true);
+ validatePersistedResult(handle, target(), lensSessionId, new String[][]{{"ID", "INT"}, {"IDSTR", "STRING"}},
+ true, mt);
// test cancel query
- final QueryHandle handle2 = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
+ final QueryHandle handle2 = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandle>>() {}).getData();
assertNotNull(handle2);
- APIResult result = target.path(handle2.toString()).queryParam("sessionid", lensSessionId).request()
+ APIResult result = target.path(handle2.toString()).queryParam("sessionid", lensSessionId).request(mt)
.delete(APIResult.class);
// cancel would fail query is already successful
- LensQuery ctx2 = target.path(handle2.toString()).queryParam("sessionid", lensSessionId).request()
+ LensQuery ctx2 = target.path(handle2.toString()).queryParam("sessionid", lensSessionId).request(mt)
.get(LensQuery.class);
if (result.getStatus().equals(APIResult.Status.FAILED)) {
assertEquals(ctx2.getStatus().getStatus(), QueryStatus.Status.SUCCESSFUL,
@@ -720,7 +699,7 @@ public class TestQueryService extends LensJerseyTest {
log.info("Starting httpendpoint test");
final FormDataMultiPart mp3 = new FormDataMultiPart();
mp3.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp3.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from "
+ TEST_TABLE));
mp3.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
@@ -728,12 +707,12 @@ public class TestQueryService extends LensJerseyTest {
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_SET, "true");
mp3.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- final QueryHandle handle3 = target.request().post(Entity.entity(mp3, MediaType.MULTIPART_FORM_DATA_TYPE),
+ mt));
+ final QueryHandle handle3 = target.request(mt).post(Entity.entity(mp3, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandle>>() {}).getData();
// Get query
- waitForQueryToFinish(target(), lensSessionId, handle3, Status.SUCCESSFUL);
+ waitForQueryToFinish(target(), lensSessionId, handle3, Status.SUCCESSFUL, mt);
validateHttpEndPoint(target(), null, handle3, null);
}
@@ -747,19 +726,19 @@ public class TestQueryService extends LensJerseyTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
static void validatePersistedResult(QueryHandle handle, WebTarget parent, LensSessionHandle lensSessionId,
- String[][] schema, boolean isDir) throws IOException {
+ String[][] schema, boolean isDir, MediaType mt) throws IOException {
final WebTarget target = parent.path("queryapi/queries");
// fetch results
validateResultSetMetadata(handle, "",
schema,
- parent, lensSessionId);
+ parent, lensSessionId, mt);
String presultset = target.path(handle.toString()).path("resultset").queryParam("sessionid", lensSessionId)
- .request().get(String.class);
+ .request(mt).get(String.class);
System.out.println("PERSISTED RESULT:" + presultset);
PersistentQueryResult resultset = target.path(handle.toString()).path("resultset")
- .queryParam("sessionid", lensSessionId).request().get(PersistentQueryResult.class);
+ .queryParam("sessionid", lensSessionId).request(mt).get(PersistentQueryResult.class);
validatePersistentResult(resultset, handle, isDir);
if (isDir) {
@@ -781,7 +760,7 @@ public class TestQueryService extends LensJerseyTest {
assertTrue(resultset.getPersistedURI().contains(handle.toString()));
Path actualPath = new Path(resultset.getPersistedURI());
FileSystem fs = actualPath.getFileSystem(new Configuration());
- List<String> actualRows = new ArrayList<String>();
+ List<String> actualRows = new ArrayList<>();
if (fs.getFileStatus(actualPath).isDir()) {
assertTrue(isDir);
for (FileStatus fstat : fs.listStatus(actualPath)) {
@@ -832,7 +811,7 @@ public class TestQueryService extends LensJerseyTest {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(in));
- String line = "";
+ String line;
while ((line = br.readLine()) != null) {
actualRows.add(line);
@@ -951,8 +930,8 @@ public class TestQueryService extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Test
- public void testExecuteAsyncInMemoryResult() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testExecuteAsyncInMemoryResult(MediaType mt) throws InterruptedException, IOException {
// test post execute op
final WebTarget target = target().path("queryapi/queries");
@@ -960,28 +939,26 @@ public class TestQueryService extends LensJerseyTest {
LensConf conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from "
+ TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- final QueryHandle handle = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
+ mt));
+ final QueryHandle handle = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandle>>() {}).getData();
assertNotNull(handle);
// Get query
- waitForQueryToFinish(target(), lensSessionId, handle, Status.SUCCESSFUL);
+ waitForQueryToFinish(target(), lensSessionId, handle, Status.SUCCESSFUL, mt);
// fetch results
validateResultSetMetadata(handle, "",
new String[][]{{"ID", "INT"}, {"IDSTR", "STRING"}},
- target(), lensSessionId);
+ target(), lensSessionId, mt);
- InMemoryQueryResult resultset = target.path(handle.toString()).path("resultset")
- .queryParam("sessionid", lensSessionId).request().get(InMemoryQueryResult.class);
- validateInmemoryResult(resultset);
+ validateInmemoryResult(target, handle, mt);
validNotFoundForHttpResult(target(), lensSessionId, handle);
waitForPurge(0, queryService.finishedQueries);
@@ -1004,12 +981,12 @@ public class TestQueryService extends LensJerseyTest {
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_SET, "false");
conf.addProperty(LensConfConstants.QUERY_MAIL_NOTIFY, "false");
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ defaultMT));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from "
+ TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
+ defaultMT));
final QueryHandle handle =
target
@@ -1019,7 +996,7 @@ public class TestQueryService extends LensJerseyTest {
}).getData();
assertNotNull(handle);
- waitForQueryToFinish(target(), lensSessionId, handle, Status.SUCCESSFUL);
+ waitForQueryToFinish(target(), lensSessionId, handle, Status.SUCCESSFUL, defaultMT);
// Check TTL
QueryContext ctx = queryService.getQueryContext(lensSessionId, handle);
@@ -1048,8 +1025,8 @@ public class TestQueryService extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Test
- public void testExecuteAsyncTempTable() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testExecuteAsyncTempTable(MediaType mt) throws InterruptedException, IOException {
// test post execute op
final WebTarget target = target().path("queryapi/queries");
@@ -1057,61 +1034,59 @@ public class TestQueryService extends LensJerseyTest {
LensConf conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
drop.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
drop.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(),
"drop table if exists temp_output"));
drop.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
drop.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- final QueryHandle dropHandle = target.request().post(Entity.entity(drop, MediaType.MULTIPART_FORM_DATA_TYPE),
+ mt));
+ final QueryHandle dropHandle = target.request(mt).post(Entity.entity(drop, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandle>>() {}).getData();
assertNotNull(dropHandle);
// Get query
- waitForQueryToFinish(target(), lensSessionId, dropHandle, Status.SUCCESSFUL);
+ waitForQueryToFinish(target(), lensSessionId, dropHandle, Status.SUCCESSFUL, mt);
final FormDataMultiPart mp = new FormDataMultiPart();
conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(),
"create table temp_output as select ID, IDSTR from " + TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- final QueryHandle handle = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
+ mt));
+ final QueryHandle handle = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandle>>() {}).getData();
assertNotNull(handle);
// Get query
- waitForQueryToFinish(target(), lensSessionId, handle, Status.SUCCESSFUL);
+ waitForQueryToFinish(target(), lensSessionId, handle, Status.SUCCESSFUL, mt);
String select = "SELECT * FROM temp_output";
final FormDataMultiPart fetch = new FormDataMultiPart();
fetch.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
fetch.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), select));
fetch.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
fetch.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- final QueryHandle handle2 = target.request().post(Entity.entity(fetch, MediaType.MULTIPART_FORM_DATA_TYPE),
+ mt));
+ final QueryHandle handle2 = target.request(mt).post(Entity.entity(fetch, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandle>>() {}).getData();
assertNotNull(handle2);
// Get query
- waitForQueryToFinish(target(), lensSessionId, handle2, Status.SUCCESSFUL);
+ waitForQueryToFinish(target(), lensSessionId, handle2, Status.SUCCESSFUL, mt);
// fetch results
validateResultSetMetadata(handle2, "temp_output.", new String[][]{{"ID", "INT"}, {"IDSTR", "STRING"}},
- target(), lensSessionId);
+ target(), lensSessionId, mt);
- InMemoryQueryResult resultset = target.path(handle2.toString()).path("resultset")
- .queryParam("sessionid", lensSessionId).request().get(InMemoryQueryResult.class);
- validateInmemoryResult(resultset);
+ validateInmemoryResult(target, handle2, mt);
}
/**
@@ -1121,10 +1096,11 @@ public class TestQueryService extends LensJerseyTest {
* @param parent the parent
* @param lensSessionId the lens session id
*/
- static void validateResultSetMetadata(QueryHandle handle, WebTarget parent, LensSessionHandle lensSessionId) {
+ static void validateResultSetMetadata(QueryHandle handle, WebTarget parent, LensSessionHandle lensSessionId,
+ MediaType mt) {
validateResultSetMetadata(handle, "",
new String[][]{{"ID", "INT"}, {"IDSTR", "STRING"}, {"IDARR", "ARRAY"}, {"IDSTRARR", "ARRAY"}},
- parent, lensSessionId);
+ parent, lensSessionId, mt);
}
/**
@@ -1136,11 +1112,11 @@ public class TestQueryService extends LensJerseyTest {
* @param lensSessionId the lens session id
*/
static void validateResultSetMetadata(QueryHandle handle, String outputTablePfx, String[][] columns, WebTarget parent,
- LensSessionHandle lensSessionId) {
+ LensSessionHandle lensSessionId, MediaType mt) {
final WebTarget target = parent.path("queryapi/queries");
QueryResultSetMetadata metadata = target.path(handle.toString()).path("resultsetmetadata")
- .queryParam("sessionid", lensSessionId).request().get(QueryResultSetMetadata.class);
+ .queryParam("sessionid", lensSessionId).request(mt).get(QueryResultSetMetadata.class);
assertEquals(metadata.getColumns().size(), columns.length);
for (int i = 0; i < columns.length; i++) {
assertTrue(
@@ -1150,6 +1126,28 @@ public class TestQueryService extends LensJerseyTest {
assertEquals(columns[i][1].toLowerCase(), metadata.getColumns().get(i).getType().name().toLowerCase());
}
}
+ private void validateInmemoryResult(WebTarget target, QueryHandle handle, MediaType mt) throws IOException {
+ if (mt.equals(MediaType.APPLICATION_JSON_TYPE)) {
+ String resultSet = target.path(handle.toString()).path("resultset")
+ .queryParam("sessionid", lensSessionId).request(mt).get(String.class);
+ // this is being done because json unmarshalling does not work to construct java Objects back
+ assertEquals(resultSet.replaceAll("\\W", ""), expectedJsonResult().replaceAll("\\W", ""));
+ } else {
+ InMemoryQueryResult resultSet = target.path(handle.toString()).path("resultset")
+ .queryParam("sessionid", lensSessionId).request(mt).get(InMemoryQueryResult.class);
+ validateInmemoryResult(resultSet);
+ }
+ }
+ private String expectedJsonResult() {
+ StringBuilder expectedJson = new StringBuilder();
+ expectedJson.append("{\"inMemoryQueryResult\" : {\"rows\" : [ ")
+ .append("{\"values\" : [ {\n\"type\" : \"int\",\n\"value\" : 1}, {\"type\" : \"string\",\"value\" : \"one\"} ]},")
+ .append("{\"values\" : [ null, {\"type\" : \"string\",\"value\" : \"two\"} ]},")
+ .append("{\"values\" : [ {\"type\" : \"int\",\"value\" : 3}, null ]},")
+ .append("{\"values\" : [ null, null ]},")
+ .append("{\"values\" : [ {\"type\" : \"int\",\"value\" : 5}, {\"type\" : \"string\",\"value\" : \"\"} ]} ]}}");
+ return expectedJson.toString();
+ }
/**
* Validate inmemory result.
@@ -1182,22 +1180,22 @@ public class TestQueryService extends LensJerseyTest {
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testExecuteWithTimeoutQuery() throws IOException, InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testExecuteWithTimeoutQuery(MediaType mt) throws IOException, InterruptedException {
final WebTarget target = target().path("queryapi/queries");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from "
+ TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute_with_timeout"));
// set a timeout value enough for tests
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("timeoutmillis").build(), "300000"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- QueryHandleWithResultSet result = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
+ QueryHandleWithResultSet result = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandleWithResultSet>>() {}).getData();
assertNotNull(result.getQueryHandle());
assertNotNull(result.getResult());
@@ -1207,43 +1205,55 @@ public class TestQueryService extends LensJerseyTest {
LensConf conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from "
+ TEST_TABLE));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute_with_timeout"));
// set a timeout value enough for tests
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("timeoutmillis").build(), "300000"));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- result = target.request().post(Entity.entity(mp2, MediaType.MULTIPART_FORM_DATA_TYPE),
- new GenericType<LensAPIResult<QueryHandleWithResultSet>>() {}).getData();
- assertNotNull(result.getQueryHandle());
- assertNotNull(result.getResult());
- validateInmemoryResult((InMemoryQueryResult) result.getResult());
+ validateInmemoryResultForTimeoutQuery(target, mp2, mt);
}
+ private void validateInmemoryResultForTimeoutQuery(WebTarget target, FormDataMultiPart mp, MediaType mt) {
+ if (mt.equals(MediaType.APPLICATION_JSON_TYPE)) {
+ String result = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class);
+ assertTrue(result.contains("\"type\" : \"queryHandleWithResultSet\""));
+ assertTrue(result.contains("\"status\" : \"SUCCESSFUL\""));
+ assertTrue(result.contains("\"isResultSetAvailable\" : true"));
+ assertTrue(result.replaceAll("\\W", "").contains(expectedJsonResult().replaceAll("\\W", "")));
+ } else {
+ QueryHandleWithResultSet result = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
+ new GenericType<LensAPIResult<QueryHandleWithResultSet>>() {
+ }).getData();
+ assertNotNull(result.getQueryHandle());
+ assertNotNull(result.getResult());
+ validateInmemoryResult((InMemoryQueryResult) result.getResult());
+ }
+ }
/**
* Test execute with timeout query.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testExecuteWithTimeoutFailingQuery() throws IOException, InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testExecuteWithTimeoutFailingQuery(MediaType mt) throws IOException, InterruptedException {
final WebTarget target = target().path("queryapi/queries");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from nonexist"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute_with_timeout"));
// set a timeout value enough for tests
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("timeoutmillis").build(), "300000"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- Response response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
+ Response response = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
assertEquals(response.getStatus(), BAD_REQUEST.getStatusCode());
}
@@ -1281,7 +1291,7 @@ public class TestQueryService extends LensJerseyTest {
final String query = "select ID from " + TEST_TABLE;
QueryContext ctx = new QueryContext(query, null, queryConf, conf, queryService.getDrivers());
- Map<LensDriver, String> driverQueries = new HashMap<LensDriver, String>();
+ Map<LensDriver, String> driverQueries = new HashMap<>();
for (LensDriver driver : queryService.getDrivers()) {
driverQueries.put(driver, query);
}
@@ -1335,20 +1345,20 @@ public class TestQueryService extends LensJerseyTest {
*
* @throws InterruptedException the interrupted exception
*/
- @Test
- public void testEstimateNativeQuery() throws InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testEstimateNativeQuery(MediaType mt) throws InterruptedException {
final WebTarget target = target().path("queryapi/queries");
// estimate native query
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from " + TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "estimate"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final QueryCostTO result = target.request()
+ final QueryCostTO result = target.request(mt)
.post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryCostTO>>() {}).getData();
assertNotNull(result);
@@ -1361,8 +1371,8 @@ public class TestQueryService extends LensJerseyTest {
* Check if DB static jars get passed to Hive driver
* @throws Exception
*/
- @Test
- public void testHiveDriverGetsDBJars() throws Exception {
+ @Test(dataProvider = "mediaTypeData")
+ public void testHiveDriverGetsDBJars(MediaType mt) throws Exception {
// Set DB to a db with static jars
HiveSessionService sessionService = LensServices.get().getService(SessionService.NAME);
@@ -1385,7 +1395,7 @@ public class TestQueryService extends LensJerseyTest {
try {
// First execute query on the session with db should load jars from DB
LensServerTestUtil.createTable(tableInDBWithJars, target(), sessionHandle, "(ID INT, IDSTR STRING) "
- + "ROW FORMAT SERDE \"DatabaseJarSerde\"");
+ + "ROW FORMAT SERDE \"DatabaseJarSerde\"", mt);
boolean addedToHiveDriver = false;
@@ -1404,7 +1414,7 @@ public class TestQueryService extends LensJerseyTest {
log.info("@@@# database switch test");
session.setCurrentDatabase(DB_WITH_JARS_2);
LensServerTestUtil.createTable(tableInDBWithJars + "_2", target(), sessionHandle, "(ID INT, IDSTR STRING) "
- + "ROW FORMAT SERDE \"DatabaseJarSerde\"");
+ + "ROW FORMAT SERDE \"DatabaseJarSerde\"", mt);
// All db jars should have been added
assertTrue(session.getDBResources(DB_WITH_JARS_2).isEmpty());
@@ -1423,8 +1433,8 @@ public class TestQueryService extends LensJerseyTest {
} finally {
log.info("@@@ TEST_OVER");
try {
- LensServerTestUtil.dropTable(tableInDBWithJars, target(), sessionHandle);
- LensServerTestUtil.dropTable(tableInDBWithJars + "_2", target(), sessionHandle);
+ LensServerTestUtil.dropTable(tableInDBWithJars, target(), sessionHandle, mt);
+ LensServerTestUtil.dropTable(tableInDBWithJars + "_2", target(), sessionHandle, mt);
} catch (Throwable th) {
log.error("Exception while dropping table.", th);
}
@@ -1432,21 +1442,21 @@ public class TestQueryService extends LensJerseyTest {
}
}
- @Test
- public void testRewriteFailure() {
+ @Test(dataProvider = "mediaTypeData")
+ public void testRewriteFailure(MediaType mt) {
final WebTarget target = target().path("queryapi/queries");
// estimate cube query which fails semantic analysis
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(),
"cube sdfelect ID from cube_nonexist"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "estimate"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final Response response = target.request()
+ final Response response = target.request(mt)
.post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
@@ -1480,36 +1490,37 @@ public class TestQueryService extends LensJerseyTest {
}
}
- @Test
- public void testNonSelectQueriesWithPersistResult() throws InterruptedException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testNonSelectQueriesWithPersistResult(MediaType mt) throws InterruptedException {
LensConf conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "true");
String tblName = "testNonSelectQueriesWithPersistResult";
- LensServerTestUtil.dropTableWithConf(tblName, target(), lensSessionId, conf);
+ LensServerTestUtil.dropTableWithConf(tblName, target(), lensSessionId, conf, mt);
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_SET, "true");
- LensServerTestUtil.dropTableWithConf(tblName, target(), lensSessionId, conf);
+ LensServerTestUtil.dropTableWithConf(tblName, target(), lensSessionId, conf, mt);
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
- LensServerTestUtil.dropTableWithConf(tblName, target(), lensSessionId, conf);
+ LensServerTestUtil.dropTableWithConf(tblName, target(), lensSessionId, conf, mt);
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_SET, "false");
- LensServerTestUtil.dropTableWithConf(tblName, target(), lensSessionId, conf);
+ LensServerTestUtil.dropTableWithConf(tblName, target(), lensSessionId, conf, mt);
}
- @Test
- public void testEstimateGauges() {
+ @Test(dataProvider = "mediaTypeData")
+ public void testEstimateGauges(MediaType mt) {
final WebTarget target = target().path("queryapi/queries");
LensConf conf = new LensConf();
- conf.addProperty(LensConfConstants.QUERY_METRIC_UNIQUE_ID_CONF_KEY, "TestQueryService-testEstimateGauges");
+ String gaugeKey = "TestQueryService-testEstimateGauges" + mt.getSubtype();
+ conf.addProperty(LensConfConstants.QUERY_METRIC_UNIQUE_ID_CONF_KEY, gaugeKey);
// estimate native query
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID from " + TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "estimate"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- final QueryCostTO queryCostTO = target.request()
+ final QueryCostTO queryCostTO = target.request(mt)
.post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryCostTO>>() {
}).getData();
@@ -1518,34 +1529,34 @@ public class TestQueryService extends LensJerseyTest {
MetricRegistry reg = LensMetricsRegistry.getStaticRegistry();
assertTrue(reg.getGauges().keySet().containsAll(Arrays.asList(
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-DRIVER_SELECTION",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-hive/hive1-CUBE_REWRITE",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-hive/hive1-DRIVER_ESTIMATE",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-hive/hive1-RewriteUtil-rewriteQuery",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-hive/hive2-CUBE_REWRITE",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-hive/hive2-DRIVER_ESTIMATE",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-hive/hive2-RewriteUtil-rewriteQuery",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-jdbc/jdbc1-CUBE_REWRITE",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-jdbc/jdbc1-DRIVER_ESTIMATE",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-jdbc/jdbc1-RewriteUtil-rewriteQuery",
- "lens.MethodMetricGauge.TestQueryService-testEstimateGauges-PARALLEL_ESTIMATE")),
+ "lens.MethodMetricGauge." + gaugeKey + "-DRIVER_SELECTION",
+ "lens.MethodMetricGauge." + gaugeKey + "-hive/hive1-CUBE_REWRITE",
+ "lens.MethodMetricGauge." + gaugeKey + "-hive/hive1-DRIVER_ESTIMATE",
+ "lens.MethodMetricGauge." + gaugeKey + "-hive/hive1-RewriteUtil-rewriteQuery",
+ "lens.MethodMetricGauge." + gaugeKey + "-hive/hive2-CUBE_REWRITE",
+ "lens.MethodMetricGauge." + gaugeKey + "-hive/hive2-DRIVER_ESTIMATE",
+ "lens.MethodMetricGauge." + gaugeKey + "-hive/hive2-RewriteUtil-rewriteQuery",
+ "lens.MethodMetricGauge." + gaugeKey + "-jdbc/jdbc1-CUBE_REWRITE",
+ "lens.MethodMetricGauge." + gaugeKey + "-jdbc/jdbc1-DRIVER_ESTIMATE",
+ "lens.MethodMetricGauge." + gaugeKey + "-jdbc/jdbc1-RewriteUtil-rewriteQuery",
+ "lens.MethodMetricGauge." + gaugeKey + "-PARALLEL_ESTIMATE")),
reg.getGauges().keySet().toString());
}
- @Test
- public void testQueryRejection() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testQueryRejection(MediaType mt) throws InterruptedException, IOException {
final WebTarget target = target().path("queryapi/queries");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "blah select ID from "
+ TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ mt));
- Response response = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
+ Response response = target.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
assertEquals(response.getStatus(), 400);
}
@@ -1555,29 +1566,29 @@ public class TestQueryService extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Test
- public void testQueryPurger() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testQueryPurger(MediaType mt) throws InterruptedException, IOException {
waitForPurge();
LensConf conf = getLensConf(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
// test post execute op
LensQuery ctx1 = executeAndWaitForQueryToFinish(target(), lensSessionId,
"select ID, IDSTR from " + TEST_TABLE,
- Optional.of(conf), Optional.of(Status.SUCCESSFUL));
+ Optional.of(conf), Optional.of(Status.SUCCESSFUL), mt);
LensQuery ctx2 = executeAndWaitForQueryToFinish(target(), lensSessionId,
"select ID, IDSTR from " + TEST_TABLE,
- Optional.of(conf), Optional.of(Status.SUCCESSFUL));
+ Optional.of(conf), Optional.of(Status.SUCCESSFUL), mt);
LensQuery ctx3 = executeAndWaitForQueryToFinish(target(), lensSessionId,
"select ID, IDSTR from " + TEST_TABLE,
- Optional.of(conf), Optional.of(Status.SUCCESSFUL));
+ Optional.of(conf), Optional.of(Status.SUCCESSFUL), mt);
waitForPurge(3, queryService.finishedQueries);
assertEquals(queryService.finishedQueries.size(), 3);
- getLensQueryResult(target(), lensSessionId, ctx3.getQueryHandle());
+ getLensQueryResultAsString(target(), lensSessionId, ctx3.getQueryHandle(), mt);
waitForPurge(2, queryService.finishedQueries);
assertTrue(queryService.finishedQueries.size() == 2);
- getLensQueryResult(target(), lensSessionId, ctx2.getQueryHandle());
+ getLensQueryResultAsString(target(), lensSessionId, ctx2.getQueryHandle(), mt);
waitForPurge(1, queryService.finishedQueries);
assertTrue(queryService.finishedQueries.size() == 1);
- getLensQueryResult(target(), lensSessionId, ctx1.getQueryHandle());
+ getLensQueryResultAsString(target(), lensSessionId, ctx1.getQueryHandle(), mt);
}
/**
@@ -1585,19 +1596,19 @@ public class TestQueryService extends LensJerseyTest {
*
* @throws Exception
*/
- @Test
- public void testSessionClose() throws Exception {
+ @Test(dataProvider = "mediaTypeData")
+ public void testSessionClose(MediaType mt) throws Exception {
// Query with group by, will run long enough to close the session before finish
String query = "select ID, IDSTR, count(*) from " + TEST_TABLE + " group by ID, IDSTR";
SessionService sessionService = LensServices.get().getService(HiveSessionService.NAME);
- Map<String, String> sessionconf = new HashMap<String, String>();
+ Map<String, String> sessionconf = new HashMap<>();
LensSessionHandle sessionHandle = sessionService.openSession("foo", "bar", "default", sessionconf);
LensConf conf = getLensConf(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "true");
QueryHandle qHandle =
- executeAndGetHandle(target(), Optional.of(sessionHandle), Optional.of(query), Optional.of(conf));
+ executeAndGetHandle(target(), Optional.of(sessionHandle), Optional.of(query), Optional.of(conf), mt);
sessionService.closeSession(sessionHandle);
sessionHandle = sessionService.openSession("foo", "bar", "default", sessionconf);
- waitForQueryToFinish(target(), sessionHandle, qHandle, Status.SUCCESSFUL);
+ waitForQueryToFinish(target(), sessionHandle, qHandle, Status.SUCCESSFUL, mt);
}
@AfterMethod
http://git-wip-us.apache.org/repos/asf/lens/blob/d559ef2e/lens-server/src/test/java/org/apache/lens/server/query/TestResultFormatting.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/query/TestResultFormatting.java b/lens-server/src/test/java/org/apache/lens/server/query/TestResultFormatting.java
index 30d1e34..6db990e 100644
--- a/lens-server/src/test/java/org/apache/lens/server/query/TestResultFormatting.java
+++ b/lens-server/src/test/java/org/apache/lens/server/query/TestResultFormatting.java
@@ -49,11 +49,9 @@ import org.apache.lens.server.common.TestResourceFile;
import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe;
-import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
-import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@@ -84,8 +82,8 @@ public class TestResultFormatting extends LensJerseyTest {
queryService = LensServices.get().getService(QueryExecutionService.NAME);
lensSessionId = queryService.openSession("foo", "bar", new HashMap<String, String>());
createTable(testTable, target(), lensSessionId,
- "(ID INT, IDSTR STRING, IDARR ARRAY<INT>, IDSTRARR ARRAY<STRING>)");
- loadDataFromClasspath(testTable, TestResourceFile.TEST_DATA2_FILE.getValue(), target(), lensSessionId);
+ "(ID INT, IDSTR STRING, IDARR ARRAY<INT>, IDSTRARR ARRAY<STRING>)", defaultMT);
+ loadDataFromClasspath(testTable, TestResourceFile.TEST_DATA2_FILE.getValue(), target(), lensSessionId, defaultMT);
}
/*
@@ -95,7 +93,7 @@ public class TestResultFormatting extends LensJerseyTest {
*/
@AfterTest
public void tearDown() throws Exception {
- dropTable(testTable, target(), lensSessionId);
+ dropTable(testTable, target(), lensSessionId, defaultMT);
queryService.closeSession(lensSessionId);
super.tearDown();
}
@@ -110,16 +108,6 @@ public class TestResultFormatting extends LensJerseyTest {
return new QueryApp();
}
- /*
- * (non-Javadoc)
- *
- * @see org.glassfish.jersey.test.JerseyTest#configureClient(org.glassfish.jersey.client.ClientConfig)
- */
- @Override
- protected void configureClient(ClientConfig config) {
- config.register(MultiPartFeature.class);
- }
-
/** The test table. */
private static String testTable = "RESULT_TEST_TABLE";
@@ -131,15 +119,15 @@ public class TestResultFormatting extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Test
- public void testResultFormatterInMemoryResult() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testResultFormatterInMemoryResult(MediaType mt) throws InterruptedException, IOException {
LensConf conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
conf.addProperty(LensConfConstants.QUERY_OUTPUT_SERDE, LazySimpleSerDe.class.getCanonicalName());
- testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, null);
+ testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, null, mt);
queryService.conf.set(LensConfConstants.RESULT_FS_READ_URL, "filereadurl://");
- testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, "filereadurl://");
+ testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, "filereadurl://", mt);
queryService.conf.unset(LensConfConstants.RESULT_FS_READ_URL);
}
@@ -151,14 +139,14 @@ public class TestResultFormatting extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Test
- public void testResultFormatterHDFSpersistentResult() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testResultFormatterHDFSpersistentResult(MediaType mt) throws InterruptedException, IOException {
LensConf conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "true");
- testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, null);
+ testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, null, mt);
queryService.conf.set(LensConfConstants.RESULT_FS_READ_URL, "filereadurl://");
- testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, "filereadurl://");
+ testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, false, "filereadurl://", mt);
queryService.conf.unset(LensConfConstants.RESULT_FS_READ_URL);
}
@@ -168,12 +156,12 @@ public class TestResultFormatting extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Test
- public void testPersistentResultWithMaxSize() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testPersistentResultWithMaxSize(MediaType mt) throws InterruptedException, IOException {
LensConf conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "true");
conf.addProperty(LensConfConstants.RESULT_FORMAT_SIZE_THRESHOLD, "1");
- testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, true, null);
+ testResultFormatter(conf, QueryStatus.Status.SUCCESSFUL, true, null, mt);
}
/**
@@ -182,12 +170,12 @@ public class TestResultFormatting extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Test
- public void testResultFormatterFailure() throws InterruptedException, IOException {
+ @Test(dataProvider = "mediaTypeData")
+ public void testResultFormatterFailure(MediaType mt) throws InterruptedException, IOException {
LensConf conf = new LensConf();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, "false");
conf.addProperty(LensConfConstants.QUERY_OUTPUT_SERDE, "NonexistentSerde.class");
- testResultFormatter(conf, QueryStatus.Status.FAILED, false, null);
+ testResultFormatter(conf, QueryStatus.Status.FAILED, false, null, mt);
}
// test with execute async post with result formatter, get query, get results
@@ -202,33 +190,31 @@ public class TestResultFormatting extends LensJerseyTest {
* @throws InterruptedException the interrupted exception
* @throws IOException Signals that an I/O exception has occurred.
*/
- private void testResultFormatter(LensConf conf, Status status, boolean isDir, String reDirectUrl)
+ private void testResultFormatter(LensConf conf, Status status, boolean isDir, String reDirectUrl, MediaType mt)
throws InterruptedException, IOException {
// test post execute op
final WebTarget target = target().path("queryapi/queries");
final FormDataMultiPart mp = new FormDataMultiPart();
conf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_SET, "true");
- mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(),
"select ID, IDSTR, IDARR, IDSTRARR from " + testTable));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute"));
- mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf,
- MediaType.APPLICATION_XML_TYPE));
- QueryHandle handle = target.request()
+ mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, mt));
+ QueryHandle handle = target.request(mt)
.post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
new GenericType<LensAPIResult<QueryHandle>>() {}).getData();
assertNotNull(handle);
// Get query
- LensQuery ctx = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request()
+ LensQuery ctx = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request(mt)
.get(LensQuery.class);
// wait till the query finishes
QueryStatus stat = ctx.getStatus();
while (!stat.finished()) {
- ctx = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request().get(LensQuery.class);
+ ctx = target.path(handle.toString()).queryParam("sessionid", lensSessionId).request(mt).get(LensQuery.class);
stat = ctx.getStatus();
Thread.sleep(1000);
}
@@ -257,7 +243,7 @@ public class TestResultFormatting extends LensJerseyTest {
// fetch results
TestQueryService.validatePersistedResult(handle, target(), lensSessionId, new String[][]{
{"ID", "INT"}, {"IDSTR", "STRING"}, {"IDARR", "ARRAY"}, {"IDSTRARR", "ARRAY"},
- }, isDir);
+ }, isDir, mt);
if (!isDir) {
TestQueryService.validateHttpEndPoint(target(), lensSessionId, handle, reDirectUrl);
}
http://git-wip-us.apache.org/repos/asf/lens/blob/d559ef2e/lens-server/src/test/java/org/apache/lens/server/query/save/TestSavedQueryService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/query/save/TestSavedQueryService.java b/lens-server/src/test/java/org/apache/lens/server/query/save/TestSavedQueryService.java
index 7c6ce49..70e2dbc 100644
--- a/lens-server/src/test/java/org/apache/lens/server/query/save/TestSavedQueryService.java
+++ b/lens-server/src/test/java/org/apache/lens/server/query/save/TestSavedQueryService.java
@@ -42,8 +42,6 @@ import org.apache.lens.server.api.query.save.SavedQueryService;
import org.apache.lens.server.error.LensExceptionMapper;
import org.apache.lens.server.query.QueryExecutionServiceImpl;
-import org.glassfish.jersey.client.ClientConfig;
-import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@@ -112,12 +110,6 @@ public class TestSavedQueryService extends LensJerseyTest {
return new SavedQueryTestApp();
}
- @Override
- protected void configureClient(ClientConfig config) {
- config.register(MultiPartFeature.class);
- config.register(LensJAXBContextResolver.class);
- }
-
@Test
public void testResource() throws InterruptedException {
assertEquals(