• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 200, comments - 8, trackbacks - 0, articles - 0

                 摘要: 轉(zhuǎn)自:http://www.redisbook.com 跳躍表¶跳躍表(skiplist)是一種隨機(jī)化的數(shù)據(jù), 由 William Pugh 在論文《Skip lists: a probabilistic alternative to balanced trees》中提出, 這種數(shù)據(jù)結(jié)構(gòu)以有序的方式在層次化的鏈表中保存元素, 它的效率可以和平衡樹(shù)媲美 ——...  閱讀全文

            posted @ 2013-04-06 20:45 鑫龍 閱讀(2243) | 評(píng)論 (0)編輯 收藏

                 摘要: 本文內(nèi)容框架: §1 Skip List 介紹 §2 Skip List 定義以及構(gòu)造步驟 §3 Skip List 完整實(shí)現(xiàn) §4 Skip List 概率分析 §5 小結(jié)   §1 Skip List 介紹  Skip List是一種隨機(jī)化的數(shù)據(jù)結(jié)構(gòu),基于并聯(lián)的鏈表,其效率可...  閱讀全文

            posted @ 2013-04-06 19:55 鑫龍 閱讀(13450) | 評(píng)論 (0)編輯 收藏

                 摘要:  轉(zhuǎn)自:http://www.redisbook.com字典字典(dictionary), 又名映射(map)或關(guān)聯(lián)數(shù)組(associative array), 它是一種抽象數(shù)據(jù)結(jié)構(gòu), 由一集鍵值對(duì)(key-value pairs)組成, 各個(gè)鍵值對(duì)的鍵各不相同, 程序可以將新的鍵值對(duì)添加到字典中, 或者基于鍵進(jìn)行查找、更新或刪除等操作。本章先對(duì)字典在 Redis 中的應(yīng)用進(jìn)行...  閱讀全文

            posted @ 2013-04-05 19:00 鑫龍 閱讀(3895) | 評(píng)論 (0)編輯 收藏

                 摘要:  轉(zhuǎn)自:http://www.redisbook.com雙端鏈表鏈表作為數(shù)組之外的一種常用序列抽象, 是大多數(shù)高級(jí)語(yǔ)言的基本數(shù)據(jù)類(lèi)型, 因?yàn)?C 語(yǔ)言本身不支持鏈表類(lèi)型, 大部分 C 程序都會(huì)自己實(shí)現(xiàn)一種鏈表類(lèi)型, Redis 也不例外 —— 它實(shí)現(xiàn)了一個(gè)雙端鏈表結(jié)構(gòu)。雙端鏈表作為一種常見(jiàn)的數(shù)據(jù)結(jié)構(gòu), 在大部分的數(shù)據(jù)結(jié)構(gòu)或者算法書(shū)里都有講解, 因此, 這一章關(guān)注的...  閱讀全文

            posted @ 2013-04-05 18:05 鑫龍 閱讀(519) | 評(píng)論 (0)編輯 收藏

                 摘要: 轉(zhuǎn)自:http://www.redisbook.com簡(jiǎn)單動(dòng)態(tài)字符串Sds (Simple Dynamic String,簡(jiǎn)單動(dòng)態(tài)字符串)是 Redis 底層所使用的字符串表示, 它被用在幾乎所有的 Redis 模塊中。本章將對(duì) sds 的實(shí)現(xiàn)、性能和功能等方面進(jìn)行介紹, 并說(shuō)明 Redis 使用 sds 而不是傳統(tǒng) C 字符串的原因。sds 的用途Sds 在 Redis 中的主要作用有以下兩個(gè):...  閱讀全文

            posted @ 2013-04-05 17:54 鑫龍 閱讀(1139) | 評(píng)論 (0)編輯 收藏

                 摘要: 雖然Redis已經(jīng)很火了,相信還是有很多同學(xué)對(duì)Redis只是有所聽(tīng)聞或者了解并不全面,下面是一個(gè)比較系統(tǒng)的Redis介紹,對(duì)Redis的特性及各種數(shù)據(jù)類(lèi)型及操作進(jìn)行了介紹。是一個(gè)很不錯(cuò)的Redis入門(mén)教程。1.介紹1.1 Redis是什么REmote DIctionary Server(Redis) 是一個(gè)由Salvatore Sanfilippo寫(xiě)的key-value存儲(chǔ)系統(tǒng)...  閱讀全文

            posted @ 2013-04-05 14:46 鑫龍 閱讀(509) | 評(píng)論 (0)編輯 收藏

                 摘要: 目錄:1. Linux系統(tǒng)調(diào)用原理2. 系統(tǒng)調(diào)用的實(shí)現(xiàn)3. Linux系統(tǒng)調(diào)用分類(lèi)及列表4.系統(tǒng)調(diào)用、用戶(hù)編程接口(API)、系統(tǒng)命令和內(nèi)核函數(shù)的關(guān)系5. Linux系統(tǒng)調(diào)用實(shí)例6. Linux自定義系統(tǒng)調(diào)用1.系統(tǒng)調(diào)用原理系統(tǒng)調(diào)用,顧名思義,說(shuō)的是操作系統(tǒng)提供給用戶(hù)程序調(diào)用的一組“特殊”接口。用戶(hù)程序可以通過(guò)這組“特殊”接口來(lái)獲得操作系統(tǒng)內(nèi)核提供的...  閱讀全文

            posted @ 2013-04-04 11:57 鑫龍 閱讀(1206) | 評(píng)論 (0)編輯 收藏

            回環(huán)設(shè)備(loop-back devices) ¶

            回環(huán)設(shè)備( 'loopback device')允許用戶(hù)以一個(gè)普通磁盤(pán)文件虛擬一個(gè)塊設(shè)備。設(shè)想一個(gè)磁盤(pán)設(shè)備,對(duì)它的所有讀寫(xiě)操作都將被重定向到讀寫(xiě)一個(gè)名為 disk-image 的普通文件而非操作實(shí)際磁盤(pán)或分區(qū)的軌道和扇區(qū)。(當(dāng)然,disk-image 必須存在于一個(gè)實(shí)際的磁盤(pán)上,而這個(gè)磁盤(pán)必須比虛擬的磁盤(pán)容量更大。)回環(huán)設(shè)備允許你這樣使用一個(gè)普通文件。

            回環(huán)設(shè)備以 /dev/loop0、/dev/loop1 等命名。每個(gè)設(shè)備可虛擬一個(gè)塊設(shè)備。注意只有超級(jí)用戶(hù)才有權(quán)限設(shè)置回環(huán)設(shè)備。

            回環(huán)設(shè)備的使用與其它任何塊設(shè)備相同。特別是,你可以在這個(gè)設(shè)備上創(chuàng)建文件系統(tǒng)并像普通的磁盤(pán)一樣將它掛載在系統(tǒng)中。這樣的一個(gè)將全部?jī)?nèi)容保存在一個(gè)普通文件中的文件系統(tǒng),被稱(chēng)為虛擬文件系統(tǒng)(virtual file system)(譯者注:這個(gè)用法并不常見(jiàn)。VFS 通常另有所指,如指代 Linux 內(nèi)核中有關(guān)文件系統(tǒng)抽象的代碼層次等)。

            可以通過(guò)下列步驟創(chuàng)建一個(gè)虛擬文件系統(tǒng)并通過(guò)回環(huán)設(shè)備掛載:

            創(chuàng)建一個(gè)用于承載虛擬文件系統(tǒng)的空文件。這個(gè)文件的大小將成為掛載后文件系統(tǒng)的大小。
            創(chuàng)建指定大小文件的簡(jiǎn)單方法是通過(guò) dd 命令。這個(gè)命令以塊為單位(通常為 512 字節(jié))從一個(gè)文件向另一個(gè)文件復(fù)制數(shù)據(jù)。/dev/zero 文件則是一個(gè)很好的數(shù)據(jù)來(lái)源。
            要建立一個(gè) 10 MB 大的名為 disk-image 的文件可以通過(guò)以下命令:
            % dd if=/dev/zero of=/tmp/disk-image count=20480
            20480+0 records in
            20480+0 records out
            % ls -l /tmp/disk-image
            -rw-rw----     1 root      root       10485760 Mar   8 01:56 /tmp/disk-image
            這個(gè)新建立的文件被填滿(mǎn)了 0 字節(jié)。在掛載之前,必須在其上建立一個(gè)文件系統(tǒng)。這個(gè)過(guò)程會(huì)建立許多用于組織和存儲(chǔ)文件的控制單元并構(gòu)造根目錄結(jié)構(gòu)。
            在這個(gè)磁盤(pán)映像之上可以構(gòu)建任何類(lèi)型的文件系統(tǒng)。以創(chuàng)建 ext2 文件系統(tǒng)為例(ext2 是 Linux 系統(tǒng)中最常見(jiàn)的文件系統(tǒng)),用 mke2fs 可以完成這個(gè)操作。因?yàn)檫@個(gè)命令通常是針對(duì)塊設(shè)備進(jìn)行操作,當(dāng)對(duì)一個(gè)普通文件操作時(shí)它會(huì)要求確認(rèn):
            % mke2fs -q /tmp/disk-image
            mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
            disk-image is not a block special device.
            Proceed anyway? (y,n) y
            這里 -q 參數(shù)用于省略輸出有關(guān)新建立文件系統(tǒng)的概要信息。如果你想看到這些信息,則請(qǐng)省略這個(gè)參數(shù)。
            現(xiàn)在 disk-image 文件包含了一個(gè)新建立的文件系統(tǒng),正如一個(gè)被剛剛初始化完畢的 10 MB 大小的磁盤(pán)。
            以一個(gè)環(huán)回設(shè)備掛載這個(gè)文件系統(tǒng)。方法是使用 mount 命令,指定磁盤(pán)文件為被掛載的設(shè)備。同時(shí)指定 loop=loopback-device 作為 -o 選項(xiàng)的參數(shù),告訴 mount 命令使用哪個(gè)回環(huán)設(shè)備。
            下面例子中的命令可用于掛載我們的 disk-image 文件系統(tǒng)。要記住的是只有超級(jí)用戶(hù)可以使用環(huán)回設(shè)備。第一個(gè)命令將創(chuàng)建一個(gè)目錄 /tmp/virtual-fs,這個(gè)目錄將被用于掛載我們的文件系統(tǒng)。
            % mkdir /tmp/virtual-fs
            % mount -o loopback=/dev/loop0 /tmp/disk-image /tmp/virtual-fs
            這時(shí),這個(gè)設(shè)備應(yīng)該已經(jīng)被掛載,就如同一個(gè)普通的 10M 空間的磁盤(pán)一樣。
            % df -h /tmp/virtual-fs
            Filesystem   Size Used Avail Use% Mounted on
            /tmp/disk-image 9.7M 13k 9.2M 0% /tmp/virtual-fs
            你可以向任何其它磁盤(pán)一樣使用這個(gè)設(shè)備:
            % cd /tmp/virtual-fs
            % echo 'Hello, world!' > test.txt
            % ls -l
            total 19
            drwxr-xr-x 2   root root 12288 Mar 8 02:00 lost+found
            -rw-rw---- 1   root root     14 Mar 8 02:12 test.txt
            % cat test.txt
            Hello, world!
            請(qǐng)注意 lost+found 是一個(gè)由 mke2fs 自動(dòng)建立的文件夾一旦文件系統(tǒng)被破壞,部分?jǐn)?shù)據(jù)被回復(fù)但沒(méi)有與任何文件關(guān)聯(lián)起來(lái),將被放置在這個(gè)文件夾中。。
            結(jié)束使用后,卸載這個(gè)文件系統(tǒng):
            % cd /tmp
            % umount /tmp/virtual-fs
            你可以刪除 disk-image,或者之后再次掛載并使用其中的文件。你甚至可以將這個(gè)文件復(fù)制到遠(yuǎn)程主機(jī)并在那里掛載、使用——文件系統(tǒng)的內(nèi)容完全不會(huì)受到影響。
            除了從新創(chuàng)建一個(gè)文件系統(tǒng),還可以從一個(gè)現(xiàn)有的文件系統(tǒng)復(fù)制而得到一份映像。例如,可以通過(guò)普通的復(fù)制操作為一個(gè) CD-ROM 創(chuàng)建一份映像。

            如果系統(tǒng)中有一個(gè) IDE 接口的 CD-ROM 驅(qū)動(dòng)器,使用前面說(shuō)過(guò)的設(shè)備名如 /dev/hda。如果 CD-ROM 是 SCSI 接口的話(huà),設(shè)備文件名可能是 /dev/scd0 之類(lèi)。系統(tǒng)中也可能包含一個(gè)符號(hào)鏈接 /dev/cdrom 指向?qū)嶋H的光驅(qū)。請(qǐng)參考 /etc/fstab (譯者注: 手冊(cè))查看系統(tǒng)實(shí)際使用的光驅(qū)對(duì)應(yīng)的設(shè)備。

            接下來(lái)要做的僅僅是將這個(gè)設(shè)備復(fù)制為一個(gè)文件——得到的文件將是被存在硬盤(pán)上的、這個(gè) CD-ROM 內(nèi)容的完整映像。例如:

            % cp /dev/cdrom /tmp/cdrom-image
            取決于設(shè)備的速度和 CD-ROM 的容量,這個(gè)操作可能需要幾分鐘的時(shí)間。最終的文件將會(huì)相當(dāng)大,它的體積與這個(gè) CD-ROM 的容量相同。

            這時(shí),你可以在系統(tǒng)中掛載這個(gè)光盤(pán)而無(wú)須插入原始的 CD-ROM 盤(pán)片。要掛載在 /mnt/cdrom 目錄下:

            mount -o loopback=/dev/loop0 /tmp/cdrom-image /mnt/cdrom
            因?yàn)橛诚裎挥诖疟P(pán)上,這個(gè)文件系統(tǒng)的速度將遠(yuǎn)勝于直接掛載自實(shí)際光驅(qū)的時(shí)候。請(qǐng)注意多數(shù)光盤(pán)使用的文件系統(tǒng)類(lèi)型都是   iso9660。

            posted @ 2013-04-03 19:47 鑫龍 閱讀(553) | 評(píng)論 (0)編輯 收藏

            Redis是一個(gè)key-value存儲(chǔ)系統(tǒng)。和Memcached類(lèi)似,它支持存儲(chǔ)的value類(lèi)型相對(duì)更多,包括string(字符串)、 list(鏈表)、set(集合)和zset(有序集合)。這些數(shù)據(jù)類(lèi)型都支持push/pop、add/remove及取交集并集和差集及更豐富的操 作,而且這些操作都是原子性的。在此基礎(chǔ)上,redis支持各種不同方式的排序。與memcached一樣,為了保證效率,數(shù)據(jù)都是緩存在內(nèi)存中。區(qū)別的 是redis會(huì)周期性的把更新的數(shù)據(jù)寫(xiě)入磁盤(pán)或者把修改操作寫(xiě)入追加的記錄文件,并且在此基礎(chǔ)上實(shí)現(xiàn)了master-slave(主從)同步。Redis 是一個(gè)高性能的key-value數(shù)據(jù)庫(kù)。
            redis的出現(xiàn),很大程度補(bǔ)償了memcached這類(lèi)key/value存儲(chǔ)的不足,在部分場(chǎng)合可以對(duì)關(guān)系數(shù)據(jù)庫(kù)起到很好的補(bǔ)充作用。它提供了Python,Ruby,Erlang,PHP客戶(hù)端,使用很方便。(以上內(nèi)容摘自百度百科)

            一:下載redis并安裝

            1. [root@server11 ~]# wget http://redis.googlecode.com/files/redis-2.6.4.tar.gz  
            2. [root@server11 ~]# tar -zxvpf redis-2.6.4.tar.gz   
            3. [root@server11 ~]# cd redis-2.6.4  
            4. [root@server11 redis-2.6.4]# make install 

            32位操作系統(tǒng)上可能會(huì)出現(xiàn)如下報(bào)錯(cuò):
            zmalloc.o: In function `zmalloc_used_memory':
            /root/redis-2.6.4/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
            collect2: ld returned 1 exit status
            make[1]: *** [redis-server] Error 1
            make[1]: Leaving directory `/root/redis-2.6.4/src'
            make: *** [all] Error 2

            解決方案參考:
            https://groups.google.com/forum/?fromgroups#!topic/redis-db/NI_d00he39o

            二:編輯redis配置文件,啟動(dòng)redis

            1. [root@server11 ~]# mkdir -p /usr/local/redis2/{bin,etc,var}  
            2. [root@server11 redis-2.6.4]# cp redis.conf /usr/local/redis2/etc/  
            3. [root@server11 redis-2.6.4]# cp /usr/local/bin/redis-* /usr/local/redis2/bin/  
            4.  
            5. [root@server11 ~]# grep -v '^#' /usr/local/redis2/etc/redis.conf |grep -v '^$' //各參數(shù)含義在配置文件中有具體的解釋和介紹  
            6. daemonize yes   
            7. pidfile /usr/local/redis2/var/redis.pid  
            8. port 6379  
            9. bind 192.168.1.112   
            10. timeout 300   
            11. loglevel notice  
            12. logfile stdout  
            13. databases 16  
            14. save 900 1  
            15. save 300 10  
            16. save 60 10000  
            17. stop-writes-on-bgsave-error yes  
            18. rdbcompression yes  
            19. rdbchecksum yes  
            20. dbfilename dump.rdb  
            21. dir ./  
            22. slave-serve-stale-data yes  
            23. slave-read-only yes  
            24. slave-priority 100  
            25. appendonly no  
            26. appendfsync everysec  
            27. no-appendfsync-on-rewrite no  
            28. auto-aof-rewrite-percentage 100  
            29. auto-aof-rewrite-min-size 64mb  
            30. lua-time-limit 5000  
            31. slowlog-log-slower-than 10000  
            32. slowlog-max-len 128  
            33. hash-max-ziplist-entries 512  
            34. hash-max-ziplist-value 64  
            35. list-max-ziplist-entries 512  
            36. list-max-ziplist-value 64  
            37. set-max-intset-entries 512  
            38. zset-max-ziplist-entries 128  
            39. zset-max-ziplist-value 64  
            40. activerehashing yes  
            41. client-output-buffer-limit normal 0 0 0  
            42. client-output-buffer-limit slave 256mb 64mb 60  
            43. client-output-buffer-limit pubsub 32mb 8mb 60  
            44.  
            45. [root@server11 ~]# /usr/local/redis2/bin/redis-server  /usr/local/redis2/etc/redis.conf   
            46. [root@server11 ~]# netstat -ntpl |grep 6379  
            47. tcp        0      0 192.168.1.112:6379          0.0.0.0:*                   LISTEN      6044/redis-server    
            48.  
            49. [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112  
            50. redis 192.168.1.112:6379> set number 100  
            51. OK  
            52. redis 192.168.1.112:6379> get number  
            53. "100"  
            54. redis 192.168.1.112:6379> del number  
            55. (integer) 1  
            56. redis 192.168.1.112:6379> get number  
            57. (nil)  
            58. redis 192.168.1.112:6379> quit 

            三: redis主從配置,關(guān)閉主節(jié)點(diǎn)的redis實(shí)例,復(fù)制/usr/local/redis2/目錄至從節(jié)點(diǎn)

            1. [root@server11 ~]# ps -ef |grep redis  
            2. root      6044     1  0 09:37 ?        00:00:00 /usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf  
            3. root      6072 27475  0 09:44 pts/1    00:00:00 grep redis  
            4. [root@server11 ~]# kill 6044  
            5. [root@server11 ~]# scp -rvp /usr/local/redis2/ root@192.168.1.113:/usr/local/  
            6.  
            7. [root@server12 ~]# grep -v '^#'  /usr/local/redis2/etc/redis.conf  |grep -v '^$' //注意紅色字體部分  
            8. daemonize yes   
            9. pidfile /usr/local/redis2/var/redis.pid  
            10. port 6379  
            11. bind 192.168.1.113  
            12. timeout 300   
            13. loglevel notice  
            14. logfile stdout  
            15. databases 16  
            16. save 900 1  
            17. save 300 10  
            18. save 60 10000  
            19. stop-writes-on-bgsave-error yes  
            20. rdbcompression yes  
            21. rdbchecksum yes  
            22. dbfilename salve.rdb  
            23. dir ./  
            24. slaveof 192.168.1.112 6379 
            25. slave-serve-stale-data yes  
            26. slave-read-only yes  
            27. slave-priority 100  
            28. appendonly no  
            29. appendfsync everysec  
            30. no-appendfsync-on-rewrite no  
            31. auto-aof-rewrite-percentage 100  
            32. auto-aof-rewrite-min-size 64mb  
            33. lua-time-limit 5000  
            34. slowlog-log-slower-than 10000  
            35. slowlog-max-len 128  
            36. hash-max-ziplist-entries 512  
            37. hash-max-ziplist-value 64  
            38. list-max-ziplist-entries 512  
            39. list-max-ziplist-value 64  
            40. set-max-intset-entries 512  
            41. zset-max-ziplist-entries 128  
            42. zset-max-ziplist-value 64  
            43. activerehashing yes  
            44. client-output-buffer-limit normal 0 0 0  
            45. client-output-buffer-limit slave 256mb 64mb 60  
            46. client-output-buffer-limit pubsub 32mb 8mb 60 

            四:分別啟動(dòng)主從節(jié)點(diǎn)redis實(shí)例并測(cè)試

            1. [root@server11 ~]# /usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf   
            2. [root@server12 ~]# /usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf   
            3.  
            4. [root@server12 ~]# netstat -ntpl |grep 6379  
            5. tcp        0      0 192.168.1.113:6379          0.0.0.0:*                   LISTEN      16653/redis-server    
            6.  
            7. [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112  
            8. redis 192.168.1.112:6379> set number 1  
            9. OK  
            10. redis 192.168.1.112:6379> get number   
            11. "1"  
            12. redis 192.168.1.112:6379> quit  
            13.  
            14. [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113  
            15. redis 192.168.1.113:6379> get number  
            16. "1"  
            17. redis 192.168.1.113:6379> del number  
            18. (error) READONLY You can't write against a read only slave.  
            19. redis 192.168.1.113:6379> quit

            posted @ 2013-04-03 18:41 鑫龍 閱讀(499) | 評(píng)論 (0)編輯 收藏

            本文地址:博客園 逖靖寒 http://gpcuster.cnblogs.com

            前提

            1. 了解JUnit4.x的使用。
            2. 了解Mock的概念在單元測(cè)試中的應(yīng)用。
            3. 了解Hadoop中MapReduce的編程模型。

              如果您對(duì)Junit和Mock不了解,可以先閱讀[翻譯]Unit testing with JUnit 4.x and EasyMock in Eclipse - Tutorial

              如果您對(duì)Hadoop中MapReduce的編程模型不了解,可以先閱讀Map/Reduce Tutorial

              介紹

              MRUnit是一款由Couldera公司開(kāi)發(fā)的專(zhuān)門(mén)針對(duì)Hadoop中編寫(xiě)MapReduce單元測(cè)試的框架。

              它可以用于0.18.x版本中的經(jīng)典org.apache.hadoop.mapred.*的模型,也能在0.20.x版本org.apache.hadoop.mapreduce.*的新模型中使用。

              官方的介紹如下:

              MRUnit is a unit test library designed to facilitate easy integration between your MapReduce development process and standard development and testing tools such as JUnit. MRUnit contains mock objects that behave like classes you interact with during MapReduce execution (e.g., InputSplit and OutputCollector) as well as test harness "drivers" that test your program's correctness while maintaining compliance with the MapReduce semantics. Mapper and Reducer implementations can be tested individually, as well as together to form a full MapReduce job.

              安裝

              在目前Hadoop的發(fā)行版中,并沒(méi)有默認(rèn)包含MRUnit。你需要去Couldera公司的官網(wǎng)中去下載一個(gè)由他們?cè)俅伟l(fā)行的版本。

              推薦的版本為:hadoop-0.20.1+133.tar.gz

              下載這個(gè)文件后,你將在hadoop-0.20.1+133\contrib\mrunit目錄中找到我們需要的jar包:hadoop-0.20.1+133-mrunit.jar。

              為了使用MRUnit,我們需要將hadoop-0.20.1+133-mrunit.jar和Junit4.x使用的jar包:junit.jar都添加到我們開(kāi)發(fā)Hadoop程序項(xiàng)目的classpath中。

              示例

              代碼是最好的文檔,我們先看一個(gè)簡(jiǎn)單的map單元測(cè)試示例,代碼如下:

              package gpcuster.cnblogs.com;

              import junit.framework.TestCase;
              import org.apache.hadoop.io.Text;
              import org.apache.hadoop.mapred.Mapper;
              import org.apache.hadoop.mapred.lib.IdentityMapper;
              import org.junit.Before;
              import org.junit.Test;
              import org.apache.hadoop.mrunit.MapDriver;

              public class TestExample extends TestCase {

              private Mapper<Text, Text, Text, Text> mapper;
              private MapDriver<Text, Text, Text, Text> driver;

              @Before
              public void setUp() {
              mapper = new IdentityMapper<Text, Text>();
              driver = new MapDriver<Text, Text, Text, Text>(mapper);
              }

              @Test
              public void testIdentityMapper() {
              driver.withInput(new Text("foo"), new Text("bar"))
              .withOutput(new Text("foo"), new Text("bar"))
              .runTest();
              }
              }

              在這段示例代碼中,我們使用的map是org.apache.hadoop.mapred.lib.IdentityMapper。這是一個(gè)非常簡(jiǎn)單的map函數(shù):輸入什么,就輸出什么。

              org.apache.hadoop.mrunit.MapDriver是我們從MRUnit框架中導(dǎo)入的一個(gè)專(zhuān)門(mén)用于測(cè)試map的類(lèi)。

              我們通過(guò)withInput指定輸入的參數(shù),通過(guò)withOutput指定我們期望的輸出,然后通過(guò)runTest運(yùn)行我們的測(cè)試。

              功能

              1. 測(cè)試Map,我們可以使用MapDriver。
              2. 測(cè)試Reduce,我們可以使用ReduceDriver。
              3. 測(cè)試一個(gè)完整的MapReduce,我們可以使用MapReduceDriver。
              4. 測(cè)試多個(gè)MapReduce組合而成的操作,我們可以使用PipelineMapReduceDriver。

                實(shí)現(xiàn)

                MRUnit框架非常精簡(jiǎn),其核心的單元測(cè)試依賴(lài)于JUnit。

                由于我們編寫(xiě)的MapReduce函數(shù)中包含有一個(gè)OutputCollector的對(duì)象,所以MRUnit自己實(shí)現(xiàn)了一套Mock對(duì)象來(lái)控制OutputCollector的操作。

                局限

                通過(guò)閱讀MRUnit的源代碼我們會(huì)發(fā)現(xiàn):

                1. 不支持MapReduce框架中的分區(qū)和排序操作:從Map輸出的值經(jīng)過(guò)shuffle處理后直接就導(dǎo)入Reduce中了。
                2. 不支持Streaming實(shí)現(xiàn)的MapReduce操作。

                  雖然MRUnit有這些局限,但是足以完成大多數(shù)的需求。

                  參考資料

                  http://www.cloudera.com/hadoop-mrunit

                   

                  本文地址:博客園 逖靖寒 http://gpcuster.cnblogs.com

                  posted @ 2013-04-03 11:27 鑫龍 閱讀(257) | 評(píng)論 (0)編輯 收藏

                  僅列出標(biāo)題
                  共20頁(yè): 1 2 3 4 5 6 7 8 9 Last 
                  久久久久久久人妻无码中文字幕爆| 久久国产高清一区二区三区| 思思久久99热只有频精品66| 亚洲精品乱码久久久久久久久久久久| 久久婷婷五月综合97色一本一本 | 婷婷久久综合九色综合98| 中文字幕乱码久久午夜| 久久精品中文字幕有码| 久久99精品久久久久婷婷| 香蕉久久夜色精品国产2020| 成人a毛片久久免费播放| 69久久精品无码一区二区| 久久久亚洲欧洲日产国码二区| 91精品免费久久久久久久久| 国产美女亚洲精品久久久综合 | 亚洲AV无码久久精品蜜桃| 国产激情久久久久影院老熟女| 亚洲国产精品无码久久青草| 久久免费精品视频| 久久久久久免费视频| 一本一道久久精品综合| 亚洲中文精品久久久久久不卡 | 97精品依人久久久大香线蕉97 | 伊人久久五月天| 国产精品热久久毛片| 97久久精品无码一区二区| 狠狠色丁香久久婷婷综合| 久久久高清免费视频| 久久99精品国产麻豆不卡| 国产精品久久久久aaaa| 伊人久久大香线蕉亚洲五月天| 亚洲乱码日产精品a级毛片久久 | 久久夜色精品国产噜噜麻豆 | 日本精品久久久久久久久免费| 天天综合久久一二三区| 99久久精品国产毛片| 97久久精品人人澡人人爽| 99久久伊人精品综合观看| 久久精品人人做人人爽电影| 国产精品伦理久久久久久| 精品久久一区二区三区|