diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTask.java index 055decdd49..062f367f6b 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTask.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplDumpTask.java @@ -203,11 +203,11 @@ private void initiateDataCopyTasks() throws SemanticException { } private void finishRemainingTasks() throws SemanticException { - prepareReturnValues(work.getResultValues()); Path dumpAckFile = new Path(work.getCurrentDumpPath(), ReplUtils.REPL_HIVE_BASE_DIR + File.separator + ReplAck.DUMP_ACKNOWLEDGEMENT.toString()); Utils.create(dumpAckFile, conf); + prepareReturnValues(work.getResultValues()); deleteAllPreviousDumpMeta(work.getCurrentDumpPath()); } diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/Utils.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/Utils.java index 3b49801138..44320a5932 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/Utils.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/repl/dump/Utils.java @@ -127,7 +127,7 @@ public static void create(Path outputFile, HiveConf hiveConf) @Override public Void execute() throws IOException { FileSystem fs = outputFile.getFileSystem(hiveConf); - fs.create(outputFile); + fs.create(outputFile).close(); return null; } }; diff --git a/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/dump/TestUtils.java b/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/dump/TestUtils.java new file mode 100644 index 0000000000..2da3e8ae96 --- /dev/null +++ b/ql/src/test/org/apache/hadoop/hive/ql/exec/repl/dump/TestUtils.java @@ -0,0 +1,55 @@ + /* + * 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.dump; + +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.parse.SemanticException; +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.mockito.junit.MockitoJUnitRunner; + +import java.io.IOException; +import static org.mockito.Mockito.times; + +@RunWith(MockitoJUnitRunner.class) +public class TestUtils { + + @Mock + Path outputFile; + + @Mock + FileSystem fileSystem; + + @Mock + FSDataOutputStream outputStream; + + @Test + public void testCreate() throws SemanticException, IOException { + HiveConf conf = new HiveConf(); + Mockito.when(outputFile.getFileSystem(conf)).thenReturn(fileSystem); + Mockito.when(fileSystem.create(outputFile)).thenReturn(outputStream); + Utils.create(outputFile, conf); + Mockito.verify(outputStream, times(1)).close(); + } +}