From 6439524cafdaabda81217d620f018f20572c1a88 Mon Sep 17 00:00:00 2001 From: Baoyi Chen Date: Sun, 14 Mar 2021 18:22:59 +0800 Subject: [PATCH] 3.6.0 --- CHANGELOG.md | 2 +- README.md | 2 +- README.zh_CN.md | 2 +- pom.xml | 2 +- .../redis/replicator/rdb/BaseRdbEncoder.java | 40 ++++++------ .../replicator/rdb/BaseRdbEncoderTest.java | 5 +- .../rdb/dump/DumpRdbVisitorTest.java | 57 +++++++++++++++++- src/test/resources/dumpV9.rdb | Bin 0 -> 202 bytes 8 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 src/test/resources/dumpV9.rdb diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e85abb7..ea9178f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -### 3.6.0 +### 3.5.3 `DumpRdbValueVisitor` support downgrade from redis 6.2 to 2.8. diff --git a/README.md b/README.md index 99e4e7d9..745d8efc 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ redis 2.6 - 6.2 com.moilioncircle redis-replicator - 3.6.0 + 3.5.3 ``` diff --git a/README.zh_CN.md b/README.zh_CN.md index 05316474..ed26d8b6 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -90,7 +90,7 @@ redis 2.6 - 6.2 com.moilioncircle redis-replicator - 3.6.0 + 3.5.3 ``` diff --git a/pom.xml b/pom.xml index 1d8f4b08..d53cdeb4 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ com.moilioncircle redis-replicator - 3.6.0 + 3.5.3 redis-replicator diff --git a/src/main/java/com/moilioncircle/redis/replicator/rdb/BaseRdbEncoder.java b/src/main/java/com/moilioncircle/redis/replicator/rdb/BaseRdbEncoder.java index 65748b91..a92b742e 100644 --- a/src/main/java/com/moilioncircle/redis/replicator/rdb/BaseRdbEncoder.java +++ b/src/main/java/com/moilioncircle/redis/replicator/rdb/BaseRdbEncoder.java @@ -36,39 +36,39 @@ /** * @author Leon Chen - * @since 3.6.0 + * @since 3.5.3 */ public class BaseRdbEncoder { /** - * @since 3.6.0 * @param time time * @param out out * @throws IOException IOException - * @see BaseRdbParser#rdbLoadTime() + * @see BaseRdbParser#rdbLoadTime() + * @since 3.5.3 */ public void rdbSaveTime(int time, OutputStream out) throws IOException { out.write(ByteBuffer.allocate(Integer.BYTES).order(LITTLE_ENDIAN).putInt(time).array()); } /** - * @since 3.6.0 + * @since 3.5.3 * @param timestamp timestamp * @param out out * @throws IOException IOException - * @see BaseRdbParser#rdbLoadMillisecondTime() + * @see BaseRdbParser#rdbLoadMillisecondTime() */ public void rdbSaveMillisecondTime(long timestamp, OutputStream out) throws IOException { out.write(ByteBuffer.allocate(Long.BYTES).order(LITTLE_ENDIAN).putLong(timestamp).array()); } /** - * @since 3.6.0 + * @since 3.5.3 * @param len len * @param out out * @return length * @throws IOException IOException - * @see BaseRdbParser#rdbLoadLen() + * @see BaseRdbParser#rdbLoadLen() */ public int rdbSaveLen(long len, OutputStream out) throws IOException { if (len < (1 << 6)) { @@ -93,7 +93,7 @@ public int rdbSaveLen(long len, OutputStream out) throws IOException { } /** - * @since 3.6.0 + * @since 3.5.3 * @param len len * @return byte array * @throws IOException IOException @@ -115,11 +115,11 @@ public byte[] rdbSaveLen(long len) throws IOException { } /** - * @since 3.6.0 + * @since 3.5.3 * @param value value * @param out out * @throws IOException IOException - * @see BaseRdbParser#rdbLoadDoubleValue() + * @see BaseRdbParser#rdbLoadDoubleValue() */ public void rdbSaveDoubleValue(double value, OutputStream out) throws IOException { if (value == Double.NEGATIVE_INFINITY) { @@ -141,33 +141,33 @@ public void rdbSaveDoubleValue(double value, OutputStream out) throws IOExceptio } /** - * @since 3.6.0 + * @since 3.5.3 * @param value value * @param out out * @throws IOException IOException - * @see BaseRdbParser#rdbLoadBinaryFloatValue() + * @see BaseRdbParser#rdbLoadBinaryFloatValue() */ public void rdbSaveBinaryFloatValue(float value, OutputStream out) throws IOException { out.write(ByteBuffer.allocate(Long.BYTES).order(LITTLE_ENDIAN).putLong(floatToIntBits(value)).array()); } /** - * @since 3.6.0 + * @since 3.5.3 * @param value value * @param out out * @throws IOException IOException - * @see BaseRdbParser#rdbLoadBinaryDoubleValue() + * @see BaseRdbParser#rdbLoadBinaryDoubleValue() */ public void rdbSaveBinaryDoubleValue(double value, OutputStream out) throws IOException { out.write(ByteBuffer.allocate(Long.BYTES).order(LITTLE_ENDIAN).putLong(doubleToLongBits(value)).array()); } /** - * @since 3.6.0 + * @since 3.5.3 * @param bytes input * @param out out * @throws IOException IOException - * @see BaseRdbParser#rdbLoadEncodedStringObject() + * @see BaseRdbParser#rdbLoadEncodedStringObject() */ public void rdbSaveEncodedStringObject(ByteArray bytes, OutputStream out) throws IOException { int type = (RDB_ENCVAL << 6) | RDB_ENC_LZF; @@ -180,11 +180,11 @@ public void rdbSaveEncodedStringObject(ByteArray bytes, OutputStream out) throws } /** - * @since 3.6.0 + * @since 3.5.3 * @param bytes bytes * @param out out * @throws IOException IOException - * @see BaseRdbParser#rdbGenericLoadStringObject(int) + * @see BaseRdbParser#rdbGenericLoadStringObject(int) */ public void rdbGenericSaveStringObject(ByteArray bytes, OutputStream out) throws IOException { if (bytes.length() > 20) { @@ -195,11 +195,11 @@ public void rdbGenericSaveStringObject(ByteArray bytes, OutputStream out) throws } /** - * @since 3.6.0 + * @since 3.5.3 * @param bytes bytes * @param out out * @throws IOException IOException - * @see BaseRdbParser#rdbLoadPlainStringObject() + * @see BaseRdbParser#rdbLoadPlainStringObject() */ public void rdbSavePlainStringObject(ByteArray bytes, OutputStream out) throws IOException { rdbSaveLen(bytes.length(), out); diff --git a/src/test/java/com/moilioncircle/redis/replicator/rdb/BaseRdbEncoderTest.java b/src/test/java/com/moilioncircle/redis/replicator/rdb/BaseRdbEncoderTest.java index bee27d87..feaaddc4 100644 --- a/src/test/java/com/moilioncircle/redis/replicator/rdb/BaseRdbEncoderTest.java +++ b/src/test/java/com/moilioncircle/redis/replicator/rdb/BaseRdbEncoderTest.java @@ -19,7 +19,8 @@ import static com.moilioncircle.redis.replicator.Constants.RDB_LOAD_ENC; import static java.lang.Double.NEGATIVE_INFINITY; import static java.lang.Double.POSITIVE_INFINITY; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -32,7 +33,7 @@ /** * @author Leon Chen - * @since 3.6.0 + * @since 3.5.3 */ public class BaseRdbEncoderTest { diff --git a/src/test/java/com/moilioncircle/redis/replicator/rdb/dump/DumpRdbVisitorTest.java b/src/test/java/com/moilioncircle/redis/replicator/rdb/dump/DumpRdbVisitorTest.java index 4605c331..f34ff51b 100644 --- a/src/test/java/com/moilioncircle/redis/replicator/rdb/dump/DumpRdbVisitorTest.java +++ b/src/test/java/com/moilioncircle/redis/replicator/rdb/dump/DumpRdbVisitorTest.java @@ -217,7 +217,7 @@ public void onEvent(Replicator replicator, Event event) { } }); replicator.open(); - + assertEquals(expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { assertArrayEquals(expected.get(i).getElement(), actual.get(i).getElement()); @@ -225,6 +225,61 @@ public void onEvent(Replicator replicator, Event event) { } } + @Test + @SuppressWarnings("resource") + public void test5() throws IOException { + Replicator replicator = new RedisReplicator(DumpRdbVisitorTest.class. + getClassLoader().getResourceAsStream("dumpV9.rdb") + , FileType.RDB, Configuration.defaultSetting()); + List expected = new ArrayList<>(); + replicator.addEventListener(new EventListener() { + @Override + public void onEvent(Replicator replicator, Event event) { + if (event instanceof KeyStringValueList) { + KeyStringValueList kv = (KeyStringValueList) event; + if (kv.getValueRdbType() == RDB_TYPE_LIST_QUICKLIST) { + for (byte[] element : kv.getValue()) { + expected.add(element); + } + } + } + } + }); + replicator.open(); + + replicator = new RedisReplicator(DumpRdbVisitorTest.class. + getClassLoader().getResourceAsStream("dumpV9.rdb") + , FileType.RDB, Configuration.defaultSetting()); + List actual = new ArrayList<>(); + replicator.setRdbVisitor(new DumpRdbVisitor(replicator, 6)); + replicator.addEventListener(new EventListener() { + @Override + public void onEvent(Replicator replicator, Event event) { + if (!(event instanceof DumpKeyValuePair)) return; + DumpKeyValuePair kv = (DumpKeyValuePair) event; + String key = new String(kv.getKey()); + if (key.equals("list1") && kv.getValueRdbType() == RDB_TYPE_LIST) { + DumpValueParser parser = new DefaultDumpValueParser(replicator); + parser.parse(kv, new EventListener() { + @Override + public void onEvent(Replicator replicator, Event event) { + KeyStringValueList kv = (KeyStringValueList) event; + for (byte[] element : kv.getValue()) { + actual.add(element); + } + } + }); + } + } + }); + replicator.open(); + + assertEquals(expected.size(), actual.size()); + for (int i = 0; i < expected.size(); i++) { + assertArrayEquals(expected.get(i), actual.get(i)); + } + } + public void template(String filename) { try { @SuppressWarnings("resource") diff --git a/src/test/resources/dumpV9.rdb b/src/test/resources/dumpV9.rdb new file mode 100644 index 0000000000000000000000000000000000000000..98a55df9add8dc7fe77f1da710d20313fe67948c GIT binary patch literal 202 zcmWG?b@2=~Ffg$E#aWb^l3A=9q0bL| z6Mk`&7N@4@=BDNzdXOx@@QWugKTWrwC^a!RDJS&+!#{@Kj0}9NIhn;JhKz?Dq8zGN zsu&m;iWQjoSs54(h#Ro*7#SNH8ye{uI