MRUnit ์ผ๋ก MultipleOutputs ๋ฅผ ์ฌ์ฉํ๋ M/R ํ ์คํธ ์ฝ๋ ์์ฑํ๊ธฐ
MRUnit 1.0.0 ๋ฒ์ ์์๋ MultipleOutputs ๋ฅผ ์ฌ์ฉํ M/R ์ฝ๋๋ฅผ ํ ์คํ ์ ์๋ ๊ธฐ๋ฅ์ด ์ ๊ณต๋์ง ์๋๋ค. ํ์ง๋ง ์ด์ ๊ด๋ จ๋ ์ด์ MRUnit-13 ๋ฅผ ์ดํด๋ณด๋ฉด ๊ธฐ๋ฅ ์ถ๊ฐ๊ฐ ์๋ฃ๋์๊ณ , ๋ค์ ๋ฒ์ (1.1.0)์ ์ถ๊ฐ๋์ด ๋์ฌ ๊ฒ์ด๋ผ๋ ๊ฑธ ์ ์ ์๋ค.
ํ์ง๋ง, ๋น์ฅ Unit test ๋ฅผ ์์ฑํ๊ณ ๊ฒ์ฆํ๋๋ฐ ์ด์ฉํด์ผ ํ๋ ์ํฉ์ด๋ผ๋ฉด ๊ฐ๋ฐ ์ค์ธ ๋ฒ์ ์ ๋ฐ์ ์ฌ์ฉํด๋ณผ ์ ์๋ค.
MRUnit ์ค์น ์ ํ๊ฒฝ ๊ตฌ์ถ
ํ๋ก์ ํธ ๋น๋ ํ๊ฒฝ์ Mac OS X 10.9 Mavericks ์ด๋ฉฐ, Maven 2 ์ Java 7 ์ ์ด์ฉํ๋ค.
Maven 2 ์ค์น (Maven 3 ์ผ๋ก๋ ๋น๋๊ฐ ๋์ง ์์์)
$ brew install maven2
Java 7 ์ค์น
http://www.oracle.com/technetwork/java/javase/downloads/index.html
์์กด์ฑ์ ๊ฐ์ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ (Maven Repository)
junit 4.10
guava 11.0.2
hadoop-common 2.3.0
hadoop-mapreduce-client-core 2.3.0
powermock-core 1.5.1
powermock-api-mockito 1.5.1
powermock-module-junit4 1.5.1
powermock-module-junit4-common 1.5.1
MRUnit ์ค์น
SOURCE AND GUIDE ํ์ด์ง ์ฐธ์กฐ.
์ ์ฅ์์์ ์ต์ ์์ค ์ฝ๋ ๋ค์ด๋ก๋
$ git clone http://git-wip-us.apache.org/repos/asf/mrunit.git
Maven ์ ์ด์ฉํด ํ๋ก์ ํธ ๋น๋
$ mvn package -Dhadoop.version=2 -Drat.numUnapprovedLic enses=128
๋น๋์ ์ฑ๊ณตํ๋ฉด target ๋๋ ํ ๋ฆฌ ๋ฐ์์ mrunit-1.2.0-SNAPSHOT-hadoop2.jar ํ์ผ์ ์ฐพ์ ์ ์๋ค. (๋ฒ์ ์ ๋ณด๋ ๋ฌ๋ผ์ง ์ ์์)
Unit test ์์ฑ
Unit test ๋ฅผ ์์ฑํ ๋ mrunit/src/test ๋ฐ์ ์๋ ์ฝ๋๋ฅผ ์ฐธ์กฐํ๋ค. (MultipleOutputs ์ ๋ํ ํ ์คํธ๋ test/java/org/apache/hadoop/mrunit/mapreduce/TestMultipleOutput.java ์ฐธ์กฐ)
@RunWith(PowerMockRunner.class) @PrepareForTest({MultipleOutputs.class, MyMap.class}) public class TestMyMap { private MapDriver<LongWritable, Text, Text, IntWritable> mapDriver; ... @Test public void testMyMapWithMultipleOutputs() throws Exception { mapDriver = MapDriver.newMapDriver(new MyMap()); mapDriver.withInput(new LongWritable(0), new Text("first")); mapDriver.withMultiOutput("OUT1", new Text("first"), new IntWritable(1)); mapDriver.runTest(); } ... }
@PrepareForTest() ์์ MultipleOutputs ํด๋์ค์ ํ ์คํธํ๊ณ ์ ํ๋ Mapper, Reducer ๋ฅผ ๋ช ์ํด๋๋ค.
withMultiOutput() ๋ฉ์๋๋ฅผ ์ด์ฉํด MultipleOutputs ๋ก ์ถ๋ ฅํ๋ Mapper/Reducer ํ ์คํธ ์ฝ๋๋ฅผ ์์ฑํ๋ค. ์ฒซ ๋ฒ์งธ ์ธ์์๋ NamedOutput ์ ์ฌ์ฉํ ์ด๋ฆ์ ๋๊ฒจ์ฃผ๊ณ , ๋ ๋ฒ์งธ์ ์ธ ๋ฒ์งธ ์ธ์์๋ ๊ฒฐ๊ณผ๋ก ์์๋๋ Key/Value ๋ฅผ ๋๊ฒจ์ค๋ค.
















