[120] | 1 | /** |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
| 3 | * or more contributor license agreements. See the NOTICE file |
---|
| 4 | * distributed with this work for additional information |
---|
| 5 | * regarding copyright ownership. The ASF licenses this file |
---|
| 6 | * to you under the Apache License, Version 2.0 (the |
---|
| 7 | * "License"); you may not use this file except in compliance |
---|
| 8 | * with the License. You may obtain a copy of the License at |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, software |
---|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | * See the License for the specific language governing permissions and |
---|
| 16 | * limitations under the License. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | package org.apache.hadoop.mapred; |
---|
| 20 | |
---|
| 21 | import java.io.*; |
---|
| 22 | import junit.framework.TestCase; |
---|
| 23 | import org.apache.hadoop.hdfs.MiniDFSCluster; |
---|
| 24 | import org.apache.hadoop.fs.FileSystem; |
---|
| 25 | import org.apache.hadoop.mapred.MRCaching.TestResult; |
---|
| 26 | |
---|
| 27 | /** |
---|
| 28 | * A JUnit test to test caching with DFS |
---|
| 29 | * |
---|
| 30 | */ |
---|
| 31 | public class TestMiniMRDFSCaching extends TestCase { |
---|
| 32 | |
---|
| 33 | public void testWithDFS() throws IOException { |
---|
| 34 | MiniMRCluster mr = null; |
---|
| 35 | MiniDFSCluster dfs = null; |
---|
| 36 | FileSystem fileSys = null; |
---|
| 37 | try { |
---|
| 38 | JobConf conf = new JobConf(); |
---|
| 39 | conf.set("fs.hdfs.impl", |
---|
| 40 | "org.apache.hadoop.hdfs.ChecksumDistributedFileSystem"); |
---|
| 41 | dfs = new MiniDFSCluster(conf, 1, true, null); |
---|
| 42 | fileSys = dfs.getFileSystem(); |
---|
| 43 | mr = new MiniMRCluster(2, fileSys.getName(), 4); |
---|
| 44 | MRCaching.setupCache("/cachedir", fileSys); |
---|
| 45 | // run the wordcount example with caching |
---|
| 46 | TestResult ret = MRCaching.launchMRCache("/testing/wc/input", |
---|
| 47 | "/testing/wc/output", |
---|
| 48 | "/cachedir", |
---|
| 49 | mr.createJobConf(), |
---|
| 50 | "The quick brown fox\nhas many silly\n" |
---|
| 51 | + "red fox sox\n", false); |
---|
| 52 | assertTrue("Archives not matching", ret.isOutputOk); |
---|
| 53 | // launch MR cache with symlinks |
---|
| 54 | ret = MRCaching.launchMRCache("/testing/wc/input", |
---|
| 55 | "/testing/wc/output", |
---|
| 56 | "/cachedir", |
---|
| 57 | mr.createJobConf(), |
---|
| 58 | "The quick brown fox\nhas many silly\n" |
---|
| 59 | + "red fox sox\n", true); |
---|
| 60 | assertTrue("Archives not matching", ret.isOutputOk); |
---|
| 61 | } finally { |
---|
| 62 | if (fileSys != null) { |
---|
| 63 | fileSys.close(); |
---|
| 64 | } |
---|
| 65 | if (dfs != null) { |
---|
| 66 | dfs.shutdown(); |
---|
| 67 | } |
---|
| 68 | if (mr != null) { |
---|
| 69 | mr.shutdown(); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | public static void main(String[] argv) throws Exception { |
---|
| 75 | TestMiniMRDFSCaching td = new TestMiniMRDFSCaching(); |
---|
| 76 | td.testWithDFS(); |
---|
| 77 | } |
---|
| 78 | } |
---|