You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ha...@apache.org on 2016/11/09 07:53:15 UTC

incubator-eagle git commit: [EAGLE-747] Add unit test for eagle-storage-base module

Repository: incubator-eagle
Updated Branches:
  refs/heads/master 137b9e038 -> 53a74633e


[EAGLE-747] Add unit test for eagle-storage-base module

EAGLE-747 Add unit test for eagle-storage-base module
- Add unit test.

https://issues.apache.org/jira/browse/EAGLE-747

Author: chitin <ch...@gmail.com>

Closes #620 from chitin/EAGLE-747.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/53a74633
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/53a74633
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/53a74633

Branch: refs/heads/master
Commit: 53a74633e90c9638554a96b7d21ef1a0bbbd4755
Parents: 137b9e0
Author: chitin <ch...@gmail.com>
Authored: Wed Nov 9 15:53:06 2016 +0800
Committer: Hao Chen <ha...@apache.org>
Committed: Wed Nov 9 15:53:06 2016 +0800

----------------------------------------------------------------------
 .../storage/operation/TestCompiledQuery.java    | 81 ++++++++++++++++++++
 .../storage/operation/TestCreateStatement.java  | 53 +++++++++++++
 .../storage/operation/TestDeleteStatement.java  | 68 ++++++++++++++++
 .../storage/operation/TestQueryStatement.java   | 41 ++++++++++
 .../operation/TestRowkeyQueryStatement.java     | 52 +++++++++++++
 .../storage/operation/TestUpdateStatement.java  | 47 ++++++++++++
 6 files changed, 342 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/53a74633/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCompiledQuery.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCompiledQuery.java b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCompiledQuery.java
