commit 4ace11b152043487245275143a0ec7f1742de34f Author: Owen O'Malley Date: Fri Mar 11 10:38:34 2016 -0800 HIVE-13232. Aggressively drop compression buffers in ORC OutStreams. diff --git orc/src/java/org/apache/orc/impl/OutStream.java orc/src/java/org/apache/orc/impl/OutStream.java index 68ef7d4..81662cc 100644 --- orc/src/java/org/apache/orc/impl/OutStream.java +++ orc/src/java/org/apache/orc/impl/OutStream.java @@ -243,8 +243,8 @@ public void flush() throws IOException { if (compressed != null && compressed.position() != 0) { compressed.flip(); receiver.output(compressed); - compressed = null; } + compressed = null; uncompressedBytes = 0; compressedBytes = 0; overflow = null; diff --git orc/src/test/org/apache/orc/impl/TestOutStream.java orc/src/test/org/apache/orc/impl/TestOutStream.java new file mode 100644 index 0000000..e9614d5 --- /dev/null +++ orc/src/test/org/apache/orc/impl/TestOutStream.java @@ -0,0 +1,43 @@ +/** + * 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.orc.impl; + +import org.apache.orc.CompressionCodec; +import org.junit.Test; +import org.mockito.Mockito; + +import java.nio.ByteBuffer; + +import static org.junit.Assert.assertEquals; + +public class TestOutStream { + + @Test + public void testFlush() throws Exception { + OutStream.OutputReceiver receiver = + Mockito.mock(OutStream.OutputReceiver.class); + CompressionCodec codec = new ZlibCodec(); + OutStream stream = new OutStream("test", 128*1024, codec, receiver); + assertEquals(0L, stream.getBufferSize()); + stream.write(new byte[]{0, 1, 2}); + stream.flush(); + Mockito.verify(receiver).output(Mockito.any(ByteBuffer.class)); + assertEquals(0L, stream.getBufferSize()); + } +}