Repository: hive Updated Branches: refs/heads/master 71b7f36cb -> 380946c13
HIVE-20361: ReplDumpTaskTest is failing (Sankar Hariappan, reviewed by Jesus Camacho Rodriguez) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/380946c1 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/380946c1 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/380946c1 Branch: refs/heads/master Commit: 380946c137d06058becc14ae00e7b41e133a11a3 Parents: 71b7f36 Author: Sankar Hariappan <sank...@apache.org> Authored: Sat Aug 11 08:45:39 2018 +0530 Committer: Sankar Hariappan <sank...@apache.org> Committed: Sat Aug 11 08:45:39 2018 +0530 ---------------------------------------------------------------------- .../hive/ql/exec/repl/ReplDumpTaskTest.java | 126 ---------------- .../hive/ql/exec/repl/TestReplDumpTask.java | 142 +++++++++++++++++++ 2 files changed, 142 insertions(+), 126 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/380946c1/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTaskTest.java ---------------------------------------------------------------------- diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTaskTest.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTaskTest.java deleted file mode 100644 index e719a08..0000000 --- a/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTaskTest.java +++ /dev/null @@ -1,126 +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.hadoop.hive.ql.exec.repl; - -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hive.ql.metadata.Hive; -import org.apache.hadoop.hive.ql.parse.repl.dump.Utils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.same; -import static org.mockito.Mockito.mock; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.verifyStatic; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ Utils.class }) -@PowerMockIgnore({ "javax.management.*" }) -public class ReplDumpTaskTest { - - @Mock - private Hive hive; - - class StubReplDumpTask extends ReplDumpTask { - - @Override - protected Hive getHive() { - return hive; - } - - @Override - long currentNotificationId(Hive hiveDb) { - return Long.MAX_VALUE; - } - - @Override - String getValidTxnListForReplDump(Hive hiveDb) { - return ""; - } - - @Override - void dumpFunctionMetadata(String dbName, Path dumpRoot) { - } - - @Override - Path dumpDbMetadata(String dbName, Path dumpRoot, long lastReplId) { - return Mockito.mock(Path.class); - } - - @Override - void dumpConstraintMetadata(String dbName, String tblName, Path dbRoot) { - } - } - - private static class TestException extends Exception { - } - - @Test(expected = TestException.class) - public void removeDBPropertyToPreventRenameWhenBootstrapDumpOfTableFails() throws Exception { - List<String> tableList = Arrays.asList("a1", "a2"); - String dbRandomKey = "akeytoberandom"; - - mockStatic(Utils.class); - when(Utils.matchesDb(same(hive), eq("default"))) - .thenReturn(Collections.singletonList("default")); - when(Utils.getAllTables(same(hive), eq("default"))).thenReturn(tableList); - when(Utils.setDbBootstrapDumpState(same(hive), eq("default"))).thenReturn(dbRandomKey); - when(Utils.matchesTbl(same(hive), eq("default"), anyString())).thenReturn(tableList); - - - when(hive.getAllFunctions()).thenReturn(Collections.emptyList()); - - ReplDumpTask task = new StubReplDumpTask() { - private int tableDumpCount = 0; - - @Override - void dumpTable(String dbName, String tblName, String validTxnList, Path dbRoot, long lastReplId) - throws Exception { - tableDumpCount++; - if (tableDumpCount > 1) { - throw new TestException(); - } - } - }; - - task.setWork( - new ReplDumpWork("default", "", - Long.MAX_VALUE, Long.MAX_VALUE, "", - Integer.MAX_VALUE, "") - ); - - try { - task.bootStrapDump(mock(Path.class), null, mock(Path.class)); - } finally { - verifyStatic(); - Utils.resetDbBootstrapDumpState(same(hive), eq("default"), eq(dbRandomKey)); - } - } -} http://git-wip-us.apache.org/repos/asf/hive/blob/380946c1/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestReplDumpTask.java ---------------------------------------------------------------------- diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestReplDumpTask.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestReplDumpTask.java new file mode 100644 index 0000000..d5956dd --- /dev/null +++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/TestReplDumpTask.java @@ -0,0 +1,142 @@ + /* + * 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.hadoop.hive.ql.exec.repl; + +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.QueryState; +import org.apache.hadoop.hive.ql.metadata.Hive; +import org.apache.hadoop.hive.ql.parse.repl.dump.Utils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.same; +import static org.mockito.Mockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.verifyStatic; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Utils.class }) +@PowerMockIgnore({ "javax.management.*" }) +public class TestReplDumpTask { + + protected static final Logger LOG = LoggerFactory.getLogger(TestReplDumpTask.class); + + @Mock + private Hive hive; + + @Mock + private HiveConf conf; + + @Mock + private QueryState queryState; + + class StubReplDumpTask extends ReplDumpTask { + + @Override + protected Hive getHive() { + return hive; + } + + @Override + long currentNotificationId(Hive hiveDb) { + return Long.MAX_VALUE; + } + + @Override + String getValidTxnListForReplDump(Hive hiveDb) { + return ""; + } + + @Override + void dumpFunctionMetadata(String dbName, Path dumpRoot) { + } + + @Override + Path dumpDbMetadata(String dbName, Path dumpRoot, long lastReplId) { + return Mockito.mock(Path.class); + } + + @Override + void dumpConstraintMetadata(String dbName, String tblName, Path dbRoot) { + } + } + + private static class TestException extends Exception { + } + + @Test(expected = TestException.class) + public void removeDBPropertyToPreventRenameWhenBootstrapDumpOfTableFails() throws Exception { + List<String> tableList = Arrays.asList("a1", "a2"); + String dbRandomKey = "akeytoberandom"; + + mockStatic(Utils.class); + when(Utils.matchesDb(same(hive), eq("default"))) + .thenReturn(Collections.singletonList("default")); + when(Utils.getAllTables(same(hive), eq("default"))).thenReturn(tableList); + when(Utils.setDbBootstrapDumpState(same(hive), eq("default"))).thenReturn(dbRandomKey); + when(Utils.matchesTbl(same(hive), eq("default"), anyString())).thenReturn(tableList); + + + when(hive.getAllFunctions()).thenReturn(Collections.emptyList()); + when(queryState.getConf()).thenReturn(conf); + when(conf.getLong("hive.repl.last.repl.id", -1L)).thenReturn(1L); + + ReplDumpTask task = new StubReplDumpTask() { + private int tableDumpCount = 0; + + @Override + void dumpTable(String dbName, String tblName, String validTxnList, Path dbRoot, long lastReplId) + throws Exception { + tableDumpCount++; + if (tableDumpCount > 1) { + throw new TestException(); + } + } + }; + + task.initialize(queryState, null, null, null); + task.setWork( + new ReplDumpWork("default", "", + Long.MAX_VALUE, Long.MAX_VALUE, "", + Integer.MAX_VALUE, "") + ); + + try { + task.bootStrapDump(mock(Path.class), null, mock(Path.class)); + } finally { + verifyStatic(); + Utils.resetDbBootstrapDumpState(same(hive), eq("default"), eq(dbRandomKey)); + } + } +}