This is an automated email from the ASF dual-hosted git repository.

nic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git


The following commit(s) were added to refs/heads/master by this push:
     new c39b238  Add additional unit tests (#631)
c39b238 is described below

commit c39b238fb2f4999f5484a7d2fa0b55245db5534c
Author: Michael Hausegger <[email protected]>
AuthorDate: Sun May 12 10:48:06 2019 +0200

    Add additional unit tests (#631)
    
    * Added Unit Tests to increase code coverage.
---
 .../org/apache/kylin/common/util/BitSetsTest.java  |  27 +++--
 .../org/apache/kylin/common/util/SortUtilTest.java |  61 +++++++++++
 .../{BitSetsTest.java => StringSplitterTest.java}  |  36 +++++--
 .../apache/kylin/common/util/SumHelperTest.java    |  82 +++++++++++++++
 .../mr/common/HadoopJobStatusCheckerTest.java      |  66 ++++++++++++
 .../org/apache/kylin/jdbc/KylinClientTest.java     |  33 ++++--
 .../core/util/TimeDerivedColumnTypeTest.java       | 112 ++++++++++++++++++---
 .../kylin/stream/source/kafka/KafkaSourceTest.java |  58 +++++++++++
 .../source/kafka/KafkaTopicAssignmentTest.java     | 108 ++++++++++++++++++++
 9 files changed, 544 insertions(+), 39 deletions(-)

diff --git 
a/core-common/src/test/java/org/apache/kylin/common/util/BitSetsTest.java 
b/core-common/src/test/java/org/apache/kylin/common/util/BitSetsTest.java
index c923969..fd03c11 100644
--- a/core-common/src/test/java/org/apache/kylin/common/util/BitSetsTest.java
+++ b/core-common/src/test/java/org/apache/kylin/common/util/BitSetsTest.java
@@ -18,19 +18,34 @@
 
 package org.apache.kylin.common.util;
 
+import org.junit.Test;
+
 import java.util.BitSet;
 
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class BitSetsTest {
 
     @Test
     public void basicTest() {
         BitSet a = BitSets.valueOf(new int[] { 1, 3, 10 });
-        Assert.assertEquals(3, a.cardinality());
-        Assert.assertTrue(10 < a.size());
-        Assert.assertTrue(a.get(3));
+        assertEquals(3, a.cardinality());
+        assertTrue(10 < a.size());
+        assertTrue(a.get(3));
     }
 
-}
\ No newline at end of file
+  @Test
+  public void testValueOfWithNull() {
+      BitSet bitSet = BitSets.valueOf((int[]) null);
+
+      assertEquals("{}", bitSet.toString());
+      assertEquals(0, bitSet.cardinality());
+
+      assertEquals(0, bitSet.length());
+      assertTrue(bitSet.isEmpty());
+
+      assertEquals(64, bitSet.size());
+  }
+
+}
diff --git 
a/core-common/src/test/java/org/apache/kylin/common/util/SortUtilTest.java 
b/core-common/src/test/java/org/apache/kylin/common/util/SortUtilTest.java
new file mode 100644
index 0000000..a849040
--- /dev/null
+++ b/core-common/src/test/java/org/apache/kylin/common/util/SortUtilTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.common.util;
+
+import org.junit.Test;
+
+import java.time.Month;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.Stack;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * Unit tests for class {@link SortUtil}.
+ *
+ * @see SortUtil
+ *
+ */
+public class SortUtilTest{
+
+  @Test
+  public void testExtractAndSort() {
+      Stack<Month> stack = new Stack<>();
+      ListIterator<Month> listIterator = stack.listIterator();
+      Iterator<Month> iterator = SortUtil.extractAndSort(listIterator, null);
+
+      assertTrue(stack.empty());
+      assertEquals("[]", stack.toString());
+
+      assertEquals(10, stack.capacity());
+      assertEquals(0, stack.size());
+
+      assertTrue(stack.isEmpty());
+      assertFalse(listIterator.hasNext());
+
+      assertFalse(listIterator.hasPrevious());
+      assertNotNull(iterator);
+  }
+
+}
\ No newline at end of file
diff --git 
a/core-common/src/test/java/org/apache/kylin/common/util/BitSetsTest.java 
b/core-common/src/test/java/org/apache/kylin/common/util/StringSplitterTest.java
similarity index 56%
copy from 
core-common/src/test/java/org/apache/kylin/common/util/BitSetsTest.java
copy to 
core-common/src/test/java/org/apache/kylin/common/util/StringSplitterTest.java
index c923969..43347c6 100644
--- a/core-common/src/test/java/org/apache/kylin/common/util/BitSetsTest.java
+++ 
b/core-common/src/test/java/org/apache/kylin/common/util/StringSplitterTest.java
@@ -18,19 +18,33 @@
 
 package org.apache.kylin.common.util;
 
-import java.util.BitSet;
-
-import org.junit.Assert;
 import org.junit.Test;
 
-public class BitSetsTest {
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for class {@link StringSplitter}.
+ *
+ * @see StringSplitter
+ *
+ */
+public class StringSplitterTest{
+
+  @Test
+  public void testSplitReturningNonEmptyArray() {
+      String[] stringArray = StringSplitter.split("Fc8!v~f?aQL", 
"Fc8!v~f?aQL");
+
+      assertEquals(2, stringArray.length);
+      assertEquals("", stringArray[0]);
+      assertEquals("", stringArray[1]);
+  }
+
+  @Test
+  public void testSplitWithNonEmptyString() {
+      String[] stringArray = StringSplitter.split("]sZ}gR\"cws,8p#|m", 
"Fc8!v~f?aQL");
 
-    @Test
-    public void basicTest() {
-        BitSet a = BitSets.valueOf(new int[] { 1, 3, 10 });
-        Assert.assertEquals(3, a.cardinality());
-        Assert.assertTrue(10 < a.size());
-        Assert.assertTrue(a.get(3));
-    }
+      assertEquals(1, stringArray.length);
+      assertEquals("]sZ}gR\"cws,8p#|m", stringArray[0]);
+  }
 
 }
\ No newline at end of file
diff --git 
a/core-common/src/test/java/org/apache/kylin/common/util/SumHelperTest.java 
b/core-common/src/test/java/org/apache/kylin/common/util/SumHelperTest.java
new file mode 100644
index 0000000..5aa431f
--- /dev/null
+++ b/core-common/src/test/java/org/apache/kylin/common/util/SumHelperTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.common.util;
+
+import org.junit.Test;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for class {@link SumHelper}.
+ *
+ * @see SumHelper
+ *
+ */
+public class SumHelperTest{
+
+  @Test
+  public void testSumDouble() {
+      List<Double> linkedList = new LinkedList<>();
+      Double doubleValue = new Double(2832);
+      linkedList.add(doubleValue);
+      Double result = SumHelper.sumDouble(linkedList);
+
+      assertTrue(linkedList.contains(result));
+      assertEquals(result, doubleValue, 0.01);
+
+      assertEquals(2832.0, result, 0.01);
+      assertEquals(1, linkedList.size());
+  }
+
+  @Test
+  public void testSumIntegerReturningLongWhereShortValueIsPositive() {
+      List<Integer> linkedList = new LinkedList<>();
+      Integer integer = Integer.valueOf(4584);
+      linkedList.add(integer);
+      Long result = SumHelper.sumInteger(linkedList);
+
+      assertTrue(linkedList.contains(integer));
+      assertNotNull(result);
+
+      assertEquals(4584L, (long) result);
+      assertEquals(1, linkedList.size());
+  }
+
+  @Test
+  public void testSumLong() {
+      List<Integer> linkedList = new LinkedList<>();
+      Long resultOne = SumHelper.sumInteger(linkedList);
+
+      assertEquals(0L, (long) resultOne);
+      assertEquals(0, linkedList.size());
+      
+      List<Long> linkedListTwo = new LinkedList<>();
+      linkedListTwo.add(resultOne);
+      Long resultTwo = SumHelper.sumLong(linkedListTwo);
+
+      assertEquals(0L, (long) resultTwo);
+      assertEquals(1, linkedListTwo.size());
+  }
+
+}
\ No newline at end of file
diff --git 
a/engine-mr/src/test/java/org/apache/kylin/engine/mr/common/HadoopJobStatusCheckerTest.java
 
b/engine-mr/src/test/java/org/apache/kylin/engine/mr/common/HadoopJobStatusCheckerTest.java
new file mode 100644
index 0000000..1bb8426
--- /dev/null
+++ 
b/engine-mr/src/test/java/org/apache/kylin/engine/mr/common/HadoopJobStatusCheckerTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.engine.mr.common;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.kylin.job.constant.JobStepStatusEnum;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * Unit tests for class {@link HadoopJobStatusChecker}.
+ *
+ * @see HadoopJobStatusChecker
+ */
+public class HadoopJobStatusCheckerTest {
+
+    @Test
+    public void testCheckStatusWithNullJob() {
+        StringBuilder stringBuilder = new StringBuilder();
+        JobStepStatusEnum jobStepStatusEnum = 
HadoopJobStatusChecker.checkStatus(null, stringBuilder);
+
+        assertEquals(JobStepStatusEnum.WAITING, jobStepStatusEnum);
+        assertEquals("Skip status check with empty job id..\n", 
stringBuilder.toString());
+
+        assertFalse(jobStepStatusEnum.isRunable());
+        assertEquals(32, jobStepStatusEnum.getCode());
+
+        assertFalse(jobStepStatusEnum.isComplete());
+    }
+
+    @Test
+    public void testCheckStatusWithEmptyJobId() throws IOException {
+        Job job = Job.getInstance(new Configuration(false));
+        StringBuilder stringBuilder = new StringBuilder();
+        JobStepStatusEnum jobStepStatusEnum = 
HadoopJobStatusChecker.checkStatus(job, stringBuilder);
+
+        assertEquals(JobStepStatusEnum.WAITING, jobStepStatusEnum);
+        assertEquals("Skip status check with empty job id..\n", 
stringBuilder.toString());
+
+        assertFalse(jobStepStatusEnum.isRunable());
+        assertEquals(32, jobStepStatusEnum.getCode());
+
+        assertFalse(jobStepStatusEnum.isComplete());
+    }
+
+}
\ No newline at end of file
diff --git a/jdbc/src/test/java/org/apache/kylin/jdbc/KylinClientTest.java 
b/jdbc/src/test/java/org/apache/kylin/jdbc/KylinClientTest.java
index 2e2e560..ccfb099 100644
--- a/jdbc/src/test/java/org/apache/kylin/jdbc/KylinClientTest.java
+++ b/jdbc/src/test/java/org/apache/kylin/jdbc/KylinClientTest.java
@@ -18,12 +18,7 @@
 
 package org.apache.kylin.jdbc;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Properties;
-
+import com.google.common.collect.Lists;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpUriRequest;
@@ -31,10 +26,16 @@ import org.apache.http.message.BasicStatusLine;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.Lists;
+import java.io.IOException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Properties;
 
 import static org.apache.http.HttpVersion.HTTP_1_1;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.mock;
@@ -111,4 +112,22 @@ public class KylinClientTest {
         ArrayList<Object> list = Lists.newArrayList(iterable);
         assertEquals(1, list.size());
     }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testWrapObjectThrowsIllegalArgumentExceptionUsingDateType() {
+      KylinClient.wrapObject("OQ? PYC6BWm`kOE", Types.DATE);
+  }
+
+
+  @Test
+  public void testWrapObjectUsingNull() {
+      assertNull(KylinClient.wrapObject(null, 1));
+  }
+
+
+  @Test
+  public void testConvertBooleanType() {
+      assertEquals("java.lang.Boolean", 
KylinClient.convertType(Types.BOOLEAN).getName());
+  }
+
 }
diff --git 
a/stream-core/src/test/java/org/apache/kylin/stream/core/util/TimeDerivedColumnTypeTest.java
 
b/stream-core/src/test/java/org/apache/kylin/stream/core/util/TimeDerivedColumnTypeTest.java
index b136d58..414de0f 100644
--- 
a/stream-core/src/test/java/org/apache/kylin/stream/core/util/TimeDerivedColumnTypeTest.java
+++ 
b/stream-core/src/test/java/org/apache/kylin/stream/core/util/TimeDerivedColumnTypeTest.java
@@ -19,9 +19,12 @@
 package org.apache.kylin.stream.core.util;
 
 import org.apache.kylin.common.util.DateFormat;
-import org.junit.Assert;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 public class TimeDerivedColumnTypeTest {
 
     @Test
@@ -35,15 +38,15 @@ public class TimeDerivedColumnTypeTest {
         String minStartTime = "2017-11-01 08:05:00";
         boolean overlap = false;
         overlap = 
TimeDerivedColumnType.MINUTE_START.hasTimeRangeOverlap(segmentStart, 
segmentEnd, minStartTime);
-        Assert.assertTrue(overlap);
+        assertTrue(overlap);
 
         minStartTime = "2017-11-01 08:00:00";
         overlap = 
TimeDerivedColumnType.MINUTE_START.hasTimeRangeOverlap(segmentStart, 
segmentEnd, minStartTime);
-        Assert.assertTrue(overlap);
+        assertTrue(overlap);
 
         minStartTime = "2017-11-01 09:00:00";
         overlap = 
TimeDerivedColumnType.MINUTE_START.hasTimeRangeOverlap(segmentStart, 
segmentEnd, minStartTime);
-        Assert.assertFalse(overlap);
+        assertFalse(overlap);
     }
 
     @Test
@@ -57,23 +60,23 @@ public class TimeDerivedColumnTypeTest {
         String hourStartTime = "2017-11-01 08:00:00";
         boolean overlap = false;
         overlap = 
TimeDerivedColumnType.MINUTE_START.hasTimeRangeOverlap(segmentStart, 
segmentEnd, hourStartTime);
-        Assert.assertTrue(overlap);
+        assertTrue(overlap);
 
         hourStartTime = "2017-11-01 08:05:00";
         overlap = 
TimeDerivedColumnType.MINUTE_START.hasTimeRangeOverlap(segmentStart, 
segmentEnd, hourStartTime);
-        Assert.assertTrue(overlap);
+        assertTrue(overlap);
 
         hourStartTime = "2017-11-01 07:00:00";
         overlap = 
TimeDerivedColumnType.MINUTE_START.hasTimeRangeOverlap(segmentStart, 
segmentEnd, hourStartTime);
-        Assert.assertFalse(overlap);
+        assertFalse(overlap);
 
         hourStartTime = "2017-11-01 09:00:00";
         overlap = 
TimeDerivedColumnType.MINUTE_START.hasTimeRangeOverlap(segmentStart, 
segmentEnd, hourStartTime);
-        Assert.assertFalse(overlap);
+        assertFalse(overlap);
 
         hourStartTime = "2017-11-01 10:00:00";
         overlap = 
TimeDerivedColumnType.MINUTE_START.hasTimeRangeOverlap(segmentStart, 
segmentEnd, hourStartTime);
-        Assert.assertFalse(overlap);
+        assertFalse(overlap);
     }
 
     @Test
@@ -87,15 +90,15 @@ public class TimeDerivedColumnTypeTest {
         String dayStartTime = "2017-11-01";
         boolean overlap = false;
         overlap = 
TimeDerivedColumnType.DAY_START.hasTimeRangeOverlap(segmentStart, segmentEnd, 
dayStartTime);
-        Assert.assertTrue(overlap);
+        assertTrue(overlap);
 
         dayStartTime = "2017-10-29";
         overlap = 
TimeDerivedColumnType.DAY_START.hasTimeRangeOverlap(segmentStart, segmentEnd, 
dayStartTime);
-        Assert.assertFalse(overlap);
+        assertFalse(overlap);
 
         dayStartTime = "2017-11-02";
         overlap = 
TimeDerivedColumnType.DAY_START.hasTimeRangeOverlap(segmentStart, segmentEnd, 
dayStartTime);
-        Assert.assertFalse(overlap);
+        assertFalse(overlap);
 
         segmentStartStr = "2017-11-01 23:00:00";
         segmentEndStr = "2017-11-02 02:00:00";
@@ -105,14 +108,93 @@ public class TimeDerivedColumnTypeTest {
 
         dayStartTime = "2017-11-02";
         overlap = 
TimeDerivedColumnType.DAY_START.hasTimeRangeOverlap(segmentStart, segmentEnd, 
dayStartTime);
-        Assert.assertTrue(overlap);
+        assertTrue(overlap);
 
         dayStartTime = "2017-11-01";
         overlap = 
TimeDerivedColumnType.DAY_START.hasTimeRangeOverlap(segmentStart, segmentEnd, 
dayStartTime);
-        Assert.assertTrue(overlap);
+        assertTrue(overlap);
 
         dayStartTime = "2017-10-30";
         overlap = 
TimeDerivedColumnType.DAY_START.hasTimeRangeOverlap(segmentStart, segmentEnd, 
dayStartTime);
-        Assert.assertFalse(overlap);
+        assertFalse(overlap);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testParseTimeValueThrowsIllegalArgumentException() {
+        TimeDerivedColumnType.parseTimeValue(new Object());
+    }
+
+    @Test
+    public void testIsTimeDerivedColumnReturningTrue() {
+        assertTrue(TimeDerivedColumnType.isTimeDerivedColumn("YEAR_START"));
+    }
+
+    @Test
+    public void testIsTimeDerivedColumnReturningFalse() {
+        assertFalse(TimeDerivedColumnType.isTimeDerivedColumn(""));
+    }
+
+    @Test
+    public void testNormalizeTimeFormatWithPositive() {
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.MINUTE_START;
+
+        assertEquals("1970-01-01 00:00:00", 
timeDerivedColumnType.normalizeTimeFormat(1438L));
+    }
+
+    @Test
+    public void testNormalizeTimeFormatAndNormalizeTimeFormatWithNegativeOne() 
{
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.WEEK_START;
+
+        assertEquals("1969-12-28", 
timeDerivedColumnType.normalizeTimeFormat((-65L)));
+    }
+
+    @Test
+    public void testNormalizeTimeFormatAndNormalizeTimeFormatWithZeroOne() {
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.MONTH_START;
+
+        assertEquals("1970-01-01", 
timeDerivedColumnType.normalizeTimeFormat(0L));
+    }
+
+    @Test
+    public void testHasTimeRangeOverlapAndValueOfReturningNonNull() {
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.valueOf("HOUR_START");
+
+        assertFalse(timeDerivedColumnType.hasTimeRangeOverlap((-2160L), 
(-2074L), new Long((-498L))));
+    }
+
+    @Test
+    public void testNormalizeTimeFormatAndValueOfReturningNonNull() {
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.valueOf("HOUR_START");
+
+        assertEquals("1970-01-01 00:00:00", 
timeDerivedColumnType.normalizeTimeFormat((-419L)));
     }
+
+    @Test
+    public void testNormalizeTimeFormatAndNormalizeTimeFormatWithZeroTwo() {
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.DAY_START;
+
+        assertEquals("1970-01-01", 
timeDerivedColumnType.normalizeTimeFormat(0L));
+    }
+
+    @Test
+    public void testHasTimeRangeOverlapReturningTrue() {
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.QUARTER_START;
+
+        assertTrue(timeDerivedColumnType.hasTimeRangeOverlap((-579L), 641L, 
new Long(0L)));
+    }
+
+    @Test
+    public void testNormalizeTimeFormatAndNormalizeTimeFormatWithNegativeTwo() 
{
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.QUARTER_START;
+
+        assertEquals("1969-10-01", 
timeDerivedColumnType.normalizeTimeFormat((-1L)));
+    }
+
+    @Test
+    public void 
testNormalizeTimeFormatAndNormalizeTimeFormatWithNegativeThree() {
+        TimeDerivedColumnType timeDerivedColumnType = 
TimeDerivedColumnType.YEAR_START;
+
+        assertEquals("1969-01-01", 
timeDerivedColumnType.normalizeTimeFormat((-170L)));
+    }
+
 }
diff --git 
a/stream-source-kafka/src/test/java/org/apache/kylin/stream/source/kafka/KafkaSourceTest.java
 
b/stream-source-kafka/src/test/java/org/apache/kylin/stream/source/kafka/KafkaSourceTest.java
new file mode 100644
index 0000000..0389473
--- /dev/null
+++ 
b/stream-source-kafka/src/test/java/org/apache/kylin/stream/source/kafka/KafkaSourceTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.stream.source.kafka;
+
+import org.junit.Test;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for class {@link KafkaSource}.
+ *
+ * @see KafkaSource
+ *
+ */
+public class KafkaSourceTest{
+
+  @Test
+  public void testGetStreamingMessageParserClass() throws 
ClassNotFoundException {
+      ConcurrentHashMap<String, String> concurrentHashMap = new 
ConcurrentHashMap<>();
+      Class<?> clasz = 
KafkaSource.getStreamingMessageParserClass(concurrentHashMap);
+
+      assertTrue(concurrentHashMap.isEmpty());
+      assertFalse(clasz.isEnum());
+      assertFalse(clasz.isSynthetic());
+      assertEquals("class 
org.apache.kylin.stream.source.kafka.TimedJsonStreamParser", clasz.toString());
+      assertFalse(clasz.isPrimitive());
+      assertFalse(clasz.isAnnotation());
+      assertFalse(clasz.isInterface());
+      assertFalse(clasz.isArray());
+  }
+
+  @Test(expected = ClassNotFoundException.class)
+  public void testGetStreamingMessageParserClassThrowsClassNotFoundException() 
throws ClassNotFoundException {
+      ConcurrentHashMap<String, String> concurrentHashMap = new 
ConcurrentHashMap<>();
+      concurrentHashMap.put("message.parser", "ev");
+      KafkaSource.getStreamingMessageParserClass(concurrentHashMap);
+  }
+
+}
\ No newline at end of file
diff --git 
a/stream-source-kafka/src/test/java/org/apache/kylin/stream/source/kafka/KafkaTopicAssignmentTest.java
 
b/stream-source-kafka/src/test/java/org/apache/kylin/stream/source/kafka/KafkaTopicAssignmentTest.java
new file mode 100644
index 0000000..e498658
--- /dev/null
+++ 
b/stream-source-kafka/src/test/java/org/apache/kylin/stream/source/kafka/KafkaTopicAssignmentTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.stream.source.kafka;
+
+import org.apache.kafka.common.TopicPartition;
+import org.junit.Test;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for class {@link KafkaTopicAssignment}.
+ *
+ * @see KafkaTopicAssignment
+ */
+public class KafkaTopicAssignmentTest {
+
+    @Test
+    public void testEqualsReturningTrueForSameObject() {
+        List<TopicPartition> linkedList = new LinkedList<>();
+        KafkaTopicAssignment kafkaTopicAssignment = new 
KafkaTopicAssignment(0, linkedList);
+
+        assertTrue(kafkaTopicAssignment.equals(kafkaTopicAssignment));
+    }
+
+    @Test
+    public void testEqualsAndEqualsReturningTrueOne() {
+        List<TopicPartition> linkedList = new LinkedList<>();
+        KafkaTopicAssignment kafkaTopicAssignment = new 
KafkaTopicAssignment(0, linkedList);
+        KafkaTopicAssignment kafkaTopicAssignmentTwo = new 
KafkaTopicAssignment(0, linkedList);
+
+        assertTrue(kafkaTopicAssignment.equals(kafkaTopicAssignmentTwo));
+        assertTrue(kafkaTopicAssignmentTwo.equals(kafkaTopicAssignment));
+    }
+
+    @Test
+    public void testEqualsAndEqualsReturningFalseOne() {
+        KafkaTopicAssignment kafkaTopicAssignment = new 
KafkaTopicAssignment(null, null);
+        KafkaTopicAssignment kafkaTopicAssignmentTwo = new 
KafkaTopicAssignment(new Integer(0), null);
+
+        assertFalse(kafkaTopicAssignment.equals(kafkaTopicAssignmentTwo));
+        assertFalse(kafkaTopicAssignmentTwo.equals(kafkaTopicAssignment));
+    }
+
+    @Test
+    public void testEqualsAndEqualsReturningFalseThree() {
+        List<TopicPartition> linkedList = new LinkedList<>();
+        Integer integer = new Integer((-21));
+        KafkaTopicAssignment kafkaTopicAssignment = new 
KafkaTopicAssignment(integer, null);
+        KafkaTopicAssignment kafkaTopicAssignmentTwo = new 
KafkaTopicAssignment(integer, linkedList);
+
+        assertFalse(kafkaTopicAssignment.equals(kafkaTopicAssignmentTwo));
+    }
+
+    @Test
+    public void testEqualsAndEqualsReturningFalseFour() {
+        KafkaTopicAssignment kafkaTopicAssignment = new 
KafkaTopicAssignment(null, null);
+        Integer integer = new Integer(0);
+        KafkaTopicAssignment kafkaTopicAssignmentTwo = new 
KafkaTopicAssignment(integer, null);
+
+        assertFalse(kafkaTopicAssignment.equals(kafkaTopicAssignmentTwo));
+    }
+
+    @Test
+    public void testEqualsAndEqualsReturningTrueTwo() {
+        List<TopicPartition> linkedList = new LinkedList<>();
+        KafkaTopicAssignment kafkaTopicAssignment = new 
KafkaTopicAssignment(null, linkedList);
+        KafkaTopicAssignment kafkaTopicAssignmentTwo = new 
KafkaTopicAssignment(null, linkedList);
+
+        assertTrue(kafkaTopicAssignment.equals(kafkaTopicAssignmentTwo));
+    }
+
+    @Test
+    public void testEqualsWithNull() {
+        List<TopicPartition> linkedList = new LinkedList<TopicPartition>();
+        KafkaTopicAssignment kafkaTopicAssignment = new 
KafkaTopicAssignment(null, linkedList);
+
+        assertFalse(kafkaTopicAssignment.equals(null));
+    }
+
+    @Test
+    public void testEqualsAndEqualsReturningFalseFive() {
+        List<TopicPartition> linkedList = new LinkedList<>();
+        KafkaTopicAssignment kafkaTopicAssignment = new 
KafkaTopicAssignment(null, linkedList);
+        TopicPartition topicPartition = new TopicPartition("sW=V$uM^HI^g", 
3221);
+
+        assertFalse(kafkaTopicAssignment.equals(topicPartition));
+    }
+
+}
\ No newline at end of file

Reply via email to