Repository: lens Updated Branches: refs/heads/master f0e458ff5 -> 68c5267f0
LENS-1143: Fix test cases to incorporate LENS-1019 changes Project: http://git-wip-us.apache.org/repos/asf/lens/repo Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/68c5267f Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/68c5267f Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/68c5267f Branch: refs/heads/master Commit: 68c5267f0868b77e24101fdd493d5d733c27871f Parents: f0e458f Author: Lavkesh Lahngir <[email protected]> Authored: Mon Jun 13 16:30:25 2016 +0530 Committer: Rajat Khandelwal <[email protected]> Committed: Mon Jun 13 16:30:25 2016 +0530 ---------------------------------------------------------------------- lens-dist/src/deb/control/ui-control/control | 29 ++ .../lens/server/query/TestDuplicateQueries.java | 198 +++++++++++++ .../server/query/TestQueryServiceDuplicate.java | 285 ------------------- 3 files changed, 227 insertions(+), 285 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lens/blob/68c5267f/lens-dist/src/deb/control/ui-control/control ---------------------------------------------------------------------- diff --git a/lens-dist/src/deb/control/ui-control/control b/lens-dist/src/deb/control/ui-control/control new file mode 100644 index 0000000..d69c3ab --- /dev/null +++ b/lens-dist/src/deb/control/ui-control/control @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +Package: apache-lens-ui +Version: [[project.version]] +Section: misc +Priority: high +Architecture: all +Depends: nodejs +Depends: nodejs-legacy +Depends: npm +Maintainer: [email protected] +Description: Apache Lens UI Distribution +Distribution: beta http://git-wip-us.apache.org/repos/asf/lens/blob/68c5267f/lens-server/src/test/java/org/apache/lens/server/query/TestDuplicateQueries.java ---------------------------------------------------------------------- diff --git a/lens-server/src/test/java/org/apache/lens/server/query/TestDuplicateQueries.java b/lens-server/src/test/java/org/apache/lens/server/query/TestDuplicateQueries.java new file mode 100644 index 0000000..3e9ddb8 --- /dev/null +++ b/lens-server/src/test/java/org/apache/lens/server/query/TestDuplicateQueries.java @@ -0,0 +1,198 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.lens.server.query; + +import static org.testng.Assert.*; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.Application; +import javax.ws.rs.core.MediaType; + +import org.apache.lens.api.LensConf; +import org.apache.lens.api.LensSessionHandle; +import org.apache.lens.api.query.QueryHandle; +import org.apache.lens.driver.hive.HiveDriver; +import org.apache.lens.server.LensJerseyTest; +import org.apache.lens.server.LensServerTestUtil; +import org.apache.lens.server.LensServices; +import org.apache.lens.server.api.LensConfConstants; +import org.apache.lens.server.api.driver.LensDriver; +import org.apache.lens.server.api.query.QueryExecutionService; +import org.apache.lens.server.common.RestAPITestUtil; +import org.apache.lens.server.common.TestResourceFile; +import org.apache.lens.server.query.TestQueryService.QueryServiceTestApp; + +import org.apache.hadoop.hive.conf.HiveConf; + +import org.glassfish.jersey.test.TestProperties; + +import org.testng.annotations.*; + +import com.google.common.base.Optional; + +import lombok.extern.slf4j.Slf4j; + +@Test(groups = "duplicate-query", dependsOnGroups = "two-working-drivers") +@Slf4j +public class TestDuplicateQueries extends LensJerseyTest { + /** + * The test table. + */ + private static final String TEST_TABLE = "TEST_TABLE_DUPLICATE_QUERIES"; + /** + * The query service. + */ + private QueryExecutionServiceImpl queryService; + + /** + * The lens session id. + */ + private LensSessionHandle lensSessionId; + + @BeforeTest + public void setUp() throws Exception { + super.setUp(); + } + + private HiveConf getServerConfLocal() { + HiveConf serverConf = new HiveConf(super.getServerConf()); + serverConf.setBoolean(LensConfConstants.SERVER_DUPLICATE_QUERY_ALLOWED, false); + return serverConf; + } + + /* + * (non-Javadoc) + * + * @see org.glassfish.jersey.test.JerseyTest#tearDown() + */ + @AfterTest + public void tearDown() throws Exception { + super.tearDown(); + } + + @Override + protected Application configure() { + enable(TestProperties.LOG_TRAFFIC); + enable(TestProperties.DUMP_ENTITY); + return new QueryServiceTestApp(); + } + + /** + * Checks duplicate query handle. In the starting of test, the lens-server is + * started with the new configuration. + * + * @throws Exception + */ + @Test + public void testExecuteAsyncDuplicate() throws Exception { + try { + MediaType mt = defaultMT; + log.info("Restarting lens server!"); + restartLensServer(getServerConfLocal(), false); + log.info("Restarted lens server!"); + + queryService = LensServices.get().getService(QueryExecutionService.NAME); + Map<String, String> sessionconf = new HashMap<>(); + sessionconf.put("test.session.key", "svalue"); + lensSessionId = queryService.openSession("foo", "bar", sessionconf); + LensServerTestUtil.createTable(TEST_TABLE, target(), lensSessionId, defaultMT); + LensServerTestUtil + .loadDataFromClasspath(TEST_TABLE, TestResourceFile.TEST_DATA2_FILE.getValue(), target(), lensSessionId, + defaultMT); + queryService.pauseQuerySubmitter(true); + String query = "select ID, IDSTR from " + TEST_TABLE; + + final QueryHandle handle1 = RestAPITestUtil + .executeAndGetHandle(target(), Optional.of(lensSessionId), Optional.of(query), Optional.of(new LensConf()), + mt); + final QueryHandle handle2 = RestAPITestUtil + .executeAndGetHandle(target(), Optional.of(lensSessionId), Optional.of(query), Optional.of(new LensConf()), + mt); + assertNotNull(handle1); + assertNotNull(handle2); + assertEquals(handle1, handle2); + // Cancel the query + queryService.cancelQuery(lensSessionId, handle1); + + // Create a different query + final QueryHandle handle3 = RestAPITestUtil + .executeAndGetHandle(target(), Optional.of(lensSessionId), Optional.of(query), Optional.of(new LensConf()), + mt); + assertNotNull(handle3); + queryService.cancelQuery(lensSessionId, handle3); + // After completion If we launch the same query it should return a new + // handle. + final QueryHandle handle4 = RestAPITestUtil + .executeAndGetHandle(target(), Optional.of(lensSessionId), Optional.of(query), Optional.of(new LensConf()), + mt); + assertNotEquals(handle4, handle3); + queryService.cancelQuery(lensSessionId, handle4); + + // Launch the query in different session should result in the different + // handle. + + final QueryHandle handle5 = RestAPITestUtil + .executeAndGetHandle(target(), Optional.of(lensSessionId), Optional.of(query), Optional.of(new LensConf()), + mt); + sessionconf = new HashMap<>(); + sessionconf.put("test.session.key", "svalue"); + + LensSessionHandle lensSessionId1 = queryService.openSession("foo@localhost", "bar", sessionconf); + + final QueryHandle handle6 = RestAPITestUtil + .executeAndGetHandle(target(), Optional.of(lensSessionId1), Optional.of(query), Optional.of(new LensConf()), + mt); + assertNotNull(handle5); + assertNotNull(handle6); + assertNotEquals(handle5, handle6); + queryService.cancelQuery(lensSessionId, handle5); + queryService.cancelQuery(lensSessionId1, handle6); + queryService.closeSession(lensSessionId1); + + // Different conf should different handle + LensConf conf = new LensConf(); + final QueryHandle handle7 = RestAPITestUtil + .executeAndGetHandle(target(), Optional.of(lensSessionId), Optional.of(query), Optional.of(conf), mt); + // Add a property + conf.addProperty("test", "test"); + final QueryHandle handle8 = RestAPITestUtil + .executeAndGetHandle(target(), Optional.of(lensSessionId), Optional.of(query), Optional.of(conf), mt); + assertNotNull(handle7); + assertNotNull(handle8); + assertNotEquals(handle7, handle8); + queryService.cancelQuery(lensSessionId, handle7); + queryService.cancelQuery(lensSessionId, handle8); + } finally { + // restart server with correct configuration + queryService.pauseQuerySubmitter(false); + LensServerTestUtil.dropTable(TEST_TABLE, target(), lensSessionId, defaultMT); + queryService.closeSession(lensSessionId); + for (LensDriver driver : queryService.getDrivers()) { + if (driver instanceof HiveDriver) { + assertFalse(((HiveDriver) driver).hasLensSession(lensSessionId)); + } + } + log.info("Restarting lens server!"); + restartLensServer(super.getServerConf(), false); + log.info("Restarted lens server!"); + } + } +} http://git-wip-us.apache.org/repos/asf/lens/blob/68c5267f/lens-server/src/test/java/org/apache/lens/server/query/TestQueryServiceDuplicate.java ---------------------------------------------------------------------- diff --git a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryServiceDuplicate.java b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryServiceDuplicate.java deleted file mode 100644 index a6ded7e..0000000 --- a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryServiceDuplicate.java +++ /dev/null @@ -1,285 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.lens.server.query; - -import java.util.HashMap; -import java.util.Map; - -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 org.apache.lens.api.APIResult; -import org.apache.lens.api.LensConf; -import org.apache.lens.api.LensSessionHandle; -import org.apache.lens.api.query.QueryHandle; -import org.apache.lens.api.result.LensAPIResult; -import org.apache.lens.driver.hive.HiveDriver; -import org.apache.lens.server.LensJerseyTest; -import org.apache.lens.server.LensServerTestUtil; -import org.apache.lens.server.LensServices; -import org.apache.lens.server.api.LensConfConstants; -import org.apache.lens.server.api.driver.LensDriver; -import org.apache.lens.server.api.metrics.MetricsService; -import org.apache.lens.server.api.query.QueryExecutionService; -import org.apache.lens.server.api.util.LensUtil; -import org.apache.lens.server.common.TestResourceFile; -import org.apache.lens.server.query.TestQueryService.QueryServiceTestApp; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertNotNull; - -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.test.TestProperties; - -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import lombok.extern.slf4j.Slf4j; - -@Test(groups = "duplicate-query", dependsOnGroups = "two-working-drivers") -@Slf4j -public class TestQueryServiceDuplicate extends LensJerseyTest { - /** The query service. */ - QueryExecutionServiceImpl queryService; - - /** The metrics svc. */ - MetricsService metricsSvc; - - /** The lens session id. */ - LensSessionHandle lensSessionId; - - @BeforeTest - public void setUp() throws Exception { - super.setUp(); - } - - @AfterTest - public void tearDown() throws Exception { - super.tearDown(); - } - - @Override - public Map<String, String> getServerConfOverWrites() { - return LensUtil.getHashMap(LensConfConstants.SERVER_DUPLICATE_QUERY_ALLOWED, String.valueOf(false)); - } - - @Override - protected Application configure() { - enable(TestProperties.LOG_TRAFFIC); - enable(TestProperties.DUMP_ENTITY); - return new QueryServiceTestApp(); - } - - /** The test table. */ - public static final String TEST_TABLE = "TEST_TABLE"; - - /** - * Creates the table. - * - * @param tblName - * the tbl name - * @throws InterruptedException - * the interrupted exception - */ - private void createTable(String tblName) throws InterruptedException { - LensServerTestUtil.createTable(tblName, target(), lensSessionId, defaultMT); - } - - /** - * Load data. - * - * @param tblName - * the tbl name - * @param testDataFile - * the test data file - * @throws InterruptedException - * the interrupted exception - */ - private void loadData(String tblName, final String testDataFile) throws InterruptedException { - LensServerTestUtil.loadDataFromClasspath(tblName, testDataFile, target(), lensSessionId, defaultMT); - } - - /** - * Drop table. - * - * @param tblName - * the tbl name - * @throws InterruptedException - * the interrupted exception - */ - private void dropTable(String tblName) throws InterruptedException { - LensServerTestUtil.dropTable(tblName, target(), lensSessionId, defaultMT); - } - - /** - * Checks duplicate query handle. In the starting of test, the lens-server is - * started with the new configuration. - * - * @throws Exception - */ - public void testExecuteAsyncDuplicate() throws Exception { - MediaType mt = MediaType.APPLICATION_JSON_TYPE; - log.info("Restarting lens server!"); - restartLensServer(getServerConf(), false); - log.info("Restarted lens server!"); - queryService = LensServices.get().getService(QueryExecutionService.NAME); - metricsSvc = LensServices.get().getService(MetricsService.NAME); - Map<String, String> sessionconf = new HashMap<>(); - sessionconf.put("test.session.key", "svalue"); - lensSessionId = queryService.openSession("foo", "bar", sessionconf); - // automatically - createTable(TEST_TABLE); - loadData(TEST_TABLE, TestResourceFile.TEST_DATA2_FILE.getValue()); - final WebTarget target = target().path("queryapi/queries"); - queryService.pauseQuerySubmitter(true); - try { - final FormDataMultiPart mp = new FormDataMultiPart(); - mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, 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(), mt)); - // Dummy query - final QueryHandle handle = target.request(mt) - .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - - target.path(handle.toString()).queryParam("sessionid", lensSessionId).request(mt).delete(APIResult.class); - - final QueryHandle handle1 = target.request(mt) - .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - - final QueryHandle handle2 = target.request(mt) - .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - - assertNotNull(handle1); - assertNotNull(handle2); - assertEquals(handle1, handle2); - // Cancel the query - target.path(handle1.toString()).queryParam("sessionid", lensSessionId).request(mt).delete(APIResult.class); - - // Create a different query - final FormDataMultiPart mp1 = new FormDataMultiPart(); - mp1.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt)); - mp1.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from " - + TEST_TABLE)); - mp1.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); - mp1.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), - new LensConf(), mt)); - final QueryHandle handle3 = target.request(mt) - .post(Entity.entity(mp1, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - assertNotNull(handle3); - target.path(handle3.toString()).queryParam("sessionid", lensSessionId).request(mt).delete(APIResult.class); - - // After completion If we launch the same query it should return a new - // handle. - final QueryHandle handle4 = target.request(mt) - .post(Entity.entity(mp1, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - assertNotEquals(handle4, handle3); - - target.path(handle4.toString()).queryParam("sessionid", lensSessionId).request(mt).delete(APIResult.class); - // Launch the query in different session should result in the different - // handle. - - final FormDataMultiPart mp2 = new FormDataMultiPart(); - mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt)); - mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from " - + TEST_TABLE)); - mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); - mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), - new LensConf(), mt)); - final QueryHandle handle5 = target.request(mt) - .post(Entity.entity(mp2, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - - sessionconf = new HashMap<>(); - sessionconf.put("test.session.key", "svalue"); - - LensSessionHandle lensSessionId1 = queryService.openSession("foo@localhost", "bar", sessionconf); - final FormDataMultiPart mp3 = new FormDataMultiPart(); - mp3.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId1, mt)); - mp3.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from " - + TEST_TABLE)); - mp3.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); - mp3.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), - new LensConf(), mt)); - final QueryHandle handle6 = target.request(mt) - .post(Entity.entity(mp3, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - - assertNotNull(handle5); - assertNotNull(handle6); - assertNotEquals(handle5, handle6); - target.path(handle5.toString()).queryParam("sessionid", lensSessionId).request(mt).delete(APIResult.class); - target.path(handle6.toString()).queryParam("sessionid", lensSessionId1).request(mt).delete(APIResult.class); - - // Diffrent conf should different handle - LensConf conf = new LensConf(); - final FormDataMultiPart mp4 = new FormDataMultiPart(); - mp4.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt)); - mp4.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from " - + TEST_TABLE)); - mp4.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); - mp4.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, mt)); - final QueryHandle handle7 = target.request(mt) - .post(Entity.entity(mp4, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - - // Add a property - conf.addProperty("test", "test"); - final FormDataMultiPart mp5 = new FormDataMultiPart(); - mp5.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId, mt)); - mp5.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select ID, IDSTR from " - + TEST_TABLE)); - mp5.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "execute")); - mp5.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), conf, mt)); - final QueryHandle handle8 = target.request(mt) - .post(Entity.entity(mp5, MediaType.MULTIPART_FORM_DATA_TYPE), new GenericType<LensAPIResult<QueryHandle>>() { - }).getData(); - assertNotNull(handle7); - assertNotNull(handle8); - assertNotEquals(handle7, handle8); - target.path(handle7.toString()).queryParam("sessionid", lensSessionId).request(mt).delete(APIResult.class); - target.path(handle8.toString()).queryParam("sessionid", lensSessionId1).request(mt).delete(APIResult.class); - } finally { - queryService.pauseQuerySubmitter(false); - // cleanup - dropTable(TEST_TABLE); - queryService.closeSession(lensSessionId); - for (LensDriver driver : queryService.getDrivers()) { - if (driver instanceof HiveDriver) { - assertFalse(((HiveDriver) driver).hasLensSession(lensSessionId)); - } - } - } - } -}
