package com.wmz7year.synyed.parser;

import org.apache.commons.io.HexDump;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.wmz7year.synyed.Booter;

/**
 * redis rdb0006版本的解析器测试
 * 
 * @Title: RDBParserImpl0006Test.java
 * @Package com.wmz7year.synyed.parser
 * @author jiangwei (ydswcy513@gmail.com)
 * @date 2015年12月14日 下午2:37:44
 * @version V1.0
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Booter.class)
public class RDBParserImpl0006Test {
	private static final byte[] rdbData = new byte[] { 82, 69, 68, 73, 83, 48, 48, 48, 54, -1, -36, -77, 67, -16, 90, -36, -14, 86 };

	/**
	 * 显示RDB字节内容以及格式化
	 */
	@Test
	public void showRDBDumpData() throws Exception {
		HexDump.dump(rdbData, 0, System.out, 0);
	}

	/**
	 * 测试解析RDB文件内容
	 */
	@Test
	public void testParseRDBFile() throws Exception {
		byte[] rdbHeader = new byte[9];
		System.arraycopy(rdbData, 0, rdbHeader, 0, 9);
		RDBParser rdbParser = RDBParserFactory.createRDBParser(rdbHeader);
		rdbParser.parse(rdbData);
	}

}

@@ -26,24 +26,59 @@
 ed.parser;%0A%0A
+import static org.junit.Assert.*;%0A%0A
 import org.a
@@ -103,16 +103,16 @@
 exDump;%0A
-
 import o
@@ -788,17 +788,20 @@
 -16, 90,
- 
+%0A%09%09%09
 -36, -14
@@ -1178,16 +1178,16 @@
 eader);%0A
-
 %09%09rdbPar
@@ -1210,10 +1210,864 @@
 a);%0A%09%7D%0A%0A
+%09/**%0A%09 * %E6%B5%8B%E8%AF%95%E6%AD%A3%E5%B8%B8%E6%A0%A1%E9%AA%8Ccrc64%E5%80%BC%0A%09 */%0A%09@Test%0A%09public void testCheckRDBCRCSum() throws Exception %7B%0A%09%09byte%5B%5D rdbData = new byte%5B%5D %7B 82, 69, 68, 73, 83, 48, 48, 48, 54, -1, -36, -77, 67, -16, 90, -36, -14, 86 %7D;%0A%09%09byte%5B%5D rdbHeader = new byte%5B9%5D;%0A%09%09System.arraycopy(rdbData, 0, rdbHeader, 0, 9);%0A%09%09RDBParser rdbParser = RDBParserFactory.createRDBParser(rdbHeader);%0A%09%09rdbParser.parse(rdbData);%0A%09%7D%0A%0A%09/**%0A%09 * %E6%B5%8B%E8%AF%95%E6%AD%A3%E5%B8%B8%E6%A0%A1%E9%AA%8Ccrc64%E5%80%BC%0A%09 */%0A%09@Test%0A%09public void testCheckRDBCRCSumOnerror() throws Exception %7B%0A%09%09byte%5B%5D rdbData = new byte%5B%5D %7B 82, 69, 68, 73, 83, 48, 48, 48, 54, -1, -36, -77, 67, -16, 90, -36, -14, 87 %7D;%0A%09%09byte%5B%5D rdbHeader = new byte%5B9%5D;%0A%09%09System.arraycopy(rdbData, 0, rdbHeader, 0, 9);%0A%09%09try %7B%0A%09%09%09RDBParser rdbParser = RDBParserFactory.createRDBParser(rdbHeader);%0A%09%09%09rdbParser.parse(rdbData);%0A%09%09%09assertTrue(false);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09assertTrue(true);%0A%09%09%7D%0A%09%7D%0A%0A
 %7D%0A

添加针对crc64校验和的单元测试