Author: yliu
Date: Thu Jun 5 01:30:40 2014
New Revision: 1600553
URL: http://svn.apache.org/r1600553
Log:
HADOOP-10662. NullPointerException in CryptoInputStream while wrapped stream is
not ByteBufferReadable. Add tests using normal stream. Contributed by Yi Liu
Added:
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsNormal.java
Modified:
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/CHANGES-fs-encryption.txt
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java
Modified:
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/CHANGES-fs-encryption.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/CHANGES-fs-encryption.txt?rev=1600553&r1=1600552&r2=1600553&view=diff
==============================================================================
---
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/CHANGES-fs-encryption.txt
(original)
+++
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/CHANGES-fs-encryption.txt
Thu Jun 5 01:30:40 2014
@@ -24,6 +24,9 @@ fs-encryption (Unreleased)
HADOOP-10653. Add a new constructor for CryptoInputStream that
receives current position of wrapped stream. (Yi Liu)
+ HADOOP-10662. NullPointerException in CryptoInputStream while wrapped
+ stream is not ByteBufferReadable. Add tests using normal stream. (Yi Liu)
+
OPTIMIZATIONS
BUG FIXES
Modified:
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java?rev=1600553&r1=1600552&r2=1600553&view=diff
==============================================================================
---
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java
(original)
+++
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java
Thu Jun 5 01:30:40 2014
@@ -172,6 +172,8 @@ public class CryptoInputStream extends F
} catch (UnsupportedOperationException e) {
usingByteBufferRead = Boolean.FALSE;
}
+ } else {
+ usingByteBufferRead = Boolean.FALSE;
}
if (!usingByteBufferRead) {
n = readFromUnderlyingStream(inBuffer);
Added:
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsNormal.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsNormal.java?rev=1600553&view=auto
==============================================================================
---
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsNormal.java
(added)
+++
hadoop/common/branches/fs-encryption/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/crypto/TestCryptoStreamsNormal.java
Thu Jun 5 01:30:40 2014
@@ -0,0 +1,123 @@
+/**
+ * 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.crypto;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Test crypto streams using normal stream which does not support the
+ * additional interfaces that the Hadoop FileSystem streams implement
+ * (Seekable, PositionedReadable, ByteBufferReadable, HasFileDescriptor,
+ * CanSetDropBehind, CanSetReadahead, HasEnhancedByteBufferAccess, Syncable,
+ * CanSetDropBehind)
+ */
+public class TestCryptoStreamsNormal extends CryptoStreamsTestBase {
+ /**
+ * Data storage.
+ * {@link #getOutputStream(int, byte[], byte[])} will write to this buffer.
+ * {@link #getInputStream(int, byte[], byte[])} will read from this buffer.
+ */
+ private byte[] buffer;
+ private int bufferLen;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ Configuration conf = new Configuration();
+ codec = CryptoCodec.getInstance(conf);
+ }
+
+ @AfterClass
+ public static void shutdown() throws Exception {
+ }
+
+ @Override
+ protected OutputStream getOutputStream(int bufferSize, byte[] key, byte[] iv)
+ throws IOException {
+ OutputStream out = new ByteArrayOutputStream() {
+ @Override
+ public void flush() throws IOException {
+ buffer = buf;
+ bufferLen = count;
+ }
+ @Override
+ public void close() throws IOException {
+ buffer = buf;
+ bufferLen = count;
+ }
+ };
+ return new CryptoOutputStream(out, codec, bufferSize, key, iv);
+ }
+
+ @Override
+ protected InputStream getInputStream(int bufferSize, byte[] key, byte[] iv)
+ throws IOException {
+ ByteArrayInputStream in = new ByteArrayInputStream(buffer, 0, bufferLen);
+ return new CryptoInputStream(in, codec, bufferSize,
+ key, iv);
+ }
+
+ @Ignore("Wrapped stream doesn't support Syncable")
+ @Override
+ @Test(timeout=1000)
+ public void testSyncable() throws IOException {}
+
+ @Ignore("Wrapped stream doesn't support PositionedRead")
+ @Override
+ @Test(timeout=1000)
+ public void testPositionedRead() throws IOException {}
+
+ @Ignore("Wrapped stream doesn't support ReadFully")
+ @Override
+ @Test(timeout=1000)
+ public void testReadFully() throws IOException {}
+
+ @Ignore("Wrapped stream doesn't support Seek")
+ @Override
+ @Test(timeout=1000)
+ public void testSeek() throws IOException {}
+
+ @Ignore("Wrapped stream doesn't support ByteBufferRead")
+ @Override
+ @Test(timeout=1000)
+ public void testByteBufferRead() throws IOException {}
+
+ @Ignore("Wrapped stream doesn't support ByteBufferRead, Seek")
+ @Override
+ @Test(timeout=1000)
+ public void testCombinedOp() throws IOException {}
+
+ @Ignore("Wrapped stream doesn't support SeekToNewSource")
+ @Override
+ @Test(timeout=1000)
+ public void testSeekToNewSource() throws IOException {}
+
+ @Ignore("Wrapped stream doesn't support HasEnhancedByteBufferAccess")
+ @Override
+ @Test(timeout=1000)
+ public void testHasEnhancedByteBufferAccess() throws IOException {}
+}