Java tutorial
/** * 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 com.huawei.streaming.cql; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import org.apache.commons.io.FileUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.huawei.streaming.cql.executor.PhysicalPlanLoader; import com.huawei.streaming.cql.mapping.CQLSimpleLexerMapping; import com.huawei.streaming.cql.mapping.InputOutputOperatorMapping; import com.huawei.streaming.cql.toolkits.operators.TCPServerInputOperator; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Driver * */ public class DriverTest { private static final String TMP_TEST_DEPENDS = "/tmp/testDepends/"; private static final Logger LOG = LoggerFactory.getLogger(DriverTest.class); /** * */ private static final String BASICPATH = File.separator + "driver" + File.separator; /** * SQL */ private static String inPutDir = null; /** * ???? */ private static String outPutDir = null; /** * ????? */ private static String resultPutDir = null; /** * ???? * * @throws Exception ?? */ @BeforeClass public static void setUpBeforeClass() throws Exception { CQLSimpleLexerMapping.registerOperator("TCPServerInput", TCPServerInputOperator.class); PhysicalPlanLoader.registerPhysicalPlanAlias("TCPServerInput", com.huawei.streaming.cql.toolkits.api.TCPServerInputOperator.class); InputOutputOperatorMapping.registerOperator( com.huawei.streaming.cql.toolkits.api.TCPServerInputOperator.class, com.huawei.streaming.cql.toolkits.operators.TCPServerInputOperator.class); setDir(); /* * */ CQLTestCommons.emptyDir(new File(resultPutDir)); } private static void removeTmpDir(File tmpDir) { try { FileUtils.deleteDirectory(tmpDir); } catch (IOException e) { LOG.error("failed to delete tmp dir", e); } } private static void setDir() throws UnsupportedEncodingException { String classPath = DriverTest.class.getResource("/").getPath(); classPath = URLDecoder.decode(classPath, "UTF-8"); inPutDir = classPath + BASICPATH + CQLTestCommons.INPUT_DIR_NAME + File.separator; outPutDir = classPath + BASICPATH + CQLTestCommons.OUTPUT_DIR_NAME + File.separator; resultPutDir = classPath + BASICPATH + CQLTestCommons.RESULT_DIR_NAME + File.separator; } /** * ? * * @throws Exception */ @AfterClass public static void tearDownAfterClass() throws Exception { CQLSimpleLexerMapping.unRegisterSimpleLexerMapping("TCPServerInput"); PhysicalPlanLoader.unRegisterPhysicalPlanAlias("TCPServerInput"); InputOutputOperatorMapping .unRegisterMapping(com.huawei.streaming.cql.toolkits.api.TCPServerInputOperator.class); File tmpDir = new File(TMP_TEST_DEPENDS); LOG.info("delete tmp user dir {} in test case tear down", tmpDir.getAbsolutePath()); removeTmpDir(tmpDir); } /** * * * @throws Exception */ @Test public void testAggregate() throws Exception { executeCase("aggregate"); } /** * * * @throws Exception */ @Test public void testAggregate2() throws Exception { executeCase("aggregate2"); } /** * * * @throws Exception */ @Test public void testAggregate3() throws Exception { // executeCase("aggregate3"); } /** * * * @throws Exception */ @Test public void testJoin9() throws Exception { executeCase("join_aggregate"); } /** * * * @throws Exception */ @Test public void testGroupby1() throws Exception { executeCase("groupby1"); } /** * * * @throws Exception */ @Test public void testGroupby2() throws Exception { executeCase("groupby2"); } /** * * * @throws Exception */ @Test public void testFilterBeforeWindow() throws Exception { executeCase("filterbeforewindow"); } /** * * * @throws Exception */ @Test public void testFilterBeforeWindow2() throws Exception { executeCase("filterbeforewindow2"); } /** * * * @throws Exception */ @Test public void testWhereLengthSlide() throws Exception { executeCase("where_length_slide"); } /** * * * @throws Exception */ @Test public void testAggregateFilter() throws Exception { executeCase("aggregateFilter"); } /** * * * @throws Exception */ @Test public void testAggregateFilter2() throws Exception { executeCase("aggregateFilter2"); } /** * * * @throws Exception */ @Test public void testChineline() throws Exception { executeCase("chineline"); } /** * * * @throws Exception */ @Test public void testConfs() throws Exception { executeCase("confs"); } /** * * * @throws Exception */ @Test public void testLocalSubmit() throws Exception { executeCase("localSubmit"); } /** * * * @throws Exception */ @Test public void testFunctionCount() throws Exception { executeCase("functionCount"); } /** * * * @throws Exception */ @Test public void testSortby() throws Exception { executeCase("sortby"); } /** * * * @throws Exception */ @Test public void testLimit() throws Exception { executeCase("limit"); } /** * * * @throws Exception */ @Test public void testSubQuery1() throws Exception { executeCase("subQuery1"); } /** * * * @throws Exception */ @Test public void testSubQuery2() throws Exception { executeCase("subQuery2"); } /** * * * @throws Exception */ @Test public void testSubQuery3() throws Exception { executeCase("subQuery3"); } /** * * * @throws Exception */ @Test public void testSubQuery4() throws Exception { executeCase("subQuery4"); } /** * * * @throws Exception */ @Test public void testSubQuery5() throws Exception { executeCase("subQuery5"); } /** * * * @throws Exception */ @Test public void testSubQuery6() throws Exception { executeCase("subQuery6"); } /** * * * @throws Exception */ @Test public void testSubQuery7() throws Exception { executeCase("subQuery7"); } /** * * * @throws Exception */ @Test public void testSameStream() throws Exception { executeCase("sameStream"); } /** * * * @throws Exception */ @Test public void testAutoCreateStream1() throws Exception { executeCase("autoCreateStream1"); } /** * * * @throws Exception */ @Test public void testAutoCreateStream2() throws Exception { executeCase("autoCreateStream2"); } /** * * * @throws Exception */ @Test public void testCast() throws Exception { executeCase("cast"); } /** * * * @throws Exception */ @Test public void testCast2() throws Exception { executeCase("cast2"); } /** * * * @throws Exception */ @Test public void testParallel1() throws Exception { executeCase("parallel1"); } /** * * * @throws Exception */ @Test public void testParallel2() throws Exception { executeCase("parallel2"); } /** * * * @throws Exception */ @Test public void testParallel3() throws Exception { executeCase("parallel3"); } /** * * * @throws Exception */ @Test public void testParallel4() throws Exception { executeCase("parallel4"); } /** * * * @throws Exception */ @Test public void testParallel5() throws Exception { executeCase("parallel5"); } /** * * * @throws Exception */ @Test public void testDate() throws Exception { executeCase("date"); } /** * * * @throws Exception */ @Test public void testUserDefinedOperator1() throws Exception { executeCase("userdefinedOperator1"); } /** * * * @throws Exception */ @Test public void testUserDefinedOperator2() throws Exception { executeCase("userdefinedOperator2"); } /** * * * @throws Exception */ @Test public void testUserDefinedOperator3() throws Exception { executeCase("userdefinedOperator3"); } /** * * * @throws Exception */ @Test public void testSimpleLexer() throws Exception { executeCase("simpleLexer"); } /** * * * @throws Exception */ @Test public void testSimpleLexer3() throws Exception { executeCase("simpleLexer3"); } /** * * * @throws Exception */ @Test public void testSimpleLexer2() throws Exception { executeCase("simpleLexer2"); } /** * * * @throws Exception */ @Test public void testSimpleAggregate() throws Exception { executeCase("simpleAggregate"); } /** * * * @throws Exception */ @Test public void testKafkaInput() throws Exception { executeCase("kafkaInput"); } /** * * * @throws Exception */ @Test public void testKafkaOutput() throws Exception { executeCase("kafkaOutput"); } /** * * * @throws Exception */ @Test public void testPipeLineHaving() throws Exception { executeCase("pipelinehaving"); } /** * * * @throws Exception */ @Test public void testUDFDay() throws Exception { executeCase("udfday"); } /** * * * @throws Exception */ @Test public void testDecimalAgg() throws Exception { executeCase("decimalagg"); } /** * * * @throws Exception */ @Test public void testMultiArithmetic1() throws Exception { executeCase("multiArithmetic1"); } /** * * * @throws Exception */ @Test public void testMultiArithmetic2() throws Exception { executeCase("multiArithmetic2"); } /** * * * @throws Exception */ @Test public void testMultiArithmetic3() throws Exception { executeCase("multiArithmetic3"); } /** * * * @throws Exception */ @Test public void testMultiArithmetic4() throws Exception { executeCase("multiArithmetic4"); } /** * * * @throws Exception */ @Test public void testMultiArithmetic5() throws Exception { executeCase("multiArithmetic5"); } /** * * * @throws Exception */ @Test public void testMultiArithmetic6() throws Exception { executeCase("multiArithmetic6"); } /** * * * @throws Exception */ @Test public void testMultiArithmetic7() throws Exception { executeCase("multiArithmetic7"); } /** * * * @throws Exception */ @Test public void testMultiArithmetic8() throws Exception { executeCase("multiArithmetic8"); } /** * * * @throws Exception */ @Test public void testUserOperator1() throws Exception { executeCase("userOperator1"); } /** * * * @throws Exception */ @Test public void testUserOperator2() throws Exception { executeCase("userOperator2"); } /** * * * @throws Exception */ @Test public void testUserOperator3() throws Exception { executeCase("userOperator3"); } /** * * * @throws Exception */ @Test public void testUserOperator4() throws Exception { executeCase("userOperator4"); } /** * * * @throws Exception */ @Test public void testUserOperator5() throws Exception { executeCase("userOperator5"); } /** * * * @throws Exception */ @Test public void testUserOperator6() throws Exception { executeCase("userOperator6"); } /** * * * @throws Exception */ @Test public void testUserOperator7() throws Exception { executeCase("userOperator7"); } /** * * * @throws Exception */ @Test public void testUserOperator8() throws Exception { executeCase("userOperator8"); } /** * * * @throws Exception */ @Test public void testUserOperator9() throws Exception { executeCase("userOperator9"); } /** * * * @throws Exception */ @Test public void testSplit3() throws Exception { executeCase("split3"); } /** * * * @throws Exception */ @Test public void testSplit6() throws Exception { executeCase("split6"); } private void executeCase(String caseName) throws Exception { long startTime = System.currentTimeMillis(); DriverTestUtil qt = new DriverTestUtil(inPutDir + caseName + CQLTestCommons.INPUT_POSTFIX, outPutDir + caseName + CQLTestCommons.DRIVER_TEST_POSTFIX, resultPutDir + caseName + CQLTestCommons.DRIVER_TEST_POSTFIX); try { LOG.info("Begin query: " + caseName); qt.executeAndWrite(); if (!qt.compareResults()) { LOG.error("test result doesn't same!"); fail("test result doesn't same!"); } } catch (Throwable e) { LOG.error("Exception: " + e.getMessage(), e); LOG.error("Failed query: " + caseName); fail("Exception: " + e.getMessage()); } long elapsedTime = System.currentTimeMillis() - startTime; LOG.info("Done query: " + caseName + " elapsedTime=" + elapsedTime / CQLTestCommons.BASICTIMESTAMP + "s"); assertTrue("Test passed", true); } }