new file mode 100644
index 0000000..a59a5d8
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCompiledQuery.java
@@ -0,0 +1,81 @@
+/*
+ * 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.eagle.storage.operation;
+
+import org.apache.eagle.common.DateTimeUtil;
+import org.apache.eagle.common.config.EagleConfigFactory;
+import org.apache.eagle.log.entity.meta.EntityDefinition;
+import org.apache.eagle.log.entity.meta.EntityDefinitionManager;
+import org.apache.eagle.log.entity.test.TestTimeSeriesAPIEntity;
+import org.apache.eagle.storage.exception.QueryCompileException;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.GregorianCalendar;
+
+/**
+ * @Since 11/7/16.
+ */
+public class TestCompiledQuery {
+
+    static EntityDefinition entityDefinition = null;
+
+    final String queryStr = "TestTimeSeriesAPIEntity[@cluster=\"c4ut\"]{*}";
+    final int pageSize = 1000;
+    final long baseTimestamp = createTimeStamp(2017, 0, 11, 0, 0, 0);
+    final String startTime = DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp);
+    final String endTime = DateTimeUtil.millisecondsToHumanDateWithMilliseconds(baseTimestamp + 2000);
+
+    @BeforeClass
+    public static void setUpOnce() throws Exception {
+        entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class);
+        entityDefinition.setTags(new String[] {"cluster", "datacenter", "random"});
+    }
+
+    static long createTimeStamp(int year, int month, int date, int hourOfDay, int minute, int second) {
+        GregorianCalendar gc = new GregorianCalendar();
+        gc.clear();
+        gc.set(year, month, date, hourOfDay, minute, second);
+        gc.setTimeZone(EagleConfigFactory.load().getTimeZone());
+        return gc.getTime().getTime();
+    }
+
+    @Test
+    public void testCreatedCompiledQuery() throws QueryCompileException, IOException {
+
+
+        RawQuery rawQuery = new RawQuery();
+        rawQuery.setQuery(queryStr);
+        rawQuery.setStartTime(startTime);
+        rawQuery.setEndTime(endTime);
+        rawQuery.setPageSize(pageSize);
+
+        CompiledQuery query = new CompiledQuery(rawQuery);
+
+        Assert.assertEquals(baseTimestamp, query.getStartTime());
+        Assert.assertEquals(baseTimestamp + 2000, query.getEndTime());
+        Assert.assertEquals(rawQuery.isTreeAgg(), query.isHasAgg());
+        Assert.assertEquals(rawQuery.isTimeSeries(), query.isTimeSeries());
+
+        RawQuery raw2 = RawQuery.build().query(queryStr).startTime(startTime)
+            .endTime(endTime).pageSize(pageSize).done();
+
+        Assert.assertEquals(rawQuery.toString(), raw2.toString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/53a74633/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCreateStatement.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCreateStatement.java b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCreateStatement.java
new file mode 100644
index 0000000..60a0839
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCreateStatement.java
@@ -0,0 +1,53 @@
+/*
+ * 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.eagle.storage.operation;
+
+import org.apache.eagle.log.entity.meta.EntityDefinitionManager;
+import org.apache.eagle.log.entity.test.TestTimeSeriesAPIEntity;
+import org.apache.eagle.storage.DataStorage;
+import org.junit.Test;
+import org.mockito.Mock;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * @Since 11/7/16.
+ */
+public class TestCreateStatement {
+
+    private DataStorage mockDataStorage = mock(DataStorage.class);
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testEntityNull() throws IOException {
+        CreateStatement createStatement = new CreateStatement(null, TestTimeSeriesAPIEntity.class.getSimpleName());
+        createStatement.execute(mockDataStorage);
+    }
+
+    @Test
+    public void testCreateExecute() throws Exception {
+        List<TestTimeSeriesAPIEntity> entities = new ArrayList<>();
+        CreateStatement createStatement1 = new CreateStatement(entities, TestTimeSeriesAPIEntity.class.getSimpleName());
+        CreateStatement createStatement2 = new CreateStatement(entities, EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class));
+        createStatement1.execute(mockDataStorage);
+        createStatement2.execute(mockDataStorage);
+        verify(mockDataStorage, times(2)).create(any(), any());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/53a74633/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestDeleteStatement.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestDeleteStatement.java b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestDeleteStatement.java
new file mode 100644
index 0000000..af96a22
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestDeleteStatement.java
@@ -0,0 +1,68 @@
+/*
+ * 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.eagle.storage.operation;
+
+import org.apache.eagle.log.entity.meta.EntityDefinition;
+import org.apache.eagle.log.entity.test.TestTimeSeriesAPIEntity;
+import org.apache.eagle.storage.DataStorage;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * @Since 11/7/16.
+ */
+public class TestDeleteStatement {
+
+    private DataStorage mockDataStorage = mock(DataStorage.class);
+
+    @Test
+    public void testResultNotNullIds() throws IOException {
+        DeleteStatement deleteStatement = new DeleteStatement("TestTimeSeriesAPIEntity");
+        deleteStatement.setIds(new ArrayList<>());
+        deleteStatement.execute(mockDataStorage);
+        verify(mockDataStorage).deleteByID(anyList(), any(EntityDefinition.class));
+    }
+
+    @Test
+    public void testResultNotNullQuery() throws Exception {
+        RawQuery query = mock(RawQuery.class);
+        CompiledQuery compiledQuery = mock(CompiledQuery.class);
+        DeleteStatement deleteStatement = new DeleteStatement(query);
+        when(mockDataStorage.compile(query)).thenReturn(compiledQuery);
+        when(compiledQuery.getServiceName()).thenReturn("TestTimeSeriesAPIEntity");
+        deleteStatement.execute(mockDataStorage);
+        verify(mockDataStorage).delete(any(CompiledQuery.class), any(EntityDefinition.class));
+    }
+
+    @Test
+    public void testResultNotNullEntities() throws IOException {
+        DeleteStatement deleteStatement = new DeleteStatement(TestTimeSeriesAPIEntity.class.getSimpleName());
+        deleteStatement.setEntities(new ArrayList<>());
+        deleteStatement.execute(mockDataStorage);
+        verify(mockDataStorage).delete(anyList(), any(EntityDefinition.class));
+    }
+
+    @Test(expected = IOException.class)
+    public void testResultAllNull() throws IOException {
+        DeleteStatement deleteStatement = new DeleteStatement(TestTimeSeriesAPIEntity.class);
+        deleteStatement.execute(mockDataStorage);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/53a74633/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestQueryStatement.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestQueryStatement.java b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestQueryStatement.java
new file mode 100644
index 0000000..aeb4a6c
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestQueryStatement.java
@@ -0,0 +1,41 @@
+/*
+ * 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.eagle.storage.operation;
+
+import org.apache.eagle.storage.DataStorage;
+import org.junit.Test;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * @Since 11/7/16.
+ */
+public class TestQueryStatement {
+
+    private DataStorage mockDataStorage = mock(DataStorage.class);
+
+    @Test
+    public void testQueryExecute() throws Exception {
+        RawQuery query = mock(RawQuery.class);
+        CompiledQuery compiledQuery = mock(CompiledQuery.class);
+        QueryStatement queryStatement = new QueryStatement(query);
+        when(mockDataStorage.compile(query)).thenReturn(compiledQuery);
+        when(compiledQuery.getServiceName()).thenReturn("TestTimeSeriesAPIEntity");
+        queryStatement.execute(mockDataStorage);
+        verify(mockDataStorage).query(any(), any());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/53a74633/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestRowkeyQueryStatement.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestRowkeyQueryStatement.java b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestRowkeyQueryStatement.java
new file mode 100644
index 0000000..28a3f60
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestRowkeyQueryStatement.java
@@ -0,0 +1,52 @@
+/*
+ * 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.eagle.storage.operation;
+
+import org.apache.eagle.log.entity.meta.EntityDefinition;
+import org.apache.eagle.log.entity.meta.EntityDefinitionManager;
+import org.apache.eagle.log.entity.test.TestTimeSeriesAPIEntity;
+import org.apache.eagle.storage.DataStorage;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * @Since 11/7/16.
+ */
+public class TestRowkeyQueryStatement {
+    private DataStorage mockDataStorage = mock(DataStorage.class);
+
+    @Test
+    public void testRowkeyExecute() throws Exception {
+        String rowkey = "rowkey";
+        List<String> rowkeys = new ArrayList<>();
+        rowkeys.add(rowkey);
+        EntityDefinition entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class);
+        RowkeyQueryStatement rowkeyQueryStatement1 = new RowkeyQueryStatement(rowkey, entityDefinition);
+        RowkeyQueryStatement rowkeyQueryStatement2 = new RowkeyQueryStatement(rowkey, TestTimeSeriesAPIEntity.class.getSimpleName());
+        RowkeyQueryStatement rowkeyQueryStatement3 = new RowkeyQueryStatement(rowkeys, entityDefinition);
+        RowkeyQueryStatement rowkeyQueryStatement4 = new RowkeyQueryStatement(rowkeys, TestTimeSeriesAPIEntity.class.getSimpleName());
+        rowkeyQueryStatement1.execute(mockDataStorage);
+        rowkeyQueryStatement2.execute(mockDataStorage);
+        rowkeyQueryStatement3.execute(mockDataStorage);
+        rowkeyQueryStatement4.execute(mockDataStorage);
+        verify(mockDataStorage, times(4)).queryById(any(), any());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/53a74633/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestUpdateStatement.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestUpdateStatement.java b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestUpdateStatement.java
new file mode 100644
index 0000000..f08e020
--- /dev/null
+++ b/eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestUpdateStatement.java
@@ -0,0 +1,47 @@
+/*
+ * 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.eagle.storage.operation;
+
+import org.apache.eagle.log.entity.meta.EntityDefinitionManager;
+import org.apache.eagle.log.entity.test.TestTimeSeriesAPIEntity;
+import org.apache.eagle.storage.DataStorage;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * @Since 11/7/16.
+ */
+public class TestUpdateStatement {
+
+    private DataStorage mockDataStorage = mock(DataStorage.class);
+
+    @Test
+    public void testUpdateExecute() throws Exception {
+        List<TestTimeSeriesAPIEntity> entities = new ArrayList<>();
+        UpdateStatement updateStatement1 = new UpdateStatement(entities, TestTimeSeriesAPIEntity.class.getSimpleName());
+        UpdateStatement updateStatement2 = new UpdateStatement(entities, EntityDefinitionManager.getEntityDefinitionByEntityClass(TestTimeSeriesAPIEntity.class));
+        updateStatement1.execute(mockDataStorage);
+        updateStatement2.execute(mockDataStorage);
+        verify(mockDataStorage, times(2)).update(any(), any());
+    }
+
+}