KYLIN-3157, refine test.
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/b22ee0d2 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/b22ee0d2 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/b22ee0d2 Branch: refs/heads/sync Commit: b22ee0d2d1ba3f11506d771d45efd653c499ab0b Parents: d43abbd Author: tttMelody <245915...@qq.com> Authored: Tue Jan 9 16:49:11 2018 +0800 Committer: Li Yang <liy...@apache.org> Committed: Fri Jan 26 18:49:18 2018 +0800 ---------------------------------------------------------------------- .../rest/service/KyilnQueryTimeoutTest.java | 104 ------------------ .../rest/service/KylinQueryTimeoutTest.java | 107 +++++++++++++++++++ 2 files changed, 107 insertions(+), 104 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/b22ee0d2/server/src/test/java/org/apache/kylin/rest/service/KyilnQueryTimeoutTest.java ---------------------------------------------------------------------- diff --git a/server/src/test/java/org/apache/kylin/rest/service/KyilnQueryTimeoutTest.java b/server/src/test/java/org/apache/kylin/rest/service/KyilnQueryTimeoutTest.java deleted file mode 100644 index 25ff75b..0000000 --- a/server/src/test/java/org/apache/kylin/rest/service/KyilnQueryTimeoutTest.java +++ /dev/null @@ -1,104 +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.kylin.rest.service; -import java.sql.SQLException; - -import org.apache.kylin.common.KylinConfig; -import org.apache.kylin.common.exceptions.KylinTimeoutException; -import org.apache.kylin.common.util.LocalFileMetadataTestCase; -import org.apache.kylin.metadata.realization.IRealization; -import org.apache.kylin.metadata.realization.SQLDigest; -import org.apache.kylin.metadata.tuple.ITupleIterator; -import org.apache.kylin.metadata.tuple.TupleInfo; -import org.apache.kylin.query.security.QueryACLTestUtil; -import org.apache.kylin.rest.request.SQLRequest; -import org.apache.kylin.storage.IStorage; -import org.apache.kylin.storage.IStorageQuery; -import org.apache.kylin.storage.StorageContext; -import org.apache.kylin.storage.StorageFactory; -import org.hamcrest.CoreMatchers; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class KyilnQueryTimeoutTest extends LocalFileMetadataTestCase { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() { - this.createTestMetadata(); - KylinConfig config = KylinConfig.getInstanceFromEnv(); - config.setProperty("kylin.storage.provider.2", MockQueryTimeoutStorage.class.getName()); - config.setProperty("kylin.storage.default", "2"); - } - - @After - public void after() throws Exception { - this.cleanupTestMetadata(); - StorageFactory.clearCache(); - } - - @Test - public void testQueryTimeout() throws SQLException { - thrown.expectCause(CoreMatchers.isA(KylinTimeoutException.class)); - thrown.expectMessage(CoreMatchers.containsString("Kylin query timeout")); - StorageFactory.clearCache(); - BadQueryDetector detector = new BadQueryDetector(100, BadQueryDetector.getSystemAvailMB() * 2, 100, 1); - detector.start(); - SQLRequest request = new SQLRequest(); - request.setProject("default"); - request.setSql("select count(*) from STREAMING_TABLE"); - detector.queryStart(Thread.currentThread(), request, "ADMIN"); - try { - QueryACLTestUtil.mockQuery("default", "select * from STREAMING_TABLE"); - } finally{ - detector.queryEnd(Thread.currentThread(), "timeout"); - detector.interrupt(); - } - } - - public static class MockQueryTimeoutStorage implements IStorage { - - @Override - public IStorageQuery createQuery(IRealization realization) { - return new MockQueryTimeoutQuery(); - } - - @Override - public <I> I adaptToBuildEngine(Class<I> engineInterface) { - return null; - } - } - - private static class MockQueryTimeoutQuery implements IStorageQuery { - @Override - public ITupleIterator search(StorageContext context, SQLDigest sqlDigest, TupleInfo returnTupleInfo) { - try { - Thread.sleep(5 * 1000); - } catch (InterruptedException e) { - throw new KylinTimeoutException("Kylin query timeout"); - } - return null; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/b22ee0d2/server/src/test/java/org/apache/kylin/rest/service/KylinQueryTimeoutTest.java ---------------------------------------------------------------------- diff --git a/server/src/test/java/org/apache/kylin/rest/service/KylinQueryTimeoutTest.java b/server/src/test/java/org/apache/kylin/rest/service/KylinQueryTimeoutTest.java new file mode 100644 index 0000000..6a61b2f --- /dev/null +++ b/server/src/test/java/org/apache/kylin/rest/service/KylinQueryTimeoutTest.java @@ -0,0 +1,107 @@ +/* + * 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.kylin.rest.service; +import java.sql.SQLException; + +import org.apache.kylin.common.KylinConfig; +import org.apache.kylin.common.exceptions.KylinTimeoutException; +import org.apache.kylin.common.util.LocalFileMetadataTestCase; +import org.apache.kylin.metadata.realization.IRealization; +import org.apache.kylin.metadata.realization.SQLDigest; +import org.apache.kylin.metadata.tuple.ITupleIterator; +import org.apache.kylin.metadata.tuple.TupleInfo; +import org.apache.kylin.query.security.QueryACLTestUtil; +import org.apache.kylin.rest.request.SQLRequest; +import org.apache.kylin.storage.IStorage; +import org.apache.kylin.storage.IStorageQuery; +import org.apache.kylin.storage.StorageContext; +import org.apache.kylin.storage.StorageFactory; +import org.hamcrest.CoreMatchers; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class KylinQueryTimeoutTest extends LocalFileMetadataTestCase { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void setUp() { + this.createTestMetadata(); + KylinConfig config = KylinConfig.getInstanceFromEnv(); + config.setProperty("kylin.storage.provider.2", MockQueryTimeoutStorage.class.getName()); + config.setProperty("kylin.storage.default", "2"); + } + + @After + public void after() throws Exception { + this.cleanupTestMetadata(); + StorageFactory.clearCache(); + } + + @Test + public void testQueryTimeout() throws SQLException { + thrown.expectCause(CoreMatchers.isA(KylinTimeoutException.class)); + thrown.expectMessage(CoreMatchers.containsString("Kylin query timeout")); + StorageFactory.clearCache(); + BadQueryDetector detector = new BadQueryDetector(100, BadQueryDetector.getSystemAvailMB() * 2, 100, 1); + detector.start(); + SQLRequest request = new SQLRequest(); + request.setProject("default"); + request.setSql("select count(*) from STREAMING_TABLE"); + detector.queryStart(Thread.currentThread(), request, "ADMIN"); + try { + QueryACLTestUtil.mockQuery("default", "select * from STREAMING_TABLE"); + } finally{ + detector.queryEnd(Thread.currentThread(), "timeout"); + detector.interrupt(); + } + // every place that thrown KylinTimeoutException should reset the interrupt. + Assert.assertEquals(false, Thread.currentThread().isInterrupted()); + } + + public static class MockQueryTimeoutStorage implements IStorage { + + @Override + public IStorageQuery createQuery(IRealization realization) { + return new MockQueryTimeoutQuery(); + } + + @Override + public <I> I adaptToBuildEngine(Class<I> engineInterface) { + return null; + } + } + + private static class MockQueryTimeoutQuery implements IStorageQuery { + @Override + public ITupleIterator search(StorageContext context, SQLDigest sqlDigest, TupleInfo returnTupleInfo) { + try { + Thread.sleep(5 * 1000); + } catch (InterruptedException e) { + throw new KylinTimeoutException("Kylin query timeout"); + } + return null; + } + } +} \ No newline at end of file