HADOOP-9540. Expose the InMemoryS3 and S3N FilesystemStores implementations for Unit testing. Hari
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1479985 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1f5ac02a0d
commit
fa56ccfd53
|
@ -548,6 +548,9 @@ Trunk (Unreleased)
|
||||||
HADOOP-9483. winutils support for readlink command.
|
HADOOP-9483. winutils support for readlink command.
|
||||||
(Arpit Agarwal via suresh)
|
(Arpit Agarwal via suresh)
|
||||||
|
|
||||||
|
HADOOP-9540. Expose the InMemoryS3 and S3N FilesystemStores implementations for Unit testing.
|
||||||
|
(Hari via stevel)
|
||||||
|
|
||||||
Release 2.0.5-beta - UNRELEASED
|
Release 2.0.5-beta - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -41,7 +41,7 @@ import org.apache.hadoop.fs.s3.INode.FileType;
|
||||||
* A stub implementation of {@link FileSystemStore} for testing
|
* A stub implementation of {@link FileSystemStore} for testing
|
||||||
* {@link S3FileSystem} without actually connecting to S3.
|
* {@link S3FileSystem} without actually connecting to S3.
|
||||||
*/
|
*/
|
||||||
class InMemoryFileSystemStore implements FileSystemStore {
|
public class InMemoryFileSystemStore implements FileSystemStore {
|
||||||
|
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
private SortedMap<Path, INode> inodes = new TreeMap<Path, INode>();
|
private SortedMap<Path, INode> inodes = new TreeMap<Path, INode>();
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
* 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.fs.s3;
|
||||||
|
|
||||||
|
import org.apache.hadoop.fs.s3.S3FileSystem;
|
||||||
|
import org.apache.hadoop.fs.s3.InMemoryFileSystemStore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper implementation of {@link S3FileSystem}
|
||||||
|
* without actually connecting to S3 for unit testing.
|
||||||
|
*/
|
||||||
|
public class S3InMemoryFileSystem extends S3FileSystem {
|
||||||
|
public S3InMemoryFileSystem() {
|
||||||
|
super(new InMemoryFileSystemStore());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/**
|
||||||
|
* 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.fs.s3;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URI;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.fs.FSDataInputStream;
|
||||||
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||||
|
import org.apache.hadoop.fs.Path;
|
||||||
|
|
||||||
|
public class TestS3InMemoryFileSystem extends TestCase {
|
||||||
|
|
||||||
|
private static final String TEST_PATH = "s3://test/data.txt";
|
||||||
|
|
||||||
|
private static final String TEST_DATA = "Sample data for testing.";
|
||||||
|
|
||||||
|
private S3InMemoryFileSystem fs;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() throws IOException {
|
||||||
|
fs = new S3InMemoryFileSystem();
|
||||||
|
fs.initialize(URI.create("s3://test/"), new Configuration());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBasicReadWriteIO() throws IOException {
|
||||||
|
FSDataOutputStream writeStream = fs.create(new Path(TEST_PATH));
|
||||||
|
writeStream.write(TEST_DATA.getBytes());
|
||||||
|
writeStream.flush();
|
||||||
|
writeStream.close();
|
||||||
|
|
||||||
|
FSDataInputStream readStream = fs.open(new Path(TEST_PATH));
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(readStream));
|
||||||
|
String line = "";
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
stringBuffer.append(line);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
assert(TEST_DATA.equals(stringBuffer.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tearDown() throws IOException {
|
||||||
|
fs.close();
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,7 +47,7 @@ import org.apache.hadoop.util.Time;
|
||||||
* {@link NativeS3FileSystem} without actually connecting to S3.
|
* {@link NativeS3FileSystem} without actually connecting to S3.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
class InMemoryNativeFileSystemStore implements NativeFileSystemStore {
|
public class InMemoryNativeFileSystemStore implements NativeFileSystemStore {
|
||||||
|
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
* 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.fs.s3native;
|
||||||
|
|
||||||
|
import org.apache.hadoop.fs.s3native.NativeS3FileSystem;
|
||||||
|
import org.apache.hadoop.fs.s3native.InMemoryNativeFileSystemStore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper implementation of {@link NativeS3FileSystem}
|
||||||
|
* without actually connecting to S3 for unit testing.
|
||||||
|
*/
|
||||||
|
public class S3NInMemoryFileSystem extends NativeS3FileSystem {
|
||||||
|
public S3NInMemoryFileSystem() {
|
||||||
|
super(new InMemoryNativeFileSystemStore());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/**
|
||||||
|
* 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.fs.s3native;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.fs.FSDataInputStream;
|
||||||
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||||
|
import org.apache.hadoop.fs.Path;
|
||||||
|
|
||||||
|
public class TestS3NInMemoryFileSystem extends TestCase {
|
||||||
|
|
||||||
|
private static final String TEST_PATH = "s3n://test/data.txt";
|
||||||
|
|
||||||
|
private static final String TEST_DATA = "Sample data for testing.";
|
||||||
|
|
||||||
|
private S3NInMemoryFileSystem fs;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUp() throws IOException {
|
||||||
|
fs = new S3NInMemoryFileSystem();
|
||||||
|
fs.initialize(URI.create("s3n://test/"), new Configuration());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBasicReadWriteIO() throws IOException {
|
||||||
|
FSDataOutputStream writeData = fs.create(new Path(TEST_PATH));
|
||||||
|
writeData.write(TEST_DATA.getBytes());
|
||||||
|
writeData.flush();
|
||||||
|
writeData.close();
|
||||||
|
|
||||||
|
FSDataInputStream readData = fs.open(new Path(TEST_PATH));
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(readData));
|
||||||
|
String line = "";
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
stringBuffer.append(line);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
assert(TEST_DATA.equals(stringBuffer.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tearDown() throws IOException {
|
||||||
|
fs.close();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